var loadImage = new Image();					// holds the loading image
var tmpImage = new Array();
var effectFinished = true;
//var effectKeepScrolling = false;
var endPointer = 0;
var rightPointer = 0;
var currentProduct = 0;							// current selected product ID
var currentColor = 0;							// holds the current selected color ID
var currentProductInformation; 					// holds the product information
var shoppingCartHrefHoldText; 
var sideImageLastChecked='';						// holds the ID of the last selected color on the side, used to set the opactiy back to 1.0

loadImage.src = "./images/loading.gif";

// -- Left right arrows
var imageLeftArrow = new Image; imageLeftArrow.src = './images/left_arrow.jpg';
var imageLeftArrowHover = new Image; imageLeftArrowHover.src = './images/left_arrow_hover.jpg';
var imageRightArrow = new Image; imageRightArrow.src = './images/right_arrow.jpg';
var imageRightArrowHover = new Image; imageRightArrowHover.src = './images/right_arrow_hover.jpg';

function swapImage(objId,objImg) {
	$(objId).src = eval(objImg + ".src"); }

function initScroll() {
	/*
	Event.observe('mouseOverRight','mouseover',scrollKeepRight);
	Event.observe('mouseOverLeft','mouseover',scrollKeepLeft);
	Event.observe('mouseOverRight','mouseout',scrollStop);
	*/		
	//$('productDetailShoppingCart').style.display = 'none';
	//$('productLoadOverlay').position({ relativeTo: $('product_table'), position: 'center', edge: 'center' });
	$('productLoadOverlay').setPosition({x : ($('product_table').offsetLeft-5),y: (($('product_table').offsetTop-$('product_table').getCoordinates().height)+300)});
	$('productLoadOverlay').style.display = 'block';

	for(i=0;i<8;i++) {
		scrollAddProduct(); } 

	selectProduct(productIds['0']);
	shoppingCartHrefHoldText = $('shoppingCartInformationTableClickCart').innerHTML;

	}
function scrollEffectFinished() { effectFinished = true; }

function scrollMoveRight() {
	scrollAddProduct();
	if ((rightPointer+8) <= productIds.length) {
		if (effectFinished == true) {
			effectFinished = false;
			new Fx.Tween('imageBoxInside',{ transition: Fx.Transitions.Linear , duration : 100 , onComplete: function() { effectFinished= true; }  }).start('left',(rightPointer*(-108)),(rightPointer*(-108))-108);
			rightPointer++;
		}
	}
}
function scrollMoveLeft() {
	if (effectFinished == true) {
			if (rightPointer != 0) { 
				effectFinished = false;
				new Fx.Tween('imageBoxInside',{ transition: Fx.Transitions.Linear , duration : 100 , onComplete: function() { effectFinished= true; }  }).start('left',(rightPointer*(-108)),(rightPointer*(-108))+108);
				rightPointer=rightPointer-1 }
	 	}
}

/*
function scrollKeepRight() {
	scrollMoveRight();
	effectKeepScrolling = setTimeout("scrollKeepRight()",5); }

function scrollKeepLeft() {
	scrollMoveLeft();
	effectKeepScrolling = setTimeout("scrollKeepLeft()",5); }
function scrollStop() {
	clearTimeout(effectKeepScrolling ); }
*/

function scrollAddProduct() {
	if ((endPointer+1) <= productIds.length) {
		var tbl = $('productTableRow');
		var newCell = tbl.insertCell(endPointer);
		newCell.innerHTML="<a href=\"javascript:void(0);\" onclick=\"selectProduct('" + productIds[endPointer] + "'); return true;\"><img src=\"\" class=scroll_image id=productImage" + productIds[endPointer]  + "></a><br>" + productDescriptions[endPointer]; 
		
		var image = $("productImage" + productIds[endPointer]);
		image.src = loadImage.src;
		tmpImage[endPointer] = new Image();
		if (currentProductType == 'other') {
			tmpImage[endPointer].src = "./product_images/" + currentProductType + "_thumb_1_" + productIds[endPointer] + ".jpg"; }
		else {
			tmpImage[endPointer].src = "./product_images/" + currentProductType + "_thumb_" + productIds[endPointer] + ".jpg"; }

		tmpImage[endPointer].originalindex = endPointer;
		tmpImage[endPointer].onload = function() {
			var image = document.getElementById("productImage" + productIds[this.originalindex]);
		image.src = tmpImage[this.originalindex].src;
		tmpImage[this.originalindex].src = "" ; }

	endPointer++; } }

