/*
 * Tilex Home Page Javascript
 *
 * July 2011
 *
 */

$(document).ready( function() {
	//Look for takeover in the querystring to subvert the cookie
	var qs = (function(a) {
		if (a == "") return {};
		var b = {};
		for (var i = 0; i < a.length; ++i)
		{
		    var p=a[i].split('=');
		    if (p.length != 2) continue;
		    b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
		}
		return b;
	})(window.location.search.substr(1).split('&'));

	// If haven't already been to the home page today, show the flash movie
	// Add showintro=yes to the URL to force the movie to show
	if(
		!$.cookie('haveSeenTilexFlash').length ||
		qs['showintro'].length
	) 
	{
		//Hide the promos
		$("#promos").fadeOut(500);	
		//Show the takeover div
		$("#flashHomeHero").show();	
		var flashvars = {},
			params = {wmode:"transparent"},
			attributes = {};
		swfobject.embedSWF(
			"/swf/tilex_home_v8.swf", 
			"flashObject", 
			"1250", 
			"610", 
			"9.0.0", 
			"/swf/expressInstall.swf", 
			flashvars, 
			params, 
			attributes);
		//Animation is 12s long, but it can take some time to start up
		setTimeout(function() {
			$("#flashHomeHero").hide();		
			//Show the promos
			$("#promos").fadeIn(500);	
		}, 15000);

		// Set cookie that someone has already visited the home page today to
		// avoid showing them the flash movie over and over.
		$.cookie('haveSeenTilexFlash', 'yes', { expires: 1, path: '/' });
	}
});


