$(document).ready(function(){
	// newsletter signup input
	$("#header input").attr("value", "Search");
	
    $("#header input").one("click", function(){
        $("#header #search").attr("value", "");
    });

	// global links
	$('a[rel=external]').click(function(){window.open(this.href); return false});
	$('.printBtn').click(function(){window.print(); return false});
	$("#content form .button").hover(
	  function () {
			$(this).css({background: "#0066cc", color: "#fff"});
		},
		function () {
			$(this).css({background: "#fff", color: "#0066cc"});
	  }
	);
	// Nav positioning ==========================
	$("#nav ul ul").css({visibility: "hidden"});
	$("#nav li.main, #nav li.last").hover(
			  function () {
				var navOffset = $("#nav ul").offset();
				$(this).addClass("over");
				$("ul", this).css({visibility: "visible"});
				$("ul",this).hide();
				$("ul",this).fadeIn(200);
				var subOffset = this.offsetLeft;
				var subRight = $("ul",this).width()+this.offsetLeft;
				var rightEdge = $("#nav ul").width()+navOffset.left;
				if (jQuery.browser.msie) {
					var ieVersion = parseInt(jQuery.browser.version);
					if(ieVersion == 6) {
						subRight = subRight+navOffset.left-4;
					}
					if(ieVersion == 7) {
						subRight = subRight+navOffset.left+2;
					}
				}
				// move subnav left to right align:: if wider than nav
				if(subRight > rightEdge){
					var moveLeft = (rightEdge-subRight)+1;
					$("ul",this).css({marginLeft: moveLeft+"px"});
					$("ul ul",this).css({marginLeft: "auto"});
				}
			  },
			  function () {
				$("ul",this).hide();
			    $(this).removeClass("over");
			  }
			);
			
	// equal height for subnav dropdowns
	function equalHeight(group) {
	    tallest = 0;
	    group.each(function() {
	        thisHeight = $(this).height();
	        if(thisHeight > tallest) {
	            tallest = thisHeight;
	        }
	    });
	    group.height(tallest);
	}
	equalHeight($(".sub1"));
	equalHeight($(".sub1 div"));
	equalHeight($(".sub1 h3"));
	equalHeight($(".sub2"));
	equalHeight($(".sub2 div"));
	equalHeight($(".sub2 h3"));
	equalHeight($(".sub3"));
	equalHeight($(".sub3 div"));
	equalHeight($(".sub3 h3"));
	equalHeight($(".sub4"));
	equalHeight($(".sub4 div"));
	equalHeight($(".sub4 h3"));
	equalHeight($(".sub5"));
	equalHeight($(".sub5 div"));
	equalHeight($(".sub5 h3"));
	equalHeight($(".sub6"));
	equalHeight($(".sub6 div"));
	equalHeight($(".sub6 h3"));
	
	// iframe open: show overlay
	$('.showHide').click(function(){
		docHeight = $(document).height();
		$('#overlay').height(docHeight);
		$('#overlay').fadeIn(500);
		$(this.hash).fadeIn(500);
		$('body').append('<div id="overlay" style="background:none;">&nbsp;</div>');
		$('#overlay').show();
		$('#overlay').click(function(){
			$('.iframe:visible').fadeOut(400);
			$('#overlay').fadeOut(500,function () {
			        $('#overlay').remove();
			});
		});
		return false;
	});
	$('.showHideOverlay').click(function(){
		docHeight = $(document).height();
		$('#overlay').height(docHeight);
		$('#overlay').fadeIn(500);
		$(this.hash).fadeIn(500);
		$('body').append('<div id="overlay">&nbsp;</div>');
		$('#overlay').fadeIn(500);
		$('#overlay').click(function(){
			$('.iframe:visible').fadeOut(400);
			$('#overlay').fadeOut(500,function () {
			        $('#overlay').remove();
			});
		});
		return false;
	});
	
	
	// iframe close
	$('.iframe .close').click(function(){
		$(this).parent().parent().parent().fadeOut(1000);
		$('#overlay').fadeOut(500,function () {
		        $('#overlay').remove();
		});
		return false;
	});
	
	$('.closeThis').click(function() {
		var toggleBox = $(this).attr('href');
		$(toggleBox).fadeOut();
		return false;
	});
	
	// Input Button Hover
	jQuery(function($) {
		$('span.blueBdr').hover(function () {
			$(this).addClass('btnHover');
		}, function() {
			$(this).removeClass('btnHover');
		});
	});
	
	// Font resizing ========================
	//Create (or update) the value of a cookie to expire in 2 days:
	
	// COOKIES
    // User font size
	
	var originalFontSize = $('#contentWrapper').css('font-size');   
  	// Increase Font Size
  	$(".increaseFont").click(function() {
		// var userFontSize = $.cookie('userFontSize');
		// 		alert(userFontSize);
		if(userFontSize == null) {
			var currentFontSize = $('#contentWrapper').css('font-size');
		} else {
			var currentFontSize = $.cookie('fontSize');
		}
    	var currentFontSize = $('#contentWrapper').css('font-size');
    	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    	var largestFontSize = 16;
    	
    	if(currentFontSizeNum < largestFontSize-1){
    		var newFontSize = Math.floor(currentFontSizeNum + 2);
    		$('#contentWrapper').css('font-size', newFontSize);
    	}
    	else {
    		$('#contentWrapper').css('font-size', largestFontSize);
    	}
		// set cookie
		var userFontSize = currentFontSize;
		$.cookie('userFontSize', 'currentFontSize', { expires: 2 });
		alert(userFontSize);
    	return false;
  	});
  	// Decrease Font Size
  	$(".decreaseFont").click(function() {
    	var currentFontSize = $('#contentWrapper').css('font-size');
    	var currentFontSizeNum = parseFloat(currentFontSize, 10);    	
    	var smallFontSize = 12;   	
    	
    	if(currentFontSizeNum > smallFontSize){
    		var newFontSize = Math.floor(currentFontSizeNum - 2);
    		$('#contentWrapper').css('font-size', newFontSize);
    	}
    	
    	else {
    		$('#contentWrapper').css('font-size', smallFontSize);
    	}
    	return false;
	});
	
	// Tool Tip/Product Info Bubble
	jQuery(function($) {
		$('a.tooltip').mouseover(function(e) {
			var popup_div = $(this).attr('rel');

			var tipPos = $(this).position();		
			var popx = tipPos.left;
			var popy = tipPos.top;

			var wordWidth = $(this).width();
			var wordHeight = $(popup_div).height();

			//leftVal = popx + (wordWidth*2)+"px";
			//topVal = popy-(wordHeight*2)+"px";
			leftVal = (e.pageX+10)+"px";
			topVal = (e.pageY-28)+"px";

			$(popup_div).css({left:leftVal,top:topVal}).show().end();
			return false;	
		});				
		$('a.tooltip').mouseout(function() {	
			var popup_div = $(this).attr('rel');
			$(popup_div).hover(function() {	
				$(this).show();
			}, function() {
				$(this).hide();
			});
			$(popup_div).hide();
		});
	});

// end ready function
});





