$(document).ready( function(){
	
	/*
	----------------------------------------------------------
	01. GENERAL
	---------------------------------------------------------- */
	
	// EXTERNAL WINDOWS
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

		
	/*
	----------------------------------------------------------
	02. NAV
	---------------------------------------------------------- */
	
	// SUPERFISH NAV BAR INIT
	$(document).ready(function(){ 
	    $("ul.sf-menu").superfish({ 
	        pathClass:  'current',
			speed: 'normal',
			onBeforeShow: function(){ 
				if (jQuery.browser.msie) {
					$(this).parent(".dropdown").height(30).css("background-color","#D7D8DA").animate({ backgroundColor: "#ffffff"}, 'normal');
				}else {
					$(this).parent(".dropdown").height(30).css("background-color","#D7D8DA").animate({ backgroundColor: "#ffffff"}, 'normal').corners("7px top-left 7px top-right");
				}; 
			},
			onShow: function(){  },
			onHide: function(){ 
				if (jQuery.browser.msie) {
					$(this).parent(".dropdown").css("background-color","transparent");	
				} else {
					$(this).parent(".dropdown").css("background-color","transparent").corners("7px top-left 7px top-right");
				}
			}
	    }); 
	});
		

	// ROUNDED CORNERS
	$("#nav-main ul a.active").corners("7px"); // subnav active links
	
	if (!jQuery.browser.msie) {
		/*
		// Target just the 3rd level service menu's
		$("li#nav-services li.dropdown a").corners("7px top-left 7px top-right"); // subnav dropdown active links
		$("li#nav-services li.dropdown ul.services-list").corners("7px top-right 7px bottom-right 7px bottom-left"); // subnav dropdown menu
		$("li#nav-services li.dropdown ul.services-list a").corners("0px"); // remove rounding for subsequent dropdown links
		*/
		
		// Target all possible 3rd level menu's, not just services
		$("li.dropdown a").corners("7px top-left 7px top-right"); // subnav dropdown active links
		$("li.dropdown ul.services-list").corners("7px top-right 7px bottom-right 7px bottom-left"); // subnav dropdown menu
		$("li.dropdown ul.services-list a").corners("0px"); // remove rounding for subsequent dropdown links
		
		
	} else {
	
	}
	
	$("#nav-tools li a.current").corners("7px"); // top nav active links
	$("#contact #contact-info").corners("20px"); // contact info box
	$("#social div:not('#tab-facebook').tab-content").corners("20px"); // social media content	
	$("#social #tab-facebook.tab-content").corners("20px top-right 20px bottom-right 20px bottom-left"); 
		

	$('form input.rounded').corners("6px top-left 6px bottom-right"); // input buttons
	$('#social .rounded').corners("6px top-left 6px bottom-right"); // homepage newsletter button
	


	// LOGO FADE
	$(function() {
		// set opacity to nill on page load
		$("#logo span").css("opacity","0");
		// on mouse over
		$("#logo span").hover(function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1
			}, 'normal');
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0
			}, 'normal');
		});
	});
	
	
	/*
	----------------------------------------------------------
	03. FORMS
	---------------------------------------------------------- */
	
	// CLEAR VALUE ONFOCUS
	$('.labelvalue').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {
	            this.value = '';
	        }
	    });
	    $(this).blur(function() {
	        if(this.value == '') {
	            this.value = default_value;
	        }
	    });
	});
	
	
	// SELECT MENU STYLING INIT
	$('#content form select').sSelect();
	
	
	/*
	----------------------------------------------------------
	04. FONT REPLACEMENT
	---------------------------------------------------------- */
	Cufon.replace('h1')('h2')('.fun-facts h3')('dl.slider dt');
	
	
	
	/*
	----------------------------------------------------------
	05. FACILITIES
	---------------------------------------------------------- */
	$("#facilities #worldmap h2").hide();
	$("#facilities #worldmap h2#caption").show();
	
	//$('#worldmap').children('ul').children('li').each(function(){
	$('#worldmap li').each(function(){
	    var item = this.id;
	    item = item.slice(4,20);
		// alert(item);
	
	    $(this).hover(function() {
	        $('#worldmap h2#caption-'+item).show();
	        $('#worldmap h2#caption').hide();

	    }, function() {
	        $('#worldmap h2#caption-'+item).hide();
	        $('#worldmap h2#caption').show();
	    });
	})

	
	// usa regions
	$("#facilities dl.slider dt").click(function(){ //toggle 
		$(this).next("dd").slideToggle("normal");
		$(this).toggleClass("active");
		$(this).siblings("dt").removeClass("active");
		return false;
	});
	
	// display all regions
	$("#facilities dl.allregions dd").show(); 
	
	// make entire block clickable
	$("#facilities dl.slider dd ul li").click(function(){
    	window.location=$(this).find("a").attr("href");return false;
	});
	
	
	/*
	----------------------------------------------------------
	06. M4 INTRO HEADSHOT FADE
	---------------------------------------------------------- */
	$(function() {
		// set opacity to nill on page load
		$("ul#m4-intro span.rollover").css("opacity","0");
		// on mouse over
		$("ul#m4-intro span.rollover").hover(function () {
			// animate opacity to full
			$(this).stop().animate({
				opacity: 1
			}, 'normal');
		},
		// on mouse out
		function () {
			// animate opacity to nill
			$(this).stop().animate({
				opacity: 0
			}, 'normal');
		});
	});
	
	// show pain statements
	$("ul#m4-intro li span.rollover").hover(function() {
		$(this).next("em").css("z-index","999999").animate({opacity: "show"}, "normal");
	}, function() {
		$(this).next("em").animate({opacity: "hide"}, "normal");
	});
	
	
	/*
	----------------------------------------------------------
	07. LEAD GENERATION POP-UPS
	---------------------------------------------------------- */
	try {
		$(".colorbox-leadgen").colorbox({iframe:true, overlayClose:true, height:"680px", width: "700px", opacity: 0.30 });
	} catch(err) {
	}

	
	/*
	----------------------------------------------------------
	08. TABS
	---------------------------------------------------------- */
	$(".tab-content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab-content:first").show(); //Show first tab content


	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); // Remove any "active" class
		$(this).addClass("active"); // Add "active" class to selected tab
		$(".tab-content").hide(); // Hide all tab content

		var activeTab = $(this).find("a").attr("href"); // Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn("normal"); // Fade in the active ID content
		return false;

	});
	
	$("#tab-youtube li a span").hover(function() {
		$(this).prev("img").addClass("border");
	}, function() {
		$(this).prev("img").removeClass("border");
	});	

});

/*
----------------------------------------------------------
09. PREPEND & APPEND SPAN TAGS: ROUNDED IMG CORNERS
---------------------------------------------------------- */
$(document).ready(function(){
	$("div.rounded a").prepend("<span class='corner-top'></span>");
	$("div.rounded a").append("<span class='corner-bottom'></span>");
	$("#facilities #content-main div.rounded").append("<span class='corner-top'></span>");
	$("#facilities #content-main div.rounded").append("<span class='corner-bottom'></span>");
	$("#bio-photo.rounded").append("<span class='corner-top'></span>");
	$("#bio-photo.rounded").append("<span class='corner-bottom'></span>");
});



/*
----------------------------------------------------------
10. TOOLTIP
---------------------------------------------------------- */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});



