/**
 * Clears text input fields of their value
 * @param element The document text element to clear
 * @param defaultValue
 */
function clearTextInput(element, defaultValue)
{
	if (defaultValue != undefined) {
		if (element.value == defaultValue) {
			element.value = '';
		}
	} else {
		element.value = '';
	}
}

/**
 * Sets text input fields to their value
 * @param element The document text element to clear
 * @param defaultValue
 */
function setTextInput(element, defaultValue)
{
	if (element.value == '') {
		element.value = defaultValue;
	}
}

/**
 * Sets the "checked" property of all info cart items
 */
function checkAllInfoCartItems()
{
	var infoCartItems = document.getElementsByTagName('input');
	for (var i = 0; i < infoCartItems.length; i++) {
		if (infoCartItems[i].type == 'checkbox') {
			infoCartItems[i].checked = 'checked';
		}
	}
}

/**
 * Replaces an img's src
 * @param img Image to target
 * @param src New source
 */
function swapProductImage(img, src)
{
	document.getElementById(img).src = src
}

/**
 * Opens a document in a new window
 * @param doc
 */
function ViewDoc(doc)
{
	window.open(doc);		
}




jQuery(window).load(function() {
	
	// IE6 SuckerFish Menu Fix
	if (jQuery.browser.msie == true && jQuery.browser.version.indexOf("6") == 0) {
		jQuery("#nav li").hover(
			function () {
			jQuery(this).addClass("sfhover");
			}, 
			function () {
			jQuery(this).removeClass("sfhover");
			}
		);
		
		jQuery("#nav li.menu-0").hover(
			function () {
			jQuery(this).addClass("firsthover");
			}, 
			function () {
			jQuery(this).removeClass("firsthover");
			}
		);
		
		jQuery("#nav li.last, #nav li.menu-6").hover(
			function () {
			jQuery(this).addClass("lasthover");
			}, 
			function () {
			jQuery(this).removeClass("lasthover");
			}
		);
		
		jQuery("#nav li.sub, #nav li.menu-0, #nav li.menu-1, #nav li.menu-2, #nav li.menu-3, #nav li.menu-5, #nav li.menu-6").hover(
			function () {
			jQuery(this).addClass("submenu");
			}, 
			function () {
			jQuery(this).removeClass("submenu");
			}
		);
	}
	
	// Search
	jQuery("#search .input-text").focus(function() {
		if (this.value == "Site Search") {
			this.value = "";
		}
	}).blur(function() {
		if (this.value == "") {
			this.value = "Site Search";
		}
	});
	
	// Tabs
	jQuery(".tabs").tabs();
	
	// Open external links in a new window
	jQuery("a[rel='external']").attr("target", "_blank");
	
	// fancyzoom
	try {
		jQuery("a.fancyzoom").fancyZoom({directory: "/ui/css/img/fancyzoom"});
	} catch(e) {}
	
	jQuery("#product_catalog tr").first().addClass("first");
	
});

