/* HOME PAGE FUNCTIONS
-----------------------------------------------------*/
var videoTracker;

function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
};

function playFlash(mov, tracker) {
	$('<div id="flashMovie"><div id="fMovie"></div></div>').appendTo('#site').css({ position:'absolute', top:0, left:0, zIndex:1000 });
	swfobject.embedSWF("/flash/"+mov, "fMovie", "980", "540", "9.0.0","/flash/expressInstall.swf", {}, { menu:"false", wmode:"transparent", allowAccess:"always" }, {});
	if(tracker) urchinTracker(tracker);
	try {
		getFlashMovie('home').stopMovie(); 
	} catch(err) { };
	setTimeout(function() { getFlashMovie('home').stopMovie(); }, 2000);
};

function playVideo(vid, tracker) {
	if(vid) {
		$('<div><div id="flashVideo"></div></div>').appendTo('#site').css({ position:'absolute', top:0, left:0, zIndex:1000 });
		swfobject.embedSWF("/flash/home-video-player-v2.swf?v=1.1.2", "flashVideo", "980", "570", "9.0.0","/flash/expressInstall.swf", { video:vid  }, { menu:"false", wmode:"transparent", allowAccess:"always" }, {});
		
		stopHome();
		
		$("#foot").fadeOut();
		if(tracker) {
			videoTracker = tracker;
			urchinTracker(tracker);
		} else {
			videoTracker = '';
		};
	}; 
};

function closeVideo() {
	$("#foot").fadeIn();
	
	$('#flashVideo').remove();
	SWFAddress.setValue('/home/');
	getFlashMovie('home').startMovie();
};

function closeMovie() {
	$('#flashMovie').remove();
	getFlashMovie('home').startMovie();
	SWFAddress.setValue('/home/');
};

function unloadMovie() {
	getFlashMovie('home').startMovie();
	document.getElementById('flash_overlay').style.visibility = 'hidden';
};

function stopHome() {
	try{ 
		getFlashMovie('home').stopMovie();
	} catch(err) {
		setTimeout(stopHome, 1000);
	};
};

/* TURKEY GAME*/
function startGame() {
	SWFAddress.setValue('/thanksgiving/');
}

function startGameTrans() {
	$(window).blur();
	$('<div id="turkeyGame"><div id="game"></div></div>').appendTo('#site').css({ position:'absolute', top:-1, left:-1 });
	swfobject.embedSWF("/flash/TurkeyGamePreloader.swf?v=2.1.1", "game", "980", "540", "9.0.0","/flash/expressInstall.swf", {}, { menu:"false", wmode:"transparent", allowAccess:"always" }, {});
	urchinTracker('/thanksgiving-2010/');
	stopHome();
};

function updateTracking(minutes) { urchinTracker('/thanksgiving-2010/minutes/'+minutes+'/'); };
function gameComplete(total) { urchinTracker('/thanksgiving-2010/complete/'+total+'/'); };

function closeGame() {
	$('#turkeyGame').remove();
	getFlashMovie('home').startMovie();
	SWFAddress.setValue('/home/');
};
/* END TURKEY GAME */

/* MARCH MADNESS */
function saveBracketData(data) {
	$.get('/ajax-data.php', { action:'saveData', data:data }, function(res) {
		getFlashMovie('fMovie').dataSaved();																 
	});
};
/* END MARCH MADNESS */


$(document).ready(function() {						   	
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, function(e) {
		var c = e.target.getPathNames();
		if(c == 'thanksgiving') startGameTrans();
		//if(c == 'march-madness') playFlash('march-madness-results.swf', '/march-madness-2011-results');
		//if(c == 'march-madness') playFlash('march-madness.swf', '/march-madness-2011');
		//if(c == 'admin') playFlash('march-madness-admin.swf');
		if(c == "home" || c == "") {
			$('#turkeyGame').remove();
			try { getFlashMovie('home').startMovie(); } catch(err) {  };
		};
	});
	$(document).keypress(function(e) {
		if(e.keyCode>=38 && e.keyCode<=40) return false;							
	});
	
	//make several slideshows with class selector, all slideshows shares the same parameters
	$('.slideshow').divSlideShow(); 	
	
	//make one slideshow with id selector
	$('#dss,#promotions').divSlideShow({
		height:490, 
		width:540, 
		arrow:"split",
		loop:3,
		slideContainerClass:"slide-container",
		separatorClass:"separator", 
		controlClass:"control",  
		leftArrowClass:"control", 
		rightArrowClass:"control", 
		controlActiveClass:"control-active",
		controlHoverClass:"control-hover",
		controlContainerClass:"control-container"
		
	});
	
});
