/*-- main js--*/

//delay function
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
/*-- main js--*/

this.randomtip = function(){

	var pause = 8000; // define the pause for each tip (in milliseconds) 
	var length = $("#quotes li").length; 
	var temp = -1;		

	this.getRan = function(){
		// get the random number
		var ran = Math.floor(Math.random()*length) + 1;
		return ran;
	};
	this.show = function(){
		var ran = getRan();
		// to avoid repeating
		while (ran == temp){
			ran = getRan();
		}; 
		temp = ran;
		$("#quotes li").hide();	
		$("#quotes li:nth-child(" + ran + ")").fadeIn("medium");		
	};
	
	show(); setInterval(show,pause);
	
};

loadMovie = function(){
	
	$("#videoPlayer").append("<div id='flashPlayer'></div>");

	var flashvars = {
		file: "http://temp.playshaper.org.uk/video/playshaper.flv",
		image: "swf/preview.jpg"
		};

	var attributes = {
		id: "myDynamicContent",
		name: "myDynamicContent",
		wmode: "transparent"
		};

	swfobject.embedSWF("http://temp.playshaper.org.uk/video/playshaper.swf", "flashPlayer", "423", "276", "9.0.0","http://temp.playshaper.org.uk/swf/expressInstall.swf", flashvars, attributes);
	
}


$(document).ready(function(){
	
		
	//main nav sub nav triggers
	$('ul#mainNav li').hover(function () {
		
		var subPosition = $(this).position();
		
			$(this).children('ul').css({'left' : subPosition.left }).show();
			
			if ($(this).hasClass("last")){
			
				$(this).children('ul').css({'left' : subPosition.left - 126 }).show();
			}
			
		},
		// on mouse out
		function () {
			$(this).children('ul').hide();
		});
	
		//vertical tabs using delay function on hover
		$("div.tabbedContent").hide();

		//using the hoverIntent delay function
		var config = {    
		     sensitivity: 3, // number = sensitivity threshold  
		     interval: 63, // number = milliseconds for onMouseOver polling interval    
		     over: changeTabs, // mouseover function    
		     timeout: 250, // number = milliseconds delay before onMouseOut    
		     out: donothing // mouseout function   
			 };
			
		function donothing() { } 
		
		function changeTabs() {
			
			if ($(this).hasClass("first") && $(this,"[id!=active]")) {
				
				loadMovie()
				
				$(this).attr({id:"active"});
				
				$(".blank").remove();
				
				} else {
			
					$("#flashPlayer").replaceWith("<div class='blank'></div>");	
				}
			
			
			
			$("#vtcNav li a").removeAttr("id");
			
			$(this).attr({id:"active"});

					

			var name = $(this).attr("rel");	
			$("#vctInner div.tabbedContent").each(function (i) {			

				var thisId = $(this).attr("id");			
				//if the name of the preview map title matches the title of the promo div		
				if (name == thisId) {								
					$(".tabbedContent").hide().removeClass("tcActive");
					//$(this).addClass("tcActive");
					$(this).fadeIn("fast").addClass("tcActive");																	
				}					
				
			});	
			
			
					
		}

		$('#vtcNav li a').hoverIntent(config);
		
	
		
		
		
		$("#search").click(function () {
			if ($(this).val() == 'Search') { $(this).val(''); }
		});
		
	
});