function selectProduct(p) {
	
	hideShoppingCartOptions();
	$('productLoadOverlay').style.display = 'block';
	$('productDetailColor').style.display = 'none';
	$('shoppingCartPrice').innerHTML = ''; 	

	if (currentProduct != 0) { 
		$('productImage' + currentProduct).set('opacity',1.0); }
	currentProduct = p;
	$('productImage' + currentProduct).set('opacity',0.5);

	$('productDetailOptions').innerHTML = '';


	new Request({url : "./products.php?action=getInfo&product=" + currentProductType + "&id=" + p, method: 'get', onSuccess: function(transport){
		var response = JSON.decode(transport);
		if (response.error != '') { alert(response.error); }
		else {
			$('viewLargeImageProductButton').set('title',response.cname);
			$('productDetailName').innerHTML =  '<b><span style="font-size:20px">' + response.cname + "</span><br><i>" + response.style + " Style </i></b>";
			$('productDetailDescription').innerHTML = "<br>" + response.description;
			currentProductInformation = response;	
			

			if (currentProductType == 'belts') {
				// -- stuff for belts
				$('productDetailName').innerHTML = $('productDetailName').innerHTML + "<br>" + response.buckle + " Buckle Finish";
				$('productDetailName').innerHTML = $('productDetailName').innerHTML + "<br>" + response.cwidth +  "mm Width";
				if (response.chicagostyle == 'YES') { $('productDetailName').innerHTML = $('productDetailName').innerHTML + "<br>Chicago Style Buckle"; }
				if (userID != '0') {
					$('productDetailOptions').innerHTML = "<br><font size=+2>$" + response.pricen + "</font><font size=-2><i><br>Oversize Price : $" + response.priceo;
					}
		
				// --- do the product colors
				$('productDetailColorDescription').innerHTML = response.colorname[0] + " Color";
				var cdat = "<table cellpadding=0 cellspacing=0 class=colorOptionsTable><tr>";
				var tdcount = 0;
				for (i=0;i<response.color.length;i++) {
					if (tdcount == 2) { cdat = cdat + "</tr><tr>"; tdcount = 0; }
					cdat = cdat + "<td><a href=\"javascript:void(0);\" onclick=\"productChangeColor('" + i + "'); return true;\">"
					cdat = cdat + "<img src=./product_images/beltscolors_thumb_" + response.color[i] + ".jpg id=colorSelector_" + i + " class=imageSize100x100></a></td>";
					tdcount++; }
				cdat = cdat + "</tr></table>";
				$('productDetailColor').innerHTML = cdat;
		
				showCheckMark('colorSelector_0');
				$('shoppingCartColor').innerHTML = response.colorname[0];
				// populate the size select box
				if (response.sizetype == 'LET') { shoppingCartpopulateSizeLetters(); }
				else { shoppingCartpopulateSizeNumbers(response.minsize,response.maxsize); }
		
				swapMainImage("./product_images/beltscolors_full_" + response.color[0] + ".jpg");
				$('viewLargeImageProductButton').set('href',"./product_images/beltscolors_large_" + response.color[0] + ".jpg");
				}

			else if (currentProductType == 'cufflinks') {
				var cdat='<table cellpadding=0 cellspacing=0 class=colorOptionsTable>'
				var dopt='';	
				if (response.price_velvet != '0.00') { 
					cdat = cdat + "<tr><td><center><img src=./images/velvet_box.jpg class=class=imageSize100x100><br>Velvet Box<br>";
					if (userID != '0') { cdat = cdat + "<b>$" + response.price_velvet + "</b></td></tr>"; }
					} 
				if (response.price_flip != '0.00') {  
					cdat = cdat + "<tr><td><center><img src=./images/flip_box.jpg class=class=imageSize100x100><br>Flip Box<br>";
					if (userID != '0') { cdat = cdat + "<b>$" + response.price_flip + "</b></td></tr>"; }
					}
				if (response.price_wood != '0.00') {  
					cdat = cdat + "<tr><td><center><img src=./images/rosewood_box.jpg class=class=imageSize100x100><br>Rose-Wood Box<br>";
					if (userID != '0') { cdat = cdat + "<b>$" + response.price_wood + "</b></td></tr>"; }
					}
				cdat = cdat + "</table>";		
				$('productDetailColor').innerHTML = cdat;
				
				shoppingCartpopulateBox();
				swapMainImage("./product_images/cufflinks_full_" + currentProduct + ".jpg");	
				$('viewLargeImageProductButton').set('href',"./product_images/cufflinks_large_" + currentProduct + ".jpg");
				}

			else if (currentProductType == 'suspenders') {
				var cdat='<table cellpadding=0 cellspacing=0 class=colorOptionsTable>';
                var holdType = '';
				var dopt='';
				if (userID != '0') {
					 dopt = "<br><br><font size=+1>$" + response.price_reg_reg + "&nbsp;-&nbsp;$" + response.price_2xl_both; }


				// --- do the product colors
				var cdat = "<table cellpadding=0 cellspacing=0 class=colorOptionsTable>";
                cdat = cdat + '<tr><td colspan=2><center><span style="font-size: 13px"><b>Regular Suspenders</b></span></center></td></tr><tr>';
                holdType = "Regular";
				var tdcount = 0;
				for (i=0;i<response.color.length;i++) {
				    if (holdType != response.type[i]) {
				        holdType = response.type[i];
                        if (tdcount == 1) { cdat = cdat + '<td></td>'; }
                        tdcount = 0;
                        cdat = cdat + '</tr><tr><td colspan=2><center><span style="font-size: 13px"><b>' + response.type[i] + ' Suspenders</b></span></center></td></tr><tr>';
                        
                        }
					if (tdcount == 2) { cdat = cdat + "</tr><tr>"; tdcount = 0; }
					cdat = cdat + "<td><a href=\"javascript:void(0);\" onclick=\"productChangeColorSuspenders('" + i + "'); return true;\">"
					cdat = cdat + "<img src=./product_images/suspenderscolors_thumb_" + response.color[i] + ".jpg id=colorSelector_" + i + " class=class=imageSize100x100></a></td>";
					tdcount++; }
				cdat = cdat + "</tr></table>";
				$('productDetailOptions').innerHTML = dopt;
				$('productDetailColor').innerHTML = cdat;

				showCheckMark('colorSelector_0');
				shoppingCartpopulateBoxSuspenders();
				$('shoppingCartColor').innerHTML = "Color: " + response.colorname[0];
				swapMainImage("./product_images/suspenderscolors_full_" + response.color[0] + ".jpg");
				$('viewLargeImageProductButton').set('href',"./product_images/suspenderscolors_large_" + response.color[0] + ".jpg");
				$('productDetailColorDescription').innerHTML = response.colorname[0] + " Color";

				}

			else if (currentProductType == 'other') {
				var cdat = "<a href=\"javascript:productChangePicture('1');\"><img src=./product_images/other_thumb_1_" + currentProduct + ".jpg id=otherThumbPicture1 class=class=imageSize100x100></a><br>";
				cdat = cdat + "<a href=\"javascript:productChangePicture('2');\"><img src=./product_images/other_thumb_2_" + currentProduct + ".jpg id=otherThumbPicture2 class=class=imageSize100x100></a><br>"; 
				cdat = cdat + "<a href=\"javascript:productChangePicture('3');\"><img src=./product_images/other_thumb_3_" + currentProduct + ".jpg id=otherThumbPicture3 class=class=imageSize100x100></a>";
				$('productDetailColor').innerHTML = cdat;
				if (userID != '0') {
					$('productDetailOptions').innerHTML = "<br><br><br><font size=+2>$" + response.price; } 
				$('shoppingCartPrice').innerHTML = "$" + response.price;

				swapMainImage("./product_images/other_full_1_" + currentProduct + ".jpg");
				$('viewLargeImageProductButton').set('href',"./product_images/other_full_1_" + currentProduct + ".jpg");
				showCheckMark('otherThumbPicture1');
				}
			}
		 },

		onFailure: function(){ alert('Something went wrong...') }
	 }).send();

	}

