/**
 * Wine Cellarage specific JavaScript 
 *
 */
 
 
// collapsable shopping options

document.observe("dom:loaded", function() {	
	
	if(!$$('.narrowed-category li').size()){

		$$('#narrow-by-list dd').invoke('hide');
		
		$$('#narrow-by-list dt').invoke('observe', 'click', function(){
			$$('narrow-by-list dt.active').invoke('removeClassName', 'active');
			
					
			var selected = $(this).next('dd');

			if(selected.visible()){
				Effect.SlideUp(selected, { duration: .5 });
				$(this).removeClassName('active');
			}else{
				Effect.SlideDown(selected, { duration: .5 });
				$(this).addClassName('active');
			}
				

		}).invoke('observe', 'dblclick', function(){
			clearSelection();
		});

	}
		
});
 
function clearSelection() {
   var sel ;
   if(document.selection && document.selection.empty){
     document.selection.empty() ;
   } else if(window.getSelection) {
     sel=window.getSelection();
     if(sel && sel.removeAllRanges)
       sel.removeAllRanges() ;
   }
} 
 
 
 

function getSkinUrl(path) {
	return SKIN_URL + path;
}

function logoEffect(){
	if (! document.images) return false;
	
	/* Turning this feature off temporarily for poor performance */
	return false;
	
	if (document.wclogo.src.indexOf('logo.gif')>0) {
		document.wclogo.src = getSkinUrl('images/logo_ani.gif?'+Math.random());
	} else {
		document.wclogo.src = getSkinUrl('images/logo.gif');
	}
}

function hideInfoBox(idx){
	// $('info-box-' + idx).hide();
}

function showInfoBox(idx){
	// Effect.Appear('info-box-' + idx);
}

function customAddToCart(url, id) {
	$('qty-popup-' + id).show();
}

function inventoryPopup() {
	window.open('http://www.winecellerage.com/printinventory', 'inventory', 'scrollbars=yes, resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, width=800, height=600');
}

function createCookie(name,value,days) {
	
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
