$(document).ready(function(){
/*******************************************************************************
ADJUST HEIGHT of #header_nav on navigation :hover
	- adjust_height defined outside of document.ready, bottom of file
	- columnizer is used in press and press_article to add columns
		without editingsource
********************************************************************************/
/*	$("a.adjust_height_test").hover(function() {
		adjust_height();
	}, function(){
		adjust_height();
	});
*/
/*********************************************************
Scrollable Features
	not pretty, but gets the job done smoothly.
*********************************************************/
	$(".prev .set_two_current").hide();
	$(".prev .set_three_current").hide();
	$(".next .set_two_current").hide();
	$(".next .set_three_current").hide();

	$(".items_nav a").click(function(){
		return false;
	});

	$(".set_one a").click(function(){
		$("ul.featured_items").animate({marginLeft: "0"}, 500);
		$("ul.featured_pagination li a").removeClass("current");
		$(".set_one a").addClass("current");
		$(".set_two_current, .set_three_current").hide();
		$(".set_one_current").show();
		return false;
	});
		$(".next .set_one_current").click(function(){
			$("ul.featured_items").animate({marginLeft: "-909px"}, 500);
			$("ul.featured_pagination li a").removeClass("current");
			$(".set_two a").addClass("current");
			$(".next .set_one_current, .next .set_three_current").hide();
			$(".next .set_two_current").show();
			$(".prev .set_one_current, .prev .set_three_current").hide();
			$(".prev .set_two_current").show();
			return false;
		});

	$(".set_two a").click(function(){
		$("ul.featured_items").animate({marginLeft: "-909px"}, 500);
		$("ul.featured_pagination li a").removeClass("current");
		$(".set_two a").addClass("current");
		$(".set_one_current, .set_three_current").hide();
		$(".set_two_current").show();
		return false;
	});
		$(".prev .set_two_current").click(function(){
			$("ul.featured_items").animate({marginLeft: "0"}, 500);
			$("ul.featured_pagination li a").removeClass("current");
			$(".set_one a").addClass("current");
			$(".next .set_two_current, .next .set_three_current").hide();
			$(".next .set_one_current").show();
			$(".prev .set_two_current, .prev .set_three_current").hide();
			$(".prev .set_one_current").show();
			return false;
		});
		$(".next .set_two_current").click(function(){
			$("ul.featured_items").animate({marginLeft: "-1818px"}, 500);
			$("ul.featured_pagination li a").removeClass("current");
			$(".set_three a").addClass("current");
			$(".next .set_one_current, .next .set_two_current").hide();
			$(".next .set_three_current").show();
			$(".prev .set_one_current, .prev .set_two_current").hide();
			$(".prev .set_three_current").show();
			return false;
		});


	$(".set_three a").click(function(){
		$("ul.featured_items").animate({marginLeft: "-1818px"}, 500);
		$("ul.featured_pagination li a").removeClass("current");
		$(".set_three a").addClass("current");
		$(".set_one_current, .set_two_current").hide();
		$(".set_three_current").show();
		return false;
	});
		$(".prev .set_three_current").click(function(){
			$("ul.featured_items").animate({marginLeft: "-909px"}, 500);
			$("ul.featured_pagination li a").removeClass("current");
			$(".set_two a").addClass("current");
			$(".prev .set_one_current, .prev .set_three_current").hide();
			$(".prev .set_two_current").show();
			$(".next .set_one_current, .next .set_three_current").hide();
			$(".next .set_two_current").show();
			return false;
		});

/*********************************************************************
BREADCRUMBS
	- add class to li.current's previous LI.
	- wish we could do more w/ hovers as well, but need to move on.
**********************************************************************/
	$("ul.breadcrumbs li").removeClass("current_pre");
	$("ul.breadcrumbs li.current").prev("li").addClass("current_pre");

	// minor footer adjustments (CSS3 in IE 6 and 7)
	$("#footer_nav li:last-child").css({'padding-right': '0'});

	// replace target="_blank"
	$("[rel='external']").click(function(){
		this.target = "_blank";
	});

	// SYSTEM INFO on homepage featured items
	// $("ul.featured_items .system_info").hide();
	$("ul.featured_items h3, .system h3").css("cursor", "pointer");
	$("ul.featured_items h3").click(function() {
		if ($(this).is(".open")) {
			$(this).removeClass("open");
			$(this).parent("div.product_details").animate({marginTop: "128px", height: "47px"}, 500);
			// $(this).next(".system_info").removeClass("system_info_open");
		} else {
			$(this).addClass("open");
			$(this).parent("div.product_details").animate({marginTop: "28px", height: "150px"}, 500);
		}
	});
	$(".system h3").click(function() {
		if ($(this).is(".open")) {
			$(this).removeClass("open");
			$(this).find("+ ul.product_info").slideUp("fast");
		} else {
			$(this).addClass("open");
			$(this).find("+ ul.product_info").slideDown("fast");
		}
	});
	// Newsletter fields
	// contact form fields
	$(".name").focus(function(){
		if(this.value == "Your full name"){
			this.value = "";
		}
	});
	$(".name").blur(function(){
		if(this.value == ""){
			this.value = "Your full name";
		}
	});
	$(".name_first").focus(function(){
		if(this.value == "First name"){
			this.value = "";
		}
	});
	$(".name_first").blur(function(){
		if(this.value == ""){
			this.value = "First name";
		}
	});
	$(".name_last").focus(function(){
		if(this.value == "Last name"){
			this.value = "";
		}
	});
	$(".name_last").blur(function(){
		if(this.value == ""){
			this.value = "Last name";
		}
	});
	$(".phone").focus(function(){
		if(this.value == "Phone number"){
			this.value = "";
		}
	});
	$(".phone").blur(function(){
		if(this.value == ""){
			this.value = "Phone number";
		}
	});

	$(".email").focus(function(){
		if(this.value == "Your email address"){
			this.value = "";
		}
	});
	$(".email").blur(function(){
		if(this.value == ""){
			this.value = "Your email address";
		}
	});
	// on load, clear all newsletter values in both the fake checkboxes and the real form
	$("div.newsletter input:checkbox").each( function() {
		$(this).attr('checked', false);
	});
	$("input:checkbox").each( function() {
		$("#fake_audio,#fake_navigation,#marine").removeClass("fakechecked");
	});
	// function to 'check' the fake ones and their matching checkboxes
	$(".fakecheck").click(function(){
		if ($(this).hasClass('fakedisabled'))
		{
			// Don't touch these
			return false;
		}

		($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
		$(this.hash).trigger("click");
		return false;
	});

	// toggles ALL the checkboxes and ALL of the fake checkboxes
	var checkedState = false;
	 $('#group a#fake_all').click(function() {
		$("input[type=checkbox]").attr("checked",!checkedState);
		checkedState = !checkedState;
		if ($(this).is(".fakechecked")) {
			$("#group a.fakecheck").addClass("fakechecked");
		} else {
			$("#group a.fakecheck").removeClass("fakechecked");
		}
		return false;
	 });

	// PRODUCT_NAV
	$("ul.product_nav li:last-child").addClass("last_child");
	$("ul.product_nav li:first-child").addClass("first_child");
	// IE 6 needs :hover on the LI
	$("ul.product_nav li:first-child").not("ul.product_nav li.current:first-child").hover(function() {
			$(this).css("background-position","bottom left");
		},
		function() {
			$(this).css("background-position","top left");
		}
	);
	// js/colorbox/ (we're replaveing the old "lightbox" in this case. So let's stick w/ rel=lightbox

	$("a[rel='lightbox']").colorbox({opacity: 0.8, transition:'none'});
	/* $("a[rel='lightbox_inline']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline"}); */

	//added support for up to 5 inline popups
	$("a[rel='lightbox_inline']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline"});
	$("a[rel='lightbox_inline_01']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline_01"});
	$("a[rel='lightbox_inline_02']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline_02"});
	$("a[rel='lightbox_inline_03']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline_03"});
	$("a[rel='lightbox_inline_04']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline_04"});
	$("a[rel='lightbox_inline_05']").colorbox({opacity: 0.8, transition:'none', inline:true, href:"#lightbox_inline_05"});


