// JavaScript Document
jQuery(document).ready(function() { 

	//jQuery('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel

	/**
	 * Contact us maps
	 */
    //$('#large_map a').lightBox();

	jQuery( ".draggable" ).draggable({ 
		containment: 'parent'
	});

	jQuery(".close_button").click(function(event) {
		jQuery(".content_panel").hide('slideUp');
		jQuery(".open_button").fadeIn().show();
		event.preventDefault();
	});
	
	jQuery(".open_button").click(function(event) {
		jQuery(".open_button").hide();
		jQuery(".content_panel").show('slideDown');		
		event.preventDefault();
	});
	
	// Make the first li "on" when we load the page
	jQuery(".process_strip li").first().find('div').removeClass("dark_blue_purple_text");
	jQuery(".process_strip li").first().find('h3').addClass("on");
	jQuery(".process_strip li").first().find('div.step_image').addClass("on");
	
	jQuery(".process_strip li").mouseover(function() {
												   
		// Make sure the other li's are off
		jQuery(".process_strip li").each(function() {
			jQuery(this).find('div').addClass("dark_blue_purple_text");
			jQuery(this).find('h3').removeClass("on");
			jQuery(this).find('div.step_image').removeClass("on");									  
		});
												
		// Now highlight this item
		jQuery(this).find('div').removeClass("dark_blue_purple_text");	
		jQuery(this).find('h3').addClass("on");
		jQuery(this).find('div.step_image').addClass("on");
	});
	
	/*jQuery(".process_strip li").mouseout(function() {		
		jQuery(this).find('div').addClass("dark_blue_purple_text");
		jQuery(this).find('h3').removeClass("on");
		jQuery(this).find('div.step_image').removeClass("on");
	});*/
		
	jQuery(".content_panel_blog").find(".blog_article").last().css("border-bottom", "none");
	
	jQuery(".commentlist").find("li").last().css("border-bottom", "none");
	
	jQuery(".latest_blog_panel").find(".latest_blog_item").last().addClass("latest_blog_item_last");
		
	// Hide show other box on newsletter sign up form
	jQuery("#signup_type").change(function() {
		if (jQuery(this).find('option:selected').val() == "Other") {
			jQuery("#signup_type_other_text_box").show();
		} else {
			jQuery("#signup_type_other_text_box input").val('');
			jQuery("#signup_type_other_text_box").hide();
		}
	});
		
		
	/*********************
	 * NAVIGATION
	 ********************/

	// Main navigation
	jQuery("div#main_navigation li").each( function() {
											   
		var link = jQuery(this).find('a');
				
		// If this is the home page
		if (location.pathname == '/' && link.attr('href') == '/') {
			jQuery("div#main_navigation li").removeClass("on");
			jQuery(this).addClass("on");
			jQuery(this).addClass("current-item");
			
		// Check to see if this is a top level nav item
		} else if ((location.pathname.indexOf(link.attr('href')) > -1) && link.attr('href') != '/') {
			
			jQuery("div#main_navigation li").removeClass("on");
			
			// Handle the selected subnav pages
			if (jQuery(this).parent().attr('class') == 'dropdowns') {
				jQuery(this).parent().parent().parent().addClass("on");
				jQuery(this).parent().parent().parent().addClass("current-item");
			} else {
				jQuery(this).addClass("on");
				jQuery(this).addClass("current-item");
			}
			
		}
		
	});

	//top navigation dowpdowns - on state
	jQuery(".dropdown-holder").mouseenter(function() {
		jQuery(this).parent().addClass("on");		
	});	
	jQuery(".dropdown-holder").mouseleave(function() {
		jQuery(this).parent().removeClass("on");
	});
	
	// Site overlay
	/*jQuery("#header-nav").mouseenter(function() {
		showSiteOverlay(true);		
	});*/
	jQuery("#header-nav li.d").mouseleave(function() {
		//hideSiteOverlay(true);		
	});
	
	// Navigation links with subnav
	jQuery("ul#header-nav li a.dd").hover(function() { 	
		//Following events are applied to the subnav itself (moving subnav up and down)  
		//jQuery(this).parent().find("div.dropdown-holder").fadeIn(1000); 
		if(jQuery.browser.msie) {
			jQuery(this).parent().find("div.dropdown-holder").show(); 
		} else {
			jQuery(this).parent().find("div.dropdown-holder").slideDown(700).show(); 
		}
		
		//Drop down the subnav on hover  
		jQuery(this).parent().hover(function() {		
		}, function(){  
			if(jQuery.browser.msie) {
				jQuery(this).parent().find("div.dropdown-holder").hide(); 
			} else {
				jQuery(this).parent().find("div.dropdown-holder").slideUp(200);
			}				
			//jQuery(this).parent().find("div.dropdown-holder").fadeOut(200);
			//jQuery("#content_overlay").removeClass("alpha75");
			//When the mouse hovers out of the subnav, move it back up  
		});  
	//Following events are applied to the trigger (Hover events for the trigger)  
	}).hover(function() {  
		//On Hover Over  
		
		// Nav item rollover
		jQuery(this).parent().addClass("on");
		
		//showSiteOverlay(true);
		
	}, function(){  
		//On Hover Out
		
		// Nav item rollover
		jQuery(this).parent().removeClass("on");
				
	});
	
	//secondary navigation dowpdowns
	jQuery("ul#header-nav li a.ddd").hover(function() { //When trigger is clicked...  
	
		//Following events are applied to the subnav itself (moving subnav up and down)  
		 
		//Drop down the subnav on hover  
		jQuery(this).parent().hover(function() {  
		}, function(){  
			
			//When the mouse hovers out of the subnav, move it back up  
		});  
	//Following events are applied to the trigger (Hover events for the trigger)  
	}).hover(function() {  
		//On Hover Over  
		
		jQuery(this).parent().find("div.dropdown_nav_image").show();
		
	}, function(){  
		//On Hover Out
		
		jQuery(this).parent().find("div.dropdown_nav_image").hide();
		
	});

});

function showSiteOverlay(fade) {
	// Whole site overlay
	if (!fade) {
		jQuery("#content_overlay").hide().addClass("alpha85").fadeIn(1500);	
	} else {
		jQuery("#content_overlay").addClass("alpha85");	
	}
	
	// Remove existing opacity from header and footer to avoid double opacity
	//jQuery("#header").removeClass("alpha85");	
	//jQuery("#footer").removeClass("alpha85");
	
	// Add opacity to the content panel
	jQuery(".content_panel").css("opacity", 0.1 ); // Does this work in IE???
	jQuery("#control_navigation").css("opacity", 0.1 ); // Does this work in IE???
}

function hideSiteOverlay(fade) {
	// Whole site overlay
	if (!fade) {
		jQuery("#content_overlay").fadeOut(500).removeClass("alpha85").hide();
	} else {
		jQuery("#content_overlay").removeClass("alpha85");
	}
	
	// Add opacity bact to the header and footer
	//jQuery("#header").addClass("alpha85");	
	//jQuery("#footer").addClass("alpha85");
	
	// remove opacity from the content panel
	jQuery(".content_panel").css("opacity", 1); // Does this work in IE???	
	jQuery("#control_navigation").css("opacity", 1); // Does this work in IE???	
}

function goToAnchor(anchor_name) {	
	jQuery('html,body').animate({scrollTop: jQuery("#"+anchor_name).offset().top},0);
}
