

	function loadSchoolMenu( lsListID, lsElementID ) {
		loElement = core.$( lsElementID );
		if ( !loElement ) { return; }
		if ( loElement.innerHTML.length > 0) { return; }
		if ( !lsListID ) { return; }
		lsURI = '/schools_menu_list?_listStart=' + lsListID[0] + '&_listEnd=' + lsListID[1];
		ajaxEvent( lsURI, loElement, false, false );
	} // * * *

	var iCurrentFileID = null;

	function getCurrentFileID() {
		return iCurrentFileID;	
	} // * * *

	function setCurrentFileID( iFileID ) {
		return;
	} // * * *

	function editCartItem(cfp_id, cf_id, cf_fid, gallery, sourceW, sourceH) {
		currentItemID = cfp_id;
		currentWindow = interstate(currentWindow, 805, 660, 'appcontainer');
		photo = newPhoto(cfp_id, cf_id, cf_fid, gallery, sourceW, sourceH);
		createApp( photo ); 
	} // * * *

	function addNewCartItem(cf_id, cf_fid, gallery, sourceW, sourceH) {
		ajaxEvent(
			'/my-cart/product_config_list', core.$('product_config_list_container'), false, true
		);
		BigLeagueChew( '', core.$('current_pid_'+cf_id), 'carts_files', 'products', cf_id, 2, 1, 'insert' ); 
		ajaxEvent( '/my-cart/carts_files_products/?_context=carts_files&_id='+cf_id+'&files_id='+cf_fid,
			core.$('carts_files_products_lookup_callback_'+cf_id), false, true
		);
		currentWindow = interstate( currentWindow, 805, 660, 'appcontainer' ); //required - global active window: MUST LOAD FIRST.
		currentItemID = core.$('current_pid_'+cf_id).value;
		photo = newPhoto( currentItemID, cf_id, cf_fid, gallery, sourceW, sourceH ); 
		createApp( photo );
	} // * * *

	function swapText(oElement, toggle) {
        var add = [ new RegExp('Add\ to'), 'Remove from' ];
        var remove = [ new RegExp('Remove\ from'), 'Add to' ];
        if( !toggle ) {
            oElement.innerHTML = oElement.innerHTML.replace( remove[0], remove[1] );
		} else {
            oElement.innerHTML = oElement.innerHTML.replace( add[0], add[1] );
		}
	}



	function switchAlbum(oElement, fileID, statusID) {
        if( ClassFX.hasClass( oElement, 'added' ) ) {
            swapText( oElement, false );
    		ClassFX.tradeClass(oElement, 'added', 'addTo');
            removeAlbum( false, fileID );
		} else {
            swapText( oElement, true );
    		ClassFX.tradeClass(oElement, 'addTo', 'added');
			addAlbum( false, fileID, statusID );
		}
	}

    function removeAlbum(oElement, ID ) {
    	var UpdateURI = '/my-album/remove/';
    	var request = '&_id=' + ID;
    	UpdateURI += request;
    	ajaxEvent( UpdateURI, oElement, false, true );
    	return true;
    }
    
    function addAlbum(oElement, ID, statusID ) {
        if(statusID=='5') {
            BigLeagueChew( '', false, 'albums', 'files', 0, ID, 1, 'update' );
        } else {
            BigLeagueChew( '', false, 'albums', 'files', 0, ID, 1, 'insert' );
        }
    }



	function switchFinal(oElement, fileID) {
        if( ClassFX.hasClass( oElement, 'added' ) ) {
            swapText(oElement, false);
            removeFinal( oElement, fileID );
		} else {
            swapText(oElement, true);
			addFinal( oElement, fileID );
		}
	}

	function addFinal(oElement, fileID) {
		ClassFX.tradeClass(oElement, 'added', 'addTo');
		ClassFX.tradeClass((oElement.parentNode.parentNode.parentNode),'thumbSelectedContainer','thumbUnselectedContainer');
		addFileToCart(fileID);
	}

	function removeFinal(oElement, fileID) {
		ClassFX.tradeClass(oElement, 'addTo', 'added');
		ClassFX.tradeClass((oElement.parentNode.parentNode.parentNode),'thumbUnselectedContainer','thumbSelectedContainer');
		removeFileFromCart(fileID);
	}

	function addFileToCart(iFileID) {
		ajaxEvent( '/my-cart/add/files/'+iFileID, false, false, true); //synchronous
	} // * * *

	function removeFileFromCart(iFileID) {
		ajaxEvent( '/my-cart/remove/files/'+iFileID, null, false, true);
	} // * * *


	function updateCartPrice(id, quantity) {
		var oPrice = core.$( 'product_price_' + id );
		var oCost = core.$( 'items_cost_' + id );
		if(!oPrice){ return false; }
		var product_price = oPrice.value;
		oCost.innerHTML = ((product_price=='')?(0):(product_price)) * quantity;
		UpdateSingleField(false, 'carts_files_products', id, 'quantity', quantity);
	} // * * *

    function setCartPoints( id, element ) { //points
		var oPoints = core.$( 'users_points' );
		var oCartPoints = core.$( 'cart_points' );
		var oItemPoints = core.$( 'item_points_'+id );
		var oItemPointsTotal = core.$( 'item_points_total_'+id );
        var quantity = element.value;
        if( oItemPoints && oPoints && oItemPointsTotal ) {
            var item_points = (oItemPoints.value*1) * quantity;
            oItemPointsTotal.value = item_points;
            var totalpoints = totals( );
            oCartPoints.value = (oPoints.value*1) - totalpoints;
            var cp_left = oCartPoints.value;
            if(cp_left<0) {
                cp_left = 0;
            }
            core.$('cpleft').innerHTML = cp_left;
        }
    } // * * *
    function setTotals() {
        var totalpoints = totals( );
		var oCartPoints = core.$( 'cart_points' );
		var oPoints = core.$( 'users_points' );
        if(oCartPoints && oPoints) {
            oCartPoints.value = (oPoints.value*1) - totalpoints;
            var cp_left = oCartPoints.value;
            if(cp_left<0) {
                cp_left = 0;
            }
            core.$('cpleft').innerHTML = cp_left;
        }
    }

    function totals( ) {
        var tp = '.item_points_total';
        var totalpoints = 0;
        $(tp).each(function( item, element ) {
            if(!element.value) {
                element.value = 0;
            }
            totalpoints += (element.value*1);
        });
        return totalpoints;
    } // * * *

    function increase( id, element ) {
        var currentvalue = element.value;
        element.value = (currentvalue*1)+1; //increment item count
		var oItemPointsTotal = core.$( 'item_points_total_'+id );
        if( oItemPointsTotal ) {
            setCartPoints( id, element );
            if ( !checkCartPoints(id) ) { //count item amount ensure it does not exceed limit
                element.value = currentvalue;
                oItemPointsTotal.value=oItemPointsTotal.value-1;
                return false;
            }
        }
        updateCartPrice( id, (element.value=='')?(0):(element.value));
	} // * * *

    function decrease( id, element ) {
        if(element.value<=0) {element.value=0;return false;}
        var currentvalue = element.value;
        element.value = (element.value*1)-1;
        if( core.$('item_points_total_' + id) ) {
            setCartPoints( id, element );
            if ( !checkCartPoints(id) ) {
                element.value = currentvalue;
                return false;
            }
        }
        updateCartPrice( id, (element.value=='')?(0):(element.value));
	} // * * *

    function alter( id, element ) {
        if(element.value<0) {
            element.value=0;
        }
        var ipt = core.$('item_points_total_' + id);
        if( ipt ) {
    		var oPoints = core.$( 'users_points' );
            var oCartPoints = core.$( 'cart_points' );
            setCartPoints( id, element );
            if ( !checkCartPoints( id, element ) ) {
                var totalpoints = totals();
                element.value -= (totalpoints - oPoints.value);
                ipt.value = element.value;
            }
        }
        updateCartPrice( id, (element.value=='')?(0):(element.value));
	} // * * *
	
	function checkCartPoints( id ) { //points
		var oPoints = core.$( 'users_points' );
        var oCartPoints = core.$( 'cart_points' );
        if( ( (oCartPoints.value*1)<0 ) ) {
            oCartPoints.value=0;
            alert("You've used all your free items.");
            return false;
        }
		ajaxEvent(
			'/my-cart/product_config_list',
			document.getElementById('product_config_list_container'),
			true,
			true
		);
        return true;
	} // * * *



	function updateItemPrice( itemid, oSelector ) {
		//selected product ID
		var productid = oSelector.options[oSelector.selectedIndex].id;
		UpdateSingleField( false, 'carts_files_products', itemid, 'products_id', productid );

		//selected product price
		var itemprice = core.$( 'product_price_' + itemid );	
		itemprice.value = oSelector.options[oSelector.selectedIndex].title;

		//update static item price value	
		core.$( 'item_price_'+itemid ).innerHTML = itemprice.value;

		var quantity = core.$( 'product_quantity_'+itemid ).value;
		updateCartPrice( itemid, quantity );
		
	} // * * *

	
	function removeCartThing( itemID ) {
		UpdateSingleField( false, 'carts_files', itemID, 'status_id', 5 );
		eradicateCartItem( itemID );
		setTotals();
	} // * * *

	function removeCartItem( cfp_id, cf_id, cf_fid ) {
		vpixWaitScreen( 'flayot' );
		UpdateSingleField(
			false, 'carts_files_products', cfp_id, 'status_id', 5
		);
		ajaxEvent( '/my-cart/carts_files_products/?_context=carts_files&_id=' + cf_id + '&files_id=' + cf_fid,
			core.$( 'carts_files_products_lookup_callback_' + cf_id ), false, true
		);
		axeElement( 'product_container_'+cfp_id );
		axeElement( 'flayot' );
		setTotals();
	} // * * *

	function eradicateCartItem( cf_id ) {
		var elementID = 'carts_files_' + cf_id;
		axeElement( elementID );
	} // * * *
	
	function axeElement( elementID ) {
		var oElement = core.$( elementID );
		if(!oElement) { return false; }
        oElement.parentNode.removeChild( oElement );
	} // * * *

	function vpixWaitScreen(lsElementName) {
        return;
	} // * * *
	
	function trace() {
		alert(arguments[0]);
	}
	

