/*
$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
$.easing['jswing'] = jQuery.easing['swing'];

$.extend( jQuery.easing,
{
	def: 'easeOutBack',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeOutBack: function (x, t, b, c, d, s) {
		//if (s == undefined) s = 1.70158;
		if (s == undefined) s = 0.8;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	}
});

function findexternalAndActiveLinks() {
	var thisDomain = window.location.host,
	thisPath = window.location.pathname;
	
	$("a").each(function (i) {

		if($(this).attr("href") == null || $(this).attr("href") == undefined)
		{
			return false;
		}

		if (($(this).attr("href").match("http") == "http") && ($(this).attr("href").match(thisDomain) != thisDomain)) {
			$(this).click(function(){
				this.target = "_blank";
			});
		}
		if (($(this).attr("href") == thisPath) || ($(this).attr("href") == thisPath+"#") || ($(this).attr("href") == thisPath+"/")) {
			$(this).addClass("linkOn");
		}

	});
}

$(document).ready(function(){

	findexternalAndActiveLinks();
	
	$("#mainNav li").hoverIntent({
		sensitivity: 1, 
      	interval: 50, 
      	over: function() {
        	$(this).children("ul").animate({
				"height": "toggle",
				"opacity": "toggle"
			}, 300).siblings("a").addClass("subnavParentOpen");
			$(this).children("a").addClass("active");
		}, 
      	timeout: 300, 
      	out: function() {
			$(this).children("ul").animate({
				"height": "toggle",
				"opacity": "toggle"
			}, 100).siblings("a").removeClass("subnavParentOpen");
			$(this).children("a").removeClass("active");
		}
	});
 
 	$("#mainNav ul li ul").each(function() {
 		var menuMinWidth = $(this).parent().width();
 		$(this).css({'min-width': menuMinWidth});
 	});
    
  	if ($.browser.win()) {
  		$("#mainNav").addClass("windowsOS");
  		}
  		

	$("#location-tab").hoverIntent({
 		sensitivity: 1, 
      	interval: 50, 
      	over: function () {
      		$(this).stop(true, true).animate({
      			top:"30px"
      		}, 300, 'easeOutBack');
      	}, 
      	timeout: 300, 
      	out: function () {
   			$(this).stop(true, true).animate({
   				top:"-80px"
   			}, 300, 'easeOutBack');
      	}
	});
	
	$('#logo-container a').hide();

	var rotatingbanners = $('#banner-container').cycle({ 
    	before: function (currElement, nextElement, opts, isForward) {  
			var index = $(nextElement).index() +1; 
			$('#logo-container a:nth-child('+index+')').addClass("active-logo").stop(true,true).fadeIn(1000);
    		$('#logo-container a').not(':nth-child('+index+')').removeClass("active-logo").fadeOut(200);
  			
		},
    	timeout:	6000,
    	speed:		1000,
    	fx:			"fade"
	});


	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
	
	// If iOS then change instruction line to read "tap on each section"
	
    	$(".logo-instructions").html('Tap on a section to view facilities.');
    
    } else {
    
    // If NOT iOS then fire events on hover
    	
		$(".reveal-banner").hoverIntent({
			sensitivity: 2, 
  	  		interval: 100, 
  	  		over: function() {
  	  			var showbanner = $(this).attr("rel");
   		
      		  	$('.'+showbanner).fadeIn(1000);
     	   
       			var showlogo = showbanner.replace('banner', 'logo');
    	
    			$('#logo-container a:visible').stop(true,true).fadeOut(200, function() {});
    			$('#logo-container .'+showlogo).stop(true,true).fadeIn(1000);
  			
  				rotatingbanners.cycle('pause');
					
		}, 
    		timeout: 300, 
    		out: function() {
    			var showbanner = $(this).attr("rel");
		
				$('.'+showbanner).fadeOut(1000);
		
    			$('#logo-container a:visible').stop(true,true).fadeOut(200, function() {});
    			$('#logo-container a.active-logo').fadeIn(1000);

				rotatingbanners.cycle('resume');
			
			}
		});
		
	// End: If iOS
	}
	
	$("#splashInfo > li > a").toggle(
		function () {
      		$(this).addClass("active").siblings("ul").animate({
				"height": "toggle",
				"opacity": "toggle"
			}, 300).parent('li').addClass("subnavParentOpen");

			$('html,body').animate({scrollTop: $(this).offset().top}, 700);
			
      	}, 
		function () {
      		$(this).removeClass("active").siblings("ul").animate({
				"height": "toggle",
				"opacity": "toggle"
			}, 100).parent('li').removeClass("subnavParentOpen");
		
  	});
  	
  	
});
