//jquery actions

//Toggle CVV panel
$(document).ready(function(){
    $("#cvvlink").click(function () {
      $("#cvvdesc").toggle();
    });
    
    $("#closecvv").click(function () {
      $("#cvvdesc").toggle();
    });
    
    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = true;
    
    $('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.infiniteCarousel').trigger('next');
        }
    }, 8000);
    
});

// Cufon replacements
//Cufon.replace('h1, #secondary-nav h2, #p-additional h2, #p-xsell h2');

// JavaScript Document
function ZoomImage(sPicURL,sStoreName) {      
window.open( "/html/zoom.html?"+sPicURL, "","resizable=1,height=300,width=300");    
}

function SelectBrand(oSelect)
 {
   if(oSelect)
   {
	  var strUrl = oSelect.options[oSelect.options.selectedIndex].value;
	  if(strUrl != "")
	  {
		location.href = strUrl;
	  }
   }
 }

function PopUp(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function ToggleItem(myItem) {
	if (myItem.style.visibility != 'hidden') {
		HideItem(myItem);
	} else {
		ShowItem(myItem);
	}
	return false;
}
function ShowItem(myItem) {
	myItem.style.visibility = 'visible';
	myItem.style.display = '';
}
function HideItem(myItem) {
	myItem.style.visibility = 'hidden';
	myItem.style.display = 'none';
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}



                    function goInStock(id) {
                    	var outOfStock = document.getElementById('outofstockline' + id);
                    	var inStock = document.getElementById('addtobasketline' + id);
                    	var outOfStockMessage = document.getElementById('outofstockmessage' + id);
                    	outOfStock.style.display = 'none';
                    	outOfStock.style.visibility = 'hidden';
                    	outOfStockMessage.style.display = 'none';
                    	outOfStockMessage.style.visibility = 'hidden';
                    	inStock.style.display = '';
                    	inStock.style.visibility = 'visible';

                    }

                    function goOutOfStock(id) {
                    	var outOfStock = document.getElementById('outofstockline' + id);
                    	var inStock = document.getElementById('addtobasketline' + id);
                    	var outOfStockMessage = document.getElementById('outofstockmessage' + id);
                    	inStock.style.display = 'none';
                    	inStock.style.visibility = 'hidden';
                    	outOfStockMessage.style.display = '';
                    	outOfStockMessage.style.visibility = 'visible';
                    	outOfStock.style.display = '';
                    	outOfStock.style.visibility = 'visible';
                    }



                    function checkStock(id,outOfStockItems) {
                    	// Build up out options selections

                    	var selections = new Array();
                    	var selectionCount = 0;
                    	for (i=0;i<document.getElementById('options' + id).elements.length;i++) {
                    		var element = document.getElementById('options' + id).elements[i];
                    		if(element.name.substring(0,6)=='OPT_ID') {
                    			switch(element.type)
                    			{
                    				case 'checkbox':
                    					// is this checkbox selected?
                    					if(element.checked == true) {
                    						// use this ID
                    						selections[selectionCount]=element.value;
                    						selectionCount++;
                    					} else {
                    						// otherwise we have to get out the nocheckvalue
                    						var nocheck = document.getElementById('options' + id).elements['NOCHECK_' + element.name]
                    						selections[selectionCount]=nocheck.value;
                    						selectionCount++;
                    					}
                    					break;

                    				case 'radio':
                    					if(element.checked == true) {
                    						selections[selectionCount]=element.value;
                    						selectionCount++;
                    					}
                    					break;

                    				case 'select-one':
                    					selections[selectionCount]=element.value;
                    					selectionCount++;
                    					break;

                    				default:
                    					break;

                    			}

                    		}

                    	}

                    	selections = (selections.sort());
                    	var selection = selections.join('-');
                    	var isOutOfStock = false;

                    	// Does this combination exist in out outofstock array?
                    	for(i=0; i<outOfStockItems.length; i++) {
                    		if(outOfStockItems[i]==selection) {
                    			isOutOfStock = true;
                    			break;
                    		}
                    	}

                    	if(isOutOfStock) {
                    		goOutOfStock(id);
                    	} else {
                    		goInStock(id);
                    	}
                    }