// *************************************
// Begin javascript for product showcase
// *************************************

function mycarousel_itemLoadCallback(carousel, state)
{		 
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }	 
		 
    jQuery.get(
        'page/showcase_ajax.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );	 
};		 
		 
function mycarousel_itemAddCallback(carousel, first, last, xml)
{		 
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));
		 
    jQuery('product', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });	 
};		 
		 
/**		 
 * Item html creation helper.
 */		 
function mycarousel_getItemHTML(prod)
{		 
    var prodinfo = prod.split("|");
    return '<a href="'+prodinfo[2]+'"><img src="' + prodinfo[0] + '" height="100px" title="'+prodinfo[1]+'" /></a>';
};		 	

// *************************************
// End javascript for product showcase
// ************************************* 

// *************************************
// Begin javascript for top sellers
// *************************************

function mycarousel2_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'page/topsellers_ajax.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel2_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel2_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('product', xml).each(function(i) {
        carousel.add(first + i, mycarousel2_getItemHTML(jQuery(this).text()));
    });
};

/**
 * Item html creation helper.
 */
function mycarousel2_getItemHTML(prod)
{
    var prodinfo = prod.split("|");
    return '<a href="'+prodinfo[2]+'"><img src="' + prodinfo[0] + '" height="100px" title="'+prodinfo[1]+'" /></a>';
};

/**
* Create a Var to handle options in the lefthand vertical dock
**/
var opts1 =
	// vertical menu with expansion point along the center axis
{ align: 'center'
  // set the maximum minor axis (vertical) image dimension
, size: 90
, distance: 40
, coefficient: 1
, labels: false
, duration: 300
};

/**
* Create a Var to handle options in the righthand vertical dock
**/
var opts2 =
	// vertical menu with expansion point along the center axis
{ align: 'center'
  // set the maximum minor axis (vertical) image dimension
, size: 120
, distance: 20
, coefficient: 1.5
, labels: false
, duration: 300
};


//jQuery instantiation for all areas

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.
		scroll: 6,
		visible: 6,
        //itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback
    });
    
    jQuery('#mycarousel2').jcarousel({
        // Uncomment the following option if you want items
        // which are outside the visible range to be removed
        // from the DOM.
        // Useful for carousels with MANY items.
		scroll: 6,
		visible: 6,
        //itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel2_itemLoadCallback
    });
    
    jQuery('#leftMenu').jqDock(opts1);
    jQuery('#rightMenu').jqDock(opts2);
});	


// *************************************
// "Bookmark Us" Javascript
// *************************************

function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}


// ****************************************
// Copy Billing Address to Shipping Address
// ****************************************


function InitSaveVariables(form) {
	sname = form.sname.value;
	saddress = form.saddress.value;
	saddress2 = form.saddress2.value;
	scity = form.scity.value;
	sstateIndex = form.sstate.selectedIndex;
	sstate = form.sstate[sstateIndex].value;
	sstate2 = form.sstate2.value;
	scountryIndex = form.scountry.selectedIndex;
	scountry = form.scountry[sstateIndex].value;
	szip = form.szip.value;
	sphone = form.sphone.value;
}

function ShipToBillPerson(form) {

	var sname = "";
	var saddress = "";
	var saddress2 = "";
	var scity = "";
	var sstate = "";
	var sstateIndex = 0;
	var state2 = "";
	var country = "";
	var scountryIndex = 0;
	var szip = "";
	var sphone = "";
	
	if (form.copy.checked) {
		InitSaveVariables(form);
		form.sname.value = form.name.value;
		form.saddress.value = form.address.value;
		form.saddress2.value = form.address2.value;
		form.scity.value = form.city.value;
		form.sstate.selectedIndex = form.state.selectedIndex;
		form.sstate2.value = form.state2.value;
		form.scountry.selectedIndex = form.country.selectedIndex;
		form.szip.value = form.zip.value;
		form.sphone.value = form.phone.value;
	} else {
		form.sname.value = sname;
		form.saddress.value = saddress;
		form.saddress2.value = saddress2;
		form.scity.value = scity;
		form.sstate.selectedIndex = sstateIndex;
		form.sstate2.value = sstate2;
		form.scountry.selectedIndex = scountryIndex;
		form.szip.value = szip;
		form.sphone.value = sphone;
   }
}