$(document).ready(function(){
	// Find a pool submit Zip
	$('.submitZip').click(function(){ window.location = "find-a-pool.php?z="+$("#zip").val()+""; });
	
	// Home welcome
	$('#homeTopHook').fadeIn(1500);
	
	// Introduction
	$("div[rel]").not('.exclude').overlay({mask: '#fff', closeOnClick: false, top:25, fixed: false});

	// Products Page
	$('.pItem:eq(0)').not('.exclude').click(function(){ window.location = 'endless-pool.php'; })
	$('.pItem:eq(1)').not('.exclude').click(function(){ window.location = 'waterwell.php'; })	
	$('.pItem:eq(2)').not('.exclude').click(function(){ window.location = 'swim-spa.php'; })
	$('.pItem:eq(3)').not('.exclude').click(function(){ window.location = 'fastlane.php'; })	
	$('.pItem:eq(4)').not('.exclude').click(function(){ window.location = 'fastlane-pool.php'; })
	$('.pItem:eq(5)').not('.exclude').click(function(){ window.location = 'fiberglass-pool.php'; })	
	
	$("#primaryNav a:not('.prod'), .primaryNavLid").mouseover(function(){
		$('#flyout').slideUp(200);
		$('.prod').removeClass('prodActive');
	})
	
	
	$(".pItem").hover(function() {  
		$(this).addClass('pItemOver');
		},function() { 
		$(this).removeClass('pItemOver'); 
	}); 

	// Clear zip input
	$("#zip").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
// END DOC READY	 	
});





// Helpers & Plug-ins ////////////////////////////
// Fetch url param
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});	

// Tool tip dot pulsing
function tipPulse() {
	$(".tip").fadeTo(400, 0.7).fadeTo(900, 1, function(){tipPulse()});
}

// Manage Cookies
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

	// Form management
	function getForm(){
			  switch ($.getUrlVar('form')) {
				  	  case '28043': // Try A Pool Near You
					  		$('#formContent').load('inc/form-content.php #28043', function(){$('#subBtn').attr('value','Send')});						
					  break;					  
					  case '28042': // Email Signup
					  		$('#formContent').load('inc/form-content.php #28042', function(){$('#subBtn').attr('value','Sign Up')});
					  break;					  
					  case '28044': // Endless Pool Planning Guide
					  		$('#formContent').load('inc/form-content.php #28044', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;
					  case '28045': // Swim Spa Planning Guide
					  		$('#formContent').load('inc/form-content.php #28045', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;
					  case '28046': // Fastlane Planning Guide
					  		$('#formContent').load('inc/form-content.php #28046', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;
					  case '28047': // Fiberglass Pool Planning Guide
					  		$('#formContent').load('inc/form-content.php #28047', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;
					  case '28048': // WaterWell Planning Guide
					  		$('#formContent').load('inc/form-content.php #28048', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;
					  case '28050': // Fastlane Pool Planning Guide
					  		$('#formContent').load('inc/form-content.php #28050', function(){$('#subBtn').attr('value','Download Our Planning Guide')});
					  break;

					  case '28052': // Endless Pool Pricing
					  		$('#formContent').load('inc/form-content.php #28052', function(){$('#subBtn').attr('value','Send')});
					  break;
					  
					  case '28053': // Swim Spa Pricing
					  		$('#formContent').load('inc/form-content.php #28053', function(){$('#subBtn').attr('value','Send')});
					  break;
					  
					  case '28054': // Swim Spa Pricing
					  		$('#formContent').load('inc/form-content.php #28054', function(){$('#subBtn').attr('value','Send')});
					  break;
					  
					  case '28055': // Swim Spa Pricing
					  		$('#formContent').load('inc/form-content.php #28055', function(){$('#subBtn').attr('value','Send')});
					  break;
					  
					  case '28056': // Swim Spa Pricing
					  		$('#formContent').load('inc/form-content.php #28056', function(){$('#subBtn').attr('value','Send')});
					  break;					  					  
					  
					  case '28057': // Waterwell Pricing
					  		$('#formContent').load('inc/form-content.php #28057', function(){$('#subBtn').attr('value','Send')});
					  break;
					  					  
					  case '0': // Fastlane Pool Planning Guide
					  		$('#formContent').load('inc/form-content.php #OUTRO', function(){$('#subBtn').attr('value','Send')});
					  break;					  					  

		
					  default:
					   // nada yet
				  }    		
		
	}
