$(document).ready(function(){
	$(".rounds").hoverIntent({sensitivity: 3, interval: 100,  over: showFlyout, timeout: 600, out: hideFlyout});
	
	function showFlyout(){  
		var id = $(this).attr('id'); 
		$("#"+id+"-info").show("slow"); 	
	}
	
	function hideFlyout(){
		var id = $(this).attr('id');
		$("#"+id+"-info").hide("slow");
	}
});  


sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



//Begin Stage Functions Review before launch for removal of non-used code. //
	var preOnLoadFunctions = new Array();
	function addPreload(newFunction){
		preOnLoadFunctions[preOnLoadFunctions.length] = newFunction;	
	}
     function showPlayer(videoID,GetAutoPlay, story) {
      	document.getElementById('videoPlayer').innerHTML = getVideoViewer(videoID, {width: 530, height: 300, config: {autoplay: true}});        
      }
      function showText(story) { 
      	hideAndActivateText(lastTextActivated, story);
      	lastTextActivated = story;
      }

lastStoryUsed = 0;
	function activateStory(targetStory, imageId)
	{
			document.getElementById('twistageContentBox').style.backgroundImage='none';	
			try{overLayController(false);}catch(e){} 
		try{
			var slidI = document.getElementById('slideImage');
			if(document.getElementById('storyText' + lastStoryUsed)) {
				document.getElementById('storyText' + lastStoryUsed).style.display = 'none';	
			}						

			if(document.getElementById('storyText' + targetStory)) {	
				document.getElementById('storyText' + targetStory).style.display = 'inline';
				document.getElementById('storyText' + targetStory).style.height = '300px';
			}
			document.getElementById('videoPlayer').innerHTML = "";
			hideAndActivateText(lastStoryUsed, targetStory);	
			lastStoryUsed = targetStory;	

		}catch(e){
		}
	}

	lastAdVid = '';
	function overLayController(mode, vid){
	return false;
	}
		
	function showYoutube(utubeId, story, autoplay){

		//shows appropriate text
		//activateStory(story);
		//hides the image slider
		activateStory(story, 0);
		if(utubeId == 'http://www.youtube.com/p/13EAF3F162CF8A2E'){
			if(!document.all)
				//document.getElementById('HPFCenterImage').style.top = '250px';
			launchPlayer();
			return;
		}		
		try{
		//document.getElementById('HPFCenterImage').style.top = (250) + 'px';
		}catch(e){}
		//write the video player 
		if(utubeId.indexOf('http') == -1)
			embedSource = "http://www.youtube.com/v/" + utubeId + "&autoplay=" + autoplay;
		else
			embedSource = utubeId + "&amp;autoplay=" + 1;

		var ytFlash = new SWFObject(embedSource, "myytplayer", "530", "300", "8.0");
	//	var yourDevKey = 'AI39si5ZYda4KHUD8hIxgJZVKx-t5SP0QHnN_GysjQno86PT67hpyRIHFUMflLHz_AnwkB2PUspNy7_lZyBr44Rf9a4Q7rmHrA';
	//	var ytFlash = new SWFObject("http://gdata.youtube.com/apiplayer?key="+yourDevKey+"&enablejsapi=1&playerapiid=ytapiplayer", "ytapiplayer", "442", "320", "8.0");		
		ytFlash.addParam("wmode", "transparent");
	//	ytFlash.addParam('allowScriptAccess', "always");		
		ytFlash.write("videoPlayer");
//		

		
	}
 	function onYouTubePlayerReady(playerId)
	{
  		ytplayer = document.getElementById("ytapiplayer");
  		ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
		ytplayer.loadVideoById("IeZV3EoWegA", 0);
	}
	
	function onytplayerStateChange(newState) {

	}
	function showYoutubeSubstory(utubeId, story, autoplay)
	{

		//write the video player 
		activateStory(10,4511);
		//document.getElementById('HPFCenterImage').style.top = (250) + 'px';		
		hideAndActivateText(lastTextActivated, story);		
		lastTextActivated = story;
		if(utubeId.toUpperCase().indexOf('HTTP') == -1)
			var ytFlash = new SWFObject("http://www.youtube.com/v/" + utubeId + "&autoplay=" + autoplay, "youtubeFlash", "442", "320", "8.0");
		else
			var ytFlash = new SWFObject(utubeId + "&autoplay=" + autoplay, "youtubeFlash", "530", "300", "8.0");
		ytFlash.addParam("wmode", "transparent");
		ytFlash.write("videoPlayer");
		if(document.getElementById('slideText' + story))		//sanity check
			document.getElementById('slideText' + story).style.display = 'block';		
	}
	
	 
	lastTextActivated = 1;
	function hideAndActivateText(lastStory, newStory)
	{
		if(!lastStory)
			lastStory =0 ;
		if(lastStory != "" && newStory != lastStory)
		{
			//alert("Were in!!! slideText"+newStory);
			if (document.getElementById('slideText' + lastStory)) {
				document.getElementById('slideText' + lastStory).style.display = 'none';
			}
		
			if (document.getElementById('slideText' + newStory)) { //sanity check
				document.getElementById('slideText' + newStory).style.display = 'block';
			}
		}
	}
	function swapDivText(id, text)
	{
	 eval("divToSwap = document.getElementById('"+ id + "');");
	 if(divToSwap && divToSwap.innerHMTL != text && text.indexOf("A Problem Has Occurred") == -1)
	 {
		divToSwap.style.visibility = "visible";
	 	divToSwap.innerHTML = text;
	 }
	 else
	 {
		if( text.indexOf("A Problem Has Occurred") != -1)
			error = "A content error occured.";
		else if (!divToSwap )
			error = "No container could be located: " + id ;
		else if (divToSwap.innerHMTL == text)
			error = "Same content already on page.";
		else
			error = "Unknown error";
	
		displayNotice("Content Error", "Unable to display some, or all, of the page content. We apologize for this.<br>" + error, "pageErrorNotice", 400);
	   //alert("Unable to display some, or all, of the page content. We apologize for this");
	 }
	}
	
	function onBufferFull(clip){// - Called when a video has completely buffered. 
		player.onBufferFull(clip);
	}
	
	function onResume(clip){// - Called when the video resumes playback after being stopped or paused. 
		player.onResume(clip);
	}
	
	function onPlay(clip){// - Called when the play button is clicked. 
		player.onPlay(clip);
	}
	
	function onPause(clip){// - Called when the pause button is clicked. 
		player.onPause(clip);
	}
	
	function onStop(clip){// - Called when the stop button is clicked. 
		player.onStop(clip);
	}
	
	function onClipDone(clip){// - Called when a video completes playback. 
		player.onClipDone(clip);
	}
	function navUpdater(){
		return void(9);
	} 
		var logCount = 0;
	function logText(text){
		document.getElementById('logger').innerHTML = logCount++ + ':' + text + '<br>' + document.getElementById('logger').innerHTML;	
	}
	function newTest(){  
		//this plays a youtube story 			
		showYoutube('http://www.youtube.com/p/13EAF3F162CF8A2E',1,1);
		//showPlayer('6818135e97274', true, 1);
		}
	function addLoadEvent(_function) {
	var _onload = window.onload;
	if ( typeof window.onload != 'function' ) {
	if ( window.onload ) {
	window.onload = _function;
	} else {
	var _addEventListener = window.addEventListener || document.addEventListener;
	var _attachEvent = window.attachEvent || document.attachEvent;
	if ( _addEventListener ) {
	_addEventListener('load', _function, true);
	return true;
	} else if ( _attachEvent ) {
	var _result = _attachEvent('onload', _function);
	return _result;
	} else {
	//todo: preloading fix for ie5.2 on mac os
	return false;
	}
	}
	} else {
			window.onload = function() {
			_onload();
			_function();
		}
	}
	}