
var addToBagPrev = '';

jQuery(document).ready(function(){
	
	/* fancy boxes for pattern pages */
	jQuery("a.patternPhoto").fancybox({
		enableEscapeButton : true
	});
	jQuery('a.fancyAjax').fancybox({
		enableEscapeButton : true,
		frameWidth: 620,
		frameHeight: 400 ,
		callbackOnShow:  printLinkHook  // catches print links and binds actions to them
	
	});
	
	/* add to cart functionality */
	jQuery('li.addToBag').hover(function(){
		addToBagPrev = jQuery(this).children('div').css('color');
		jQuery(this).children('div').css({
			'cursor': 'pointer',
			'color': '#990000'
		});
		jQuery(this).find('input:submit').css('background-position', '0 -26px');
	},
	function(){
		jQuery(this).children('div').css({
			'color': addToBagPrev,
			'cursor': 'normal'
		});
		jQuery(this).find('input:submit').css('background-position', '0 0');
	});
	
	jQuery('li.addToBag').bind('click',function(){
		jQuery(this).children('form').submit();
	});
	
	printLinkHook();
	
	
	//if we've been sent to a print page, hide the printer icon and bring up the print dialog
	if (window.location.hash == '#print'){
		window.print();
	}
	
	
});

function printLinkHook(){
	/* print this info */
	/* shouldn't have to use jQuery.data for this, but for some reason bill gates' pile of crap browser 
	doesn't want to work properly without this gigantic hacktitude */ 
	try{
		jQuery(window).data('popUrl', this.itemArray[0].href); 
	} catch(err)  {
		jQuery(window).data('popUrl','');
	}
	jQuery('#printThis a').unbind('click');
	jQuery('#printThis a').bind('click',function(){
	
		if (jQuery(window).data('popUrl') !== ''){
			popup(jQuery(window).data('popUrl')+"#print");			
		} else {
			window.print();
		}
		return false;
	});
}


function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = ""
	// If Dynamic Style is supported, clear the style
	if (el.style) el.style.cssText = ""
}

function setDefault(el) {
  el.value = el.defaultValue
}

function popup(url) {
	newwindow = window.open(url,'name','width=620,height=560'+',scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}