function swapMainImage(url) {
	$('productLoadOverlay').style.display = 'block';
	$('productDetailColor').style.display = 'none';
	$('productDetailImage').src='';
	var images = url;
	var loader = new Asset.images(images, { onComplete: function() {
		$('productDetailImage').src=images
		$('productLoadOverlay').style.display = 'none';
		$('productDetailColor').style.display = 'block'; } } );
	}

function productChangePicture(p) {
	$('productLoadOverlay').style.display = 'block';
	$('productDetailColor').style.display = 'none';
	swapMainImage("./product_images/other_full_" + p + "_" + currentProduct + ".jpg");
	$('viewLargeImageProductButton').set('href',"./product_images/other_full_" + p + "_" + currentProduct + ".jpg");
	showCheckMark('otherThumbPicture' + p);
 }


function productChangeColor(p) {
 	hideShoppingCartOptions();
	$('shoppingCartColor').innerHTML = currentProductInformation.colorname[p];
	currentColor = p;
	swapMainImage("./product_images/beltscolors_full_" + currentProductInformation.color[p] + ".jpg");
	$('viewLargeImageProductButton').set('href',"./product_images/beltscolors_large_" + currentProductInformation.color[p] + ".jpg");
	$('productDetailColorDescription').innerHTML = currentProductInformation.colorname[p] + " Color";
	showCheckMark('colorSelector_' + p); }

