$(document).ready(function() {

	$('body a.lightBox').lightBox();
	 	
	$("a.smoothScroll").anchorAnimate();

	// fix for target='_blank'
	/*
	$('a[href^="http://"], a[href^="https://"], a[rel^="external"]').attr({
		target: "_blank", 
		title: "Opens in a new window"
	});		
	*/
	
	//call the jQuery Hover Over and Out
    $('.mainNav').find("li").hover(over, out);
  
    function over(event) {
		if(!$(this).find("ul.subNav").is(":animated") ) $(this).find("ul.subNav").slideDown("fast");
    }
    function out(event) { 
		$(this).find("ul.subNav").slideUp("fast");
	}
    
    //clear search box text on click
    $(".text").click(function(){
    	$(this).val("");
    });
	
	//run fader
	$(".fader").edFade();




	// Automatically inject "collapse" link if <div class="slider"> is detected
	$(".slider .sliderContent").append('<a href="#" class="collapse">[collapse]</a><br class="clearBoth"/>');

	
	// If link OR collapse is Clicked - then hide/reveal the content <div>
	$(".link").click(function(e){	
		e.preventDefault();
		
		var content = $(this).closest(".slider").find(".sliderContent:eq(0)");
	
		if (content.is(":visible")) {
			content.slideUp("slow");
		} else {
			content.slideDown("slow");
		}
			
	});
	
	
	$(".collapse").click(function(e){	
		e.preventDefault();
		
		var content = $(this).parent(".sliderContent:eq(0)");
		
		if (content.is(":visible")) {
			content.slideUp("slow");
		} else {
			content.slideDown("slow");
		}
			
	});
	
});



//smooth scroll 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")
			$(".faq").find("div").removeClass("selected");
			$("div").find(elementClick).addClass("selected");
			
			var destination = $(elementClick).offset().top;
		
			
			if (elementClick == "#top") {
				$(".faq").find("div").removeClass("selected");
			}
			
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}
