var left_img = "";
var total_entries = 0;
var total_pages = 0;

$(function(){
	
	/* Navigation */
	
	if (nav_section == "disclaimer") {
		$("#disclaimer a").css("color", "#FF6633");
	}
	
	if (nav_section == "newsletter") {
		nav_section = "newsletters";
	}
	if (nav_section == "article") {
		nav_section = "published";
	}
	if (nav_section == "event") {
		nav_section = "events";
	}
	if (nav_section == "press") {
		nav_section = "in-the-news";
	}
	if (nav_section == "case") {
		nav_section = "results";
	}
	if (nav_section == "case-test") {
		nav_section = "results-test";
	}
	
	
	if (nav_subsection == "resolved") {
		nav_section = "resolved";
	}
	
	if (nav_subsection == "pending") {
		nav_section = "pending";
	}
	
	
	/*$("#nav li[id!=nav-" + nav_section + "]").mouseover(function(event){
		$(this).children("ul").show();
	}).mouseout(function(){
		$(this).children("ul:not(.selected-nav-menu)").hide();
	});*/
	
	$("#nav-" + nav_section).addClass("selected-nav");
	$("#nav-" + nav_section).parent().addClass("selected-nav-menu");
	var parent_nav = $("#nav-" + nav_section).parent();
	parent_nav.parent().addClass("selected-nav-menu-item");
	//$("#nav-" + nav_section + " ul").show();
	$("#nav-" + nav_section + " ul").css("display", "block");
	
	if (nav_subsection != "") {
		$("#subnav-" + nav_subsection).addClass("selected-nav");
	} else {
		$(".left-list li:first").addClass("selected-nav");
	}
	
	/* Background image for left side */
	
	if (left_img != "") {
		$("#left-column").css("background-image", "url('" + left_img + "')");
	}
	
	/* Landing Pages */
	
	var landing_images = 0;
	var current_image = 0;
	landing_images = $(".landing-image").length;
	var image_array = $(".landing-image").get();
	image_array.sort(randomize);
	function randomize() {
		return 0.5 - Math.random();
	}
	$("#landing-page").empty().append(image_array);
	
	if (landing_images > 1) {
		$(".landing-image:gt(0)").fadeTo(0, 0);
		$(document).everyTime(10000, function(i) {
			current_image++;
			if (current_image >= landing_images) {
				current_image = 0;
				$(".landing-image:eq(" + (landing_images - 1) + ")").fadeTo(1000, 0);
				for (var i = 1; i < landing_images - 1; i++) {
					$(".landing-image:eq(" + i + ")").fadeTo(0, 0);
				}
			} else {
				$(".landing-image:eq(" + current_image + ")").fadeTo(1000, 1);
			}
		});
	}
	
	$("<div>").attr("id", "popup-cover").attr("title", "Click to close").hide().appendTo("body").click(function(event){
		event.preventDefault();
		hideContact();
	});
	
	if ($.browser.msie && $.browser.version == "6.0") {
		$("#popup-cover").height($("body").outerHeight());
	}
	
	$("<div>").attr("id", "popup-close").attr("title", "Close").text("x").hide().appendTo("body").click(function(event){
		event.preventDefault();
		hideContact();
	});
	
	$("<iframe>").attr("id", "contact-popup").attr("frameBorder", 0).attr("scrolling", "no").hide().appendTo("body");
	$("#contact-popup").attr("src", "/contact-popup/");
	
	function showContact() {
		$("#contact-popup").show();
		$("#popup-close").show();
		$("#popup-cover").show();
	}
	
	function hideContact() {
		$("#contact-popup").hide();
		$("#popup-close").hide();
		$("#popup-cover").hide();
	}
	
	$("#contact-popup-button").click(function(event){
		event.preventDefault();
		showContact();
	});
	
});