function productChangeColorSuspenders(p) {
	$('shoppingCartColor').innerHTML = currentProductInformation.colorname[p];
	currentColor = p;
	swapMainImage("./product_images/suspenderscolors_full_" + currentProductInformation.color[p] + ".jpg");
	$('viewLargeImageProductButton').set('href',"./product_images/suspenderscolors_large_" + currentProductInformation.color[p] + ".jpg");
	$('productDetailColorDescription').innerHTML = currentProductInformation.colorname[p] + " Color";
	showCheckMark('colorSelector_' + p); }

function showCheckMark(objTarget) {
	if(sideImageLastChecked != '') { $(sideImageLastChecked).set('opacity',1.0); }
	$(objTarget).set('opacity',0.5);
	sideImageLastChecked = objTarget; 
	

	//alert(objTarget);
	//$('colorOptionsCheckMark').setPosition({x : ($(objTarget).offsetLeft+52),y: (($(objTarget).offsetTop-$(objTarget).getCoordinates().height)+233)});
	//$('colorOptionsCheckMark').position({ relativeTo: $(objTarget), position: 'center', edge: 'centerBottom' });
	//$('colorOptionsCheckMark').style.display = 'block'; 

}

function productSelectCategory() {
	if ($('productcategory')[$('productcategory').selectedIndex].value == 'X') { alert('Please select a vaild category'); }
	else {
	document.location.href="./products.php?product=" + currentProductType + "&category=" + $('productcategory')[$('productcategory').selectedIndex].value; 
	}
}


function shoppingCartpopulateSizeLetters() {
	e = new Array('S','M','L','XL','2XL','3XL','4XL','5XL');
	v = new Array('Small','Medium','Large','Extra Large','2X Extra Large  - oversized','3X Extra large  - oversized','4X Extra Large  - oversized','5X Extra Large  - oversized');
	$('beltsize').options.length=0;	
	new Element('option' , { text: ' -- Select Size -- ', value: 'selectsize' } ).inject('beltsize'); 
	for(i=0;i<8;i++) {
		new Element('option' , { text: v[i], value: e[i] } ).inject('beltsize');
		 }
	}

// -- populates the size select box with the number sizes
function shoppingCartpopulateSizeNumbers(start,end) {
	$('beltsize').options.length=0;	
	new Element('option' , { text: ' -- Select Size -- ', value: 'selectsize' } ).inject('beltsize');
	st = parseInt(start);

	for(i=parseInt(start);i<=parseInt(end);i=i+2) {
		if (i > 44) { 
			new Element('option' , { text: 'Size ' + i + '  - oversized', value: i } ).inject('beltsize');}
		else { 
			new Element('option' , { text: 'Size ' + i, value: i } ).inject('beltsize'); } }
	}
// -- for cufflinks
function shoppingCartpopulateBox() {
	$('cuffbox').options.length=0;	
	new Element('option' , { text: ' -- Select Box Type -- ', value: 'selectbox' } ).inject('cuffbox');
	if (currentProductInformation.price_velvet != '0.00') { new Element('option' , { text: 'Velvet Box', value: 'velvet' } ).inject('cuffbox'); }
	if (currentProductInformation.price_flip != '0.00') { new Element('option' , { text: 'Flip Box', value: 'flip' } ).inject('cuffbox'); }
	if (currentProductInformation.price_wood != '0.00') { new Element('option' , { text: 'Rose-Wood Box', value: 'wood' } ).inject('cuffbox'); }
	defaultSelectItem('cuffbox','flip');
	shoppingCartChangePrice('cufflinks');
	}

// -- for suspenders
function shoppingCartpopulateBoxSuspenders() {
	$('susbox').options.length=0;	
	new Element('option' , { text: ' -- Select Box Type -- ', value: 'selectbox' } ).inject('susbox');
    new Element('option' , { text: 'None', value: 'none' } ).inject('susbox');
	if(currentProductInformation.d_box == 'YES') { new Element('option' , { text: 'Deluxe Box', value: 'delux' } ).inject('susbox'); }
	if(currentProductInformation.r_box == 'YES') { new Element('option' , { text: 'Regular Box', value: 'regular' } ).inject('susbox'); } 
	defaultSelectItem('susbox','regular');
	shoppingCartChangePrice('suspenders');
	}

