/*======================================================================
	Hayward Pools: JavaScript Functions
	--------------------------------------------------------------------
	Author: Jay Sylvester
	Company: WebLinc
	Date: 09.01.09
----------------------------------------------------------------------*/

/* jQuery no conflict so jQuery can play nice with other JS libraries */
jQuery.noConflict();

var WEBLINC = {};

function set_cookie(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 get_cookie( name )
{
    var name_eq = 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(name_eq) == 0) return c.substring(name_eq.length,c.length);
    }
    
    return null;
}
	
//function setBGPos(divOffSet) {
//	obj = document.getElementById('body-container');
//	var curleft = curtop = 0;
//	if (obj.offsetParent) {
//		curleft = obj.offsetLeft
//		curtop = obj.offsetTop
//		while (obj = obj.offsetParent) {
//			curleft += obj.offsetLeft
//			curtop += obj.offsetTop
//		}
//	}
//	if (document.getElementById) {
//		topPos = 166 - (curtop - 181);
//		alert(curtop);
//		alert(divOffSet);
//		alert(topPos);
//		document.getElementById('page-container').style.backgroundPosition = "0px "+topPos+"px";
//	}
//}
	
jQuery(document).ready(function() {
	/*======================================================================
		UTILITY SELECT MENU'S
		--------------------------------------------------------------------
		Graphical select menu handlers
	----------------------------------------------------------------------*/
		var $optionSelectors = jQuery('#utility-nav ul.option-selector > li');
		
		jQuery('> a',$optionSelectors).click(function() { return false; });
				
		$optionSelectors.hover(
			function () {
				jQuery('> ul',this).show();
			}, 
			function () {
				jQuery('> ul',this).hide();
			}
		);

	/*======================================================================
		TEXT INPUT CLEARING/REINSTATING
		--------------------------------------------------------------------
		Handles text input clearing of text on focus, and reinstate on blur
	----------------------------------------------------------------------*/
		WEBLINC.focusInputs =
		{
			init: function(obj)
			{
				var searchInitVal = obj.val();
				
				obj.focus(function() {
					if(jQuery(this).val() == searchInitVal)
						jQuery(this).val("").removeClass("hint");
				})
				.blur(function() {
					if(jQuery(this).val() == "")
						jQuery(this).val(searchInitVal).addClass("hint");
				});
			}
		}
		
		// init the global inputs on ready
		WEBLINC.focusInputs.init(jQuery('#search-form-container .input-text'));
		WEBLINC.focusInputs.init(jQuery('#email-signup-container .input-text'));
		WEBLINC.focusInputs.init(jQuery('.landing-search .input-text'));

	/*======================================================================
		TEXT RESIZING
		--------------------------------------------------------------------
		Handles text size changes from utility nav options
	----------------------------------------------------------------------*/
		var $textSizeSelectors = jQuery('#utility-nav .text-size');
		
		jQuery('li a',$textSizeSelectors).click(function() {
			var $body = jQuery("body"),
				$this = jQuery(this);

			jQuery('li',$textSizeSelectors).removeClass('active');

			switch($this.closest('li').attr('class'))
			{
				case 'small':
					$body.css("font-size","62.5%");
					set_cookie('font-size', '62.5%', 7);
					break;
				case 'medium':
					$body.css("font-size","70%");
					set_cookie('font-size', '70%', 7);
					break;
				case 'large':
					$body.css("font-size","80%");
					set_cookie('font-size', '80%', 7);
					break;
			}
			
			$this.closest('li').addClass('active');
			return false;
		});
});



// Additional D2 Scripts

function showHide(obj) {
alert(obj);
	var obj = document.getElementById(obj);
	alert(obj.style.display);
	if(obj.style.display != 'none') obj.style.display = 'none';
	else obj.style.display = 'block';
}


// Google Analytics - Single domain code (needs to be updated to support multiple domains)

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1195124-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();


