var slideropen = 0;
var currentLink = null;
var currentSlide = null;
var topmenuopen = 0;
var submenuopen = 0;
var opensubmenuid = "";
var topmenu = "";
var descopen = 0;
var currentDescLinkId = null;
var currentDescId = null;

	
$(function() {
	// This, or...
	$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	$('#starter-gallery a').lightBox();
	$('#starterplus-gallery a').lightBox();
	$('#foundation-gallery a').lightBox();
	$('#premium-gallery a').lightBox();
	$('#executive-gallery a').lightBox();
	$('#presidential-gallery a').lightBox();
	$('#leadership-gallery a').lightBox();
	// This controles fancyzoom for price chart on search-home
	$('#price-chart a').fancyZoom();
	$('#local-z a').fancyZoom();
	$('#ppc-z a').fancyZoom();
	$('#seo-z a').fancyZoom();
	$('#gmo-z a').fancyZoom();
	$('#wom-z a').fancyZoom();
	$('#orr-z a').fancyZoom();
	});






function slideContent(slideId, linkId){
	
		 if (topmenuopen == 1){
			 forceCloseTopNavMenu(topmenu, "");

		 }
		 
		 
					
		
		if (descopen > 0){
			// first close any other open panels
			$(currentDescId).fadeOut("slow");
			descopen = 0;
		}	
		
		if (currentLink != ""){
			$(currentLink).css({backgroundPosition:"top left"});
		}
		
		$(linkId).css({backgroundPosition:"bottom right"});
		if (!$(linkId).hasClass('active')) {
			
			if (currentLink != ""){
            	$(currentLink).removeClass("active");
			}
           
			currentLink = linkId;
			
			if (slideropen > 0){
				// first close any other open panels
				$(currentSlide).fadeOut("slow");
				// then open the selected panel
			}
			
			slideropen = 1;
			currentSlide = slideId;
			
            $(slideId).fadeIn("slow");

            $(linkId).toggleClass("active");
			
			$("div#top-form").animate({height: "20px"})
			$(".formError").fadeOut("fast");

		//return false;
    } else {
        return false;
   }
   


}


function showDescription(descId, desclinkId){
	
		if (currentDescLinkId != ""){
			$(currentDescLinkId).css({backgroundPosition:"top left"});
		}
		
		$(desclinkId).css({backgroundPosition:"bottom right"});
		

		if (!$(desclinkId).hasClass('active')) {
			
			if (currentDescLinkId != ""){
            	$(currentDescLinkId).removeClass("active");
			}
           
			currentDescLinkId = desclinkId;
			
			if (descopen > 0){
				// first close any other open panels
				$(currentDescId).fadeOut("slow");
				// then open the selected panel
			}
			
			descopen = 1;
			currentDescId = descId;
			
            $(descId).fadeIn("slow");

            $(desclinkId).toggleClass("active");
			
			$("div#top-form").animate({height: "20px"})
			$(".formError").fadeOut("fast");

			
            return false;
        } else {
            return false;
        }

}



var clearedInputs = new Array();

function clearInput(input){
	
	if (null == clearedInputs[input.name]){
		input.value = '';
		clearedInputs[input.name] = '1';
	}

}

function fadeContent(slideId, linkId){
            $(slideId).fadeOut("slow");
			$(linkId).removeClass("active");
}

function openTopNavMenu(menuId, linkId){
		topmenu = menuId;
		
		if (slideropen > 0){
			
			
				// first close any other open panels
				$(currentSlide).fadeOut("slow");
				// then open the selected panel
				currentSlide = "";
				slideropen = 0;
				
			}
	
		if (currentLink != ""){
			$(currentLink).css({backgroundPosition:"top left"});
			$(currentLink).toggleClass("active");
			currentLink = "";
			
		}

		//if menu is already open, close any open submenu and do nothing
		//NOTE: makse sure to set topmenuopen = 0 and submenuopen = 0 on top menu close
	   if (topmenuopen == 1){
		   	
		    if (submenuopen == 1){
				submenuopen = 0;
				$(opensubmenuid).fadeOut("slow");
			
				
			
			}
			
			return;
	   }
	
		topmenuopen = 1;
		
		//If any open sub menues close them
		if (submenuopen == 1){
				submenuopen = 0;
				$(opensubmenuid).fadeOut("slow");
				
				opensubmenuid = "";
		}
		
		$(menuId).fadeIn("slow");

}



function openSubNavMenu(menuId, linkId) {
		
	   if (menuId == opensubmenuid) return;
	   if (submenuopen == 1){
			$(opensubmenuid).fadeOut("slow");
	   }
	   
		submenuopen = 1;
		opensubmenuid = menuId;
		$("#sub-menus").css('left', 'auto');
		$(menuId).fadeIn("slow");
		$("div#top-form").fadeOut("slow");
		
	
		
} 



function forceCloseTopNavMenu(menuId, linkId){
	
		
			
		if (submenuopen == 1){
			submenuopen = 0;
			$(opensubmenuid).fadeOut("fast");
			opensubmenuid = "";
		
		}
		$("#sub-menus").css('left', -1200);
		$(menuId).fadeOut("fast");
		$(currentLink).css({backgroundPosition:"top left"});
		$(currentLink).toggleClass("active");
		$("div#top-form").fadeIn("slow");
		
	 
	
		topmenuopen = 0;
}

function closeTopNavMenuLeft(event, menuId, linkId){
	try{

	  var xposition = event.offsetX;
  	  var yposition = event.offsetY;
	  
	  if (xposition > 225){
		  return;	   
	  }
	}
	catch(e){
			alert(e);
	}
	 
		
		//if menu is already open, close any open submenu and do nothing
		//NOTE: makse sure to set topmenuopen = 0 and submenuopen = 0 on top menu close
	   if (topmenuopen == 1){
		   	//Check if cursor over menu
			
		    if (submenuopen == 1){
				submenuopen = 0;
				$(opensubmenuid).fadeOut("fast");
				opensubmenuid = "";
			}
			
			$(menuId).fadeOut("fast");
	   }
	
		topmenuopen = 0;
}

function closeTopNavMenuRight(event, menuId, linkId){
	try{

	  var xposition = event.offsetX;
  	  var yposition = event.offsetY;
	  	 
	  if (xposition > 300 && submenuopen == 1){

		  return;
	  }
	  else{
		  	if (xposition < 20) {

				return;
			}
	  }
	}
	catch(e){
			alert(e);
	}
	 
		
		//if menu is already open, close any open submenu and do nothing
		//NOTE: makse sure to set topmenuopen = 0 and submenuopen = 0 on top menu close
	   if (topmenuopen == 1){
		   	//Check if cursor over menu
			
		    if (submenuopen == 1){
				submenuopen = 0;
				$(opensubmenuid).fadeOut("slow");
				opensubmenuid = "";
			}
			
			$(menuId).fadeOut("slow");
	   }
	
		topmenuopen = 0;
}

function closeSubNavMenu(menuId, linkId){
	
	try{

	  var xposition = event.offsetX;
  	  var yposition = event.offsetY;
	  if (xposition < 547) return;	   
	}
	catch(e){
			alert(e);
	}
	
	   if (submenuopen == 1){
		   	$(menuId).fadeOut("slow");
			
	   }
	   
	   submenuopen = 0;
	   opensubmenuid = "";
}