// -- changes the price based on the belt size selected
function shoppingCartChangePrice(objType) {
	if (objType == 'belts') {	
		if ($('beltsize')[$('beltsize').selectedIndex].value != 'selectsize')  {
			if ($('beltsize')[$('beltsize').selectedIndex].value > 44) {
				$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.priceo; }
			else if ($('beltsize')[$('beltsize').selectedIndex].value.length > 2) {
				$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.priceo; }
			else {
				$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.pricen; } }
		else { $('shoppingCartPrice').innerHTML = '<font color=red><b>Select Options 1st</b></font>'; }
	}
	
	else if (objType == 'cufflinks') {
		if ($('cuffbox')[$('cuffbox').selectedIndex].value != 'selectbox')  {
			$('shoppingCartPrice').innerHTML = "$" + eval("currentProductInformation.price_" + $('cuffbox')[$('cuffbox').selectedIndex].value); }
		else { $('shoppingCartPrice').innerHTML = '<font color=red><b>Select Options 1st</b></font>'; }	
		}


	else if (objType == 'suspenders') {
	   
		if ($('susbox')[$('susbox').selectedIndex].value != 'selectbox' && $('selectSusSize')[$('selectSusSize').selectedIndex].value != 'select' && $('selectSusStyle')[$('selectSusStyle').selectedIndex].value != 'select')  {
			var e=0.00;
			//alert($('susbox')[$('susbox').selectedIndex].value);
			if ($('susbox')[$('susbox').selectedIndex].value == 'regular') { e=priceSuspendersRegular; }
			if ($('susbox')[$('susbox').selectedIndex].value == 'deluxe') { e=priceSuspendersDelux; }
            
            var tmp = '';
            tmp = $('selectSusSize')[$('selectSusSize').selectedIndex].value;
            tmp = tmp + $('selectSusStyle')[$('selectSusStyle').selectedIndex].value;
            
            $('shoppingCartPrice').innerHTML = "$" + (e + parseFloat(currentProductInformation[tmp]));
            
			//$('shoppingCartPrice').innerHTML = "$" + (e + parseFloat(currentProductInformation[$('sussizebox')[$('sussizebox').selectedIndex].value])); 
            }
		else { $('shoppingCartPrice').innerHTML = '<font color=red><b>Select Options 1st</b></font>'; }
		}
        
	if ($('shoppingCartPrice').innerHTML == '$NaN') { $('shoppingCartPrice').innerHTML = 'Select Product Options'; }
    
}	

// -- changes the price based on the size selected
function shoppingCartChangeBeltPrice() {
	if ($('beltsize')[$('beltsize').selectedIndex].value != 'selectsize')  {
		if ($('beltsize')[$('beltsize').selectedIndex].value > 44) {
			$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.priceo; }
		else if ($('beltsize')[$('beltsize').selectedIndex].value.length > 2) {
			$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.priceo; }
		else {
			$('shoppingCartPrice').innerHTML = "$" + currentProductInformation.pricen; } } }