/************************************************************/
	// PRODUCT HERO images, get src of clicked image
	// remove "th" from the end of the filename
	$("ul.viewer li img").click(function() {
		$("ul.viewer li").removeClass("current");
		$(this).parent("li").addClass("current");
		var product = $(this).attr('src');
		// alert (product);
		match = /(.*).{2}(\..*)/.exec(product);
		result = match[1]+'lg'+match[2];
	   $("#product_hero").attr('src', result);
	});

	// jquery.cluetip.js
	$("a.snapshot").cluetip({
		hoverClass: 'highlight',
		width: 460,
		sticky: false,
		cursor: 'arrow',
		attribute: 'rel',
		arrows: 'true',
		clickThrough: 'true',
		// closePosition: 'top',
		positionBy: 'mouse',
		//truncate: 60,
		leftOffset: 20,
		cluetipClass: 'rounded_alpine',
		dropShadow: false,
		ajaxSettings: {
			type: 'POST'
			}
	});
	// power rating hovers on each product page
	$('a.title,a.p_rating').cluetip({
		splitTitle: '|',
		sticky: false,
		hoverClass: 'highlight',
		width: 250,
		cursor: 'arrow',
		attribute: 'rel',
		arrows: 'true',
		clickThrough: 'true',
		// closePosition: 'top',
		positionBy: 'mouse',
		//truncate: 60,
		leftOffset: 20,
		cluetipClass: 'rounded_alpine_title',
		dropShadow: false
	});
	/******************************************************************************************
	VERTICAL CENTERING
		- this JS is duplicated in filter.php file (we need to deal w/ those ajax results inline)
	/*************************************************************************************/
	/*$('.pic').each(
		function(){
			var top = (142 - $(this).children('img').height() ) / 2;
			$(this).children('img').css('margin-top', top);
		}
	); */
});
/*********************************************************
RUN OUTSIDE OF JQUERY'S DOCUMENT.READY
	- This MUST remain outside of document.ready
*********************************************************/
// called from external Interface
function adjust_height(){
	if ($("#header_wrap").not(".home #header_wrap").height() > "400") {
		$("#header_wrap").css("height","90px");
		// alert ("Height adjusted to 90");
	} else {
		$("#header_wrap").not(".home #header_wrap").css("height","468px");
		// alert ("Height adjusted to 468");
	}
}
function h(text)
{
	return $('<p>').text(text).html();
}