var flVer = deconcept.SWFObjectUtil.getPlayerVersion();
var check_iPhone = navigator.userAgent.search('iPhone');
var check_iTouch = navigator.userAgent.search('iPod');

function sizePage()
{
	var f = $("footer");

	var fd = f.getCoordinates();
	
	var ph = fd.top+fd.height;
	var wh = window.getHeight() + 60;
	
	if(ph<wh) f.setStyle('height', fd.height + (wh-ph));

	$('content').setStyle('width',window.getWidth());
	if($('masthead') != null) $('masthead').setStyle('width',window.getWidth());
}

// have page resize on rotation
window.onorientationchange = sizePage;


window.addEvent('domready', function()
{
	var redirecting = false;
	
	// do redirect if browser supports flash and isn't iPhone
	if(flVer["major"] > 0)
	{
		
		$$('html')[0].setStyle("height", "100%");
		$$('html')[0].setStyle("overflow", "auto");
		
		//check to see if not iPhone!
		if(window.orientation === undefined && document.body.id != "index")
		{
		//Not running on iPhone/iPod or version is less than 1.1.1, check further.
		//run user agent check
			if(check_iPhone < 0 && check_iTouch < 0)
			{
				var newDeeplink =  pathToRoot + "index.html";
				//var newDeeplink = "http://www.nike.com/jumpman23/index.html";
			
				var cpval = gup('cp');
				if(cpval != null && cpval != "" && cpval != undefined && cpval != "undefined")
				{
					newDeeplink += "?cp=" + cpval;	
				}
				else
				{
					var fbcpval = gup('fb_ref');
					if(fbcpval != null && fbcpval != "" && fbcpval != undefined && fbcpval != "undefined")
					{
						newDeeplink += "?cp=fb_" + fbcpval;	
					}
				}
				
				
				var ssval = gup('siteSrc');
				if(ssval != null && ssval != "" && ssval != undefined && ssval != "undefined")
				{
					if(newDeeplink.indexOf("?") == -1)
					{
						newDeeplink += "?siteSrc=" + ssval;
					}
					else
					{
						newDeeplink += "&siteSrc="+ssval;
					}
				}
				
				if(sectionID != null && sectionID != "" && sectionID != undefined && sectionID != "undefined")
				{
					newDeeplink += "#" + sectionID;
					
					if(contentID != null && contentID != "" && contentID != undefined && contentID != "undefined")
					{
						newDeeplink += "/" + contentID;
						
						if(sectionID == "stories")
						{
							if(document.location.href.indexOf("/features/") != -1)
							{
								newDeeplink += "?type=contentFeatures";
							}
							else
							{
								newDeeplink += "?type=jtvContent";
							}
						}
						
					}				
				}

				redirecting = true;
				document.location = newDeeplink;			
			}
		}
	}
	else
	{
		// if no flash and on iPhone/iTouch
		if(window.orientation !== undefined || (check_iPhone >= 0 || check_iTouch >= 0))
		{
			sizePage();
			
			var scrollChange = new Fx.Scroll($(window));
			scrollChange.set(0,1);
						
			var paddingChange = new Fx.Tween(document.body, {
			duration:500, 
			transition: Fx.Transitions.Sine.easeOut
			});
			paddingChange.start('padding-left',window.getWidth(), 0);

		}
		
		var t=setTimeout(function()
		{
			$("loadMask").style.display = "none";
			clearTimeout(t);
		},25);
		
	}

}
);