// -- add item to shopping cart	
function shoppingCartAddItem(objType) {

		var url = '';
		if (objType == 'belts') {
			if ($('beltsize')[$('beltsize').selectedIndex].value == 'selectsize') { alert('Please select a size'); }
			else { url = './products.php?action=addCart&product=' + currentProductType + '&productid=' + currentProduct + '&colorid=' + currentProductInformation.color[currentColor] + '&size=' + $('beltsize')[$('beltsize').selectedIndex].value + '&qty=' + $('qty').value; }
		}
		else if (objType == 'cufflinks') {
			if ($('cuffbox')[$('cuffbox').selectedIndex].value == 'selectbox') { alert('Please select a box type'); }
			else { url = './products.php?action=addCart&product=' + currentProductType + '&productid=' + currentProduct + '&box=' + $('cuffbox')[$('cuffbox').selectedIndex].value + '&qty=' + $('qty').value; }
		}
		else if (objType == 'suspenders') {
            if ($('susbox')[$('susbox').selectedIndex].value == 'selectbox' || $('selectSusSize')[$('selectSusSize').selectedIndex].value == 'select' || $('selectSusStyle')[$('selectSusStyle').selectedIndex].value == 'select')  { alert('Please select a box type & size/style'); }
			//if ($('susbox')[$('susbox').selectedIndex].value == 'selectbox' || $('sussizebox')[$('sussizebox').selectedIndex].value == 'selectsize')  { alert('Please select a box type & size/style'); }
			//else { url = './products.php?action=addCart&product=' + currentProductType + '&productid=' + currentProduct + '&box=' + $('susbox')[$('susbox').selectedIndex].value + '&size=' + $('sussizebox')[$('sussizebox').selectedIndex].value + '&colorid=' + currentProductInformation.color[currentColor] + '&qty=' + $('qty').value; }
            
            
            else { 
                url = './products.php?action=addCart&product=' + currentProductType + '&productid=' + currentProduct + '&box=' + $('susbox')[$('susbox').selectedIndex].value;
                var tmp = '';
                tmp = $('selectSusSize')[$('selectSusSize').selectedIndex].value;
                tmp = tmp + $('selectSusStyle')[$('selectSusStyle').selectedIndex].value;
                
                url = url + '&size=' + tmp + '&colorid=' + currentProductInformation.color[currentColor] + '&qty=' + $('qty').value; }
            
            
		}
		else if (objType == 'other') {
			url = './products.php?action=addCart&product=' + currentProductType + '&productid=' + currentProduct + '&qty=' + $('qty').value; 
		}
	
		if (url !== '') {
			$('shoppingCartInformationTableClickCart').innerHTML = '<I>Adding to Cart Please Wait..</i>';
			new Request({url : url, method: 'get', onSuccess: function(transport){
				var response = JSON.decode(transport);
				if (response.error != '') { alert("ERROR:" + response.error); return false; }
				$('shoppingCartTotalItems').innerHTML = '<b>' + response.items + '</b> item(s) totaling <b>$' + response.total + '</b> in Shopping Cart';
				$('shoppingCartInformationTableClickCart').innerHTML = shoppingCartHrefHoldText;
				new Fx.Morph($('shoppingCartTotalItems'), { duration: 500  , transition: Fx.Transitions.Sine.easeOut } ).start( { 'color' : '#000000' } ).chain(function() {
				new Fx.Morph($('shoppingCartTotalItems'), { duration: 500  , transition: Fx.Transitions.Sine.easeOut } ).start( { 'color' : '#FFFFFF' } ); } );
				$('productDetailShoppingCart').fade('out');
				 },
				onFailure: function(){ alert('Something went wrong...') }
		 	}).send(); }
}

// --- Adjust the qty in the cart
function shoppingCartAdjustQty(p) {
	document.location.href='./shopping.php?action=adjustqty&id=' + p + '&qty=' + $('qty' + p).value; }

function shoppingCardEmpty() {
	var x = confirm('Are you sure you want to empty your shopping cart?');
	if (x) { document.location.href='./shopping.php?action=empty'; } }


// -- capture chr(13) on search box and submit value ( just for chris )
function searchBoxCapture(e) {
    var key;     
	if(window.event) { key = window.event.keyCode; }
	else { key = e.which; }
	if (key == 13) {
		if ($('textSearchBox').value.length < 3) { alert('Please enter a search term longer then 3 characters'); }
		else { document.location.href = "./search.php?q=" + $('textSearchBox').value } 	} }

function goSearch() { 
		if ($('textSearchBox').value.length < 3) { alert('Please enter a search term longer then 3 characters'); }
		else { document.location.href = "./search.php?q=" + $('textSearchBox').value } }

// -- Get the postion of the add to cart button, move the options box and show it
function showShoppingCartOptions() {
	if (userID == '0') { alert('You must be logged in to add items to your shopping cart'); }
	else {
		//alert($('shoppingCartAddProductButton').offsetLeft);
		$('productDetailShoppingCart').style.display = 'block';
		$('productDetailShoppingCart').setPosition({x : ($('shoppingCartAddProductButton').offsetLeft+500),y: (($('shoppingCartAddProductButton').offsetTop-$('productDetailShoppingCart').getCoordinates().height)+245)});
		$('productDetailShoppingCart').fade('in'); 
		}
	}

function hideShoppingCartOptions() { 
	$('productDetailShoppingCart').fade('out'); }

// -- Selects an item in a select box 
function defaultSelectItem(objSelect,objValue) {
for (i=0; i< $(objSelect).length; i++) {
	if (objValue ==  $(objSelect).options[i].value) {
		 $(objSelect).options[i].selected = true; break; } } }




	