//dropdown menu variables
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function menu_open()
{  menu_canceltimer();
   menu_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function menu_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function menu_timer()
{  closetimer = window.setTimeout(menu_close, timeout);}

function menu_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

//anchorAnimate function. 
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

$(document).ready(function(){
	//#billing div cycle found in left_navigation_products.html
	if ($("#billing")[0]){
		$.getScript("/js/jquery.cycle.2.88.js", function(){
				//if #billing exists then call cycle
		$('#billing').cycle({
			fx: 'fade',
			delay:  -4000 
		});
		
		});	
	}
	//if .tooltip exists then  ...
	if ($(".tooltip")[0]){
		$(".tooltip p").hover(
		  function () {
		    $(this).css('cursor', 'help').next().stop().fadeIn();
		  },
		  function () {
		    $(this).next().stop().fadeOut();
		});
	}
	//dropdown menu jquery
	$('#menu > li').bind('mouseover', menu_open);
	$('#menu > li').bind('mouseout',  menu_timer);
	//equalheight :: script reference has been removed from header. this is here for now in case it has to be reverted at some point
	//$(".row-1-height").equalHeights();
	//$(".row-2-height").equalHeights();

	$('.modal').click(function(){
		$('.popup').fadeIn(500);
	//	$('.overlay').fadeIn(500);
	});
	$('.close').click(function(event){
		$('.popup').fadeOut(500);
	//	$('.overlay').fadeOut(500);
		event.preventDefault();
	});
	
	$("a.anchorLink").anchorAnimate()
	
//close jquery	
});

document.onclick = menu_close;

//code for faq auto expand :: not sure if this is needed, see header_inside.php
function doFaq(q) {
	// set value on the drop-down
	document.forms[1].menu.value = q;
	showInfo();
}

//validation script for zip lookup
var errors=0;
function validcheck() {
    if( $("#validCheck").val().length <= 4 || $("#validCheck").val().length >= 8){
		if( errors==0){
			$("#form-error-container").html("<div class='formError'>We're sorry, but you've entered an invalid Zip Code</div>"); errors=1;} return false;
		}
    	return true;
	}

