var MIN_WIDTH = 942;

var reqFlashStr = '9.0.115';
var noFlashDiv = 'container';
var flashVerVeriferDiv = 'flashVerVerifier';

var minWidth = MIN_WIDTH;
var minHeight = 575;
var scrollable = false;

var requiredFlashVersion = new deconcept.PlayerVersion(reqFlashStr.split("."));

var buildStr = "";
if(window.location.href.indexOf("http:") != -1 || window.location.href.indexOf("https:") != -1) buildStr = "?cb=" + Math.round((Math.random() * 10000000));


var currentHref;

var j23home = new SWFObject("swf/J23Home.swf"+buildStr, "J23Home", minWidth, minHeight, reqFlashStr, "#E5E5E5", true);
j23home.setAttribute('xiRedirectUrl', 'http://jumpman23.com/');
j23home.setAttribute('width', '100%');
j23home.setAttribute('height', '100%');
j23home.setAttribute('id', 'J23Home');
j23home.addParam("scale", "noscale");
j23home.addParam("allowFullScreen", "true");
j23home.addParam("allowScriptAccess", "always");
j23home.addParam('menu', 'false');
j23home.addParam('wmode', 'opaque');
j23home.addVariable('deploydomain',window.location.href.split("?")[0]);
//j23home.write("flashContent");

var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1);
var IE9 = (navigator.userAgent.toLowerCase().indexOf('msie 9') != -1);

/*
	Called onload.
*/
function flashCheck(flashVersion)
{
	var userFlashVersion;

	if(typeof flashVersion != "undefined")
	{
		userFlashVersion = new deconcept.PlayerVersion(flashVersion.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").replace(/,/g,'.').split("."));
	}
	else
	{
		userFlashVersion = deconcept.SWFObjectUtil.getPlayerVersion();
	}

	
	if(userFlashVersion.versionIsValid(requiredFlashVersion))
	{
		j23home.skipDetect = true;
		writeSWFObj();
	}
	else
	{
		var fvStr = '0.0.0';
		
		if(userFlashVersion.versionIsValid(new deconcept.PlayerVersion(fvStr.split("."))) && (typeof flashVersion == "undefined"))
		{
			var myDiv = document.createElement("div");
			myDiv.id = flashVerVeriferDiv;
			myDiv.setAttribute("id",flashVerVeriferDiv);
			document.body.appendChild(myDiv);
		
			var flashVersionVerifer = new SWFObject('swf/flashVersionVerifier.swf', 'fvv', '1', '1', fvStr, '#ededed');
			flashVersionVerifer.write(flashVerVeriferDiv);
		}
		else
		{	
			if(document.getElementById(flashVerVeriferDiv))
			{
				setTimeout(
					function()
					{
						document.body.removeChild(document.getElementById(flashVerVeriferDiv));
					},100);
			}

			j23home.useExpressInstall('swf/expressinstall.swf');
			
			writeSWFObj();
		}	
	}
}

function writeSWFObj()
{
	$('body').append($('<div id=\"scrollDiv\" />'));

	onWindowResize();
	$(window).resize(onWindowResize);
	$(window).scroll(onWindowScroll);

	/*
	$("footer").style.display = "none";
	$("tlNav").style.display = "none";
	*/
	
	youtubeID = "J23Home";

	var t = setTimeout(
		function()
		{
			//$("loadMask").style.display = "none";
			
			j23home.write(noFlashDiv)
			if(IE6)
			{
				$('html').css('background-image', 'url(about: blank)');
				$('#container').addClass('fixedTopLeft');
			}
			else
			{
				$("#container").css("position","fixed");
			}

			clearTimeout(t);
		},100);
		
	currentHref = window.location.href;
}

if(check_iPhone != -1 || check_iTouch != -1 || check_iPad != -1 || check_android != -1)
{
	$(document).ready(function()
	{
		var rssURL = (document.location.protocol.indexOf('http') != -1 ) ? 'feeds/rss/blogRSS.jsp' : 'http://www.nike.com/jumpman23/feeds/rss/blogRSS.jsp';
		
		$('#blogEntryList').simplerss({
        	url: rssURL,
            //html: '<a href="{link}">{image}<strong>{category}</strong>{title}</a><p class="blogTimeStamp">{date}</p><p>{text}</p>',
            html: '<a href="{link}&linksrc=hp">{image}{title}</a><p class="blogTimeStamp">{date}</p><p>{text}</p>',
			display: 2
        }).show();
	
	
	}
	);
}


function returnFocus()
{
	window.focus();		
}

function onWindowResize()
{
	if($("#J23Home") != null && $("#J23Home").flashUpdateScrollOffset != undefined)
	{
		if ($(window).height() > $("#scrollDiv").height()) 
		{
			$("#J23Home").flashUpdateScrollOffset(false);
		}
		else 
		{
			$("#J23Home").flashUpdateScrollOffset(true);
		}		
	}
	
	var w = $(window).width();
	if(w>MIN_WIDTH)
	{
		$("#container").css({width:w, height: $(window).height()});

		if(currentLikeButton)
		{
			var diff = w-widthAtAdd;
			
			currentLikeButton.style.left =  startingPos.x + Math.round(diff/2) + "px";
		}

	}
	else
	{
		$("#container").css({width:MIN_WIDTH, height: $(window).height()});
	}

}

function onWindowScroll()
{
	if(window.location.href != currentHref)
	{
		currentHref = window.location.href;
		return;
	}

	if($("#J23Home") != null && $("#J23Home")[0].flashScrollManagerScrollTo)
	{	
		$("#J23Home")[0].flashScrollManagerScrollTo($(window).scrollTop());
	}
}

function setGSProxy(size,pos)
{

	if(size != -1) resizeHTMLContainer(size);
	$(window).scrollTop(pos);
	onWindowScroll();
}

function resizeHTMLContainer(newHeight)
{	
	//$("#scrollDiv").css("height",newHeight);
	$("#scrollDiv").height(newHeight);
	//alert($("scrollDiv").height());
		
	onWindowResize();
}

/*Credit http://www.netlobo.com/*/
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function openJ23PopUp(url, name, width, height, status, scrollbars, moreProperties, openerName)
{
	var newWin = openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName);
	
	if(!newWin) alert("Unable to launch pop-up window. If you wish to view pop-ups on this site, please disable your pop-up blocker and try again.");
}

function openJ23NewWindow(url, name, openerName)
{
	var newWin = openFullChromeWindow(url, name, openerName);
	
	if(!newWin) alert("Unable to launch content in window. If you wish to view this content, please disable your pop-up blocker and try again.");
}

var currentLikeButton;
var startingPos;
var gYOffset;
var widthAtAdd;
var likeID;

function addLikeButton(url, x, y, yOffset, metricsRef)
{
	likeID = metricsRef;
	
	if(currentLikeButton) killLikeButton();
	
	gYOffset = Math.round(yOffset);
	startingPos = {x:x, y:y};
	widthAtAdd = $(window).width();
	

	currentLikeButton = document.createElement('div');
	currentLikeButton.style.position = "fixed";
	currentLikeButton.style.top = parseInt(y)+"px";
	currentLikeButton.style.left = parseInt(x)+"px";
	currentLikeButton.style.clip = 'rect(' + (0-(y-yOffset)) + 'px,' + $(window).width() + 'px,' + $(window).height() + 'px,0px)'


	if(IE6 || IE9)
	{
		currentLikeButton.style.position = "absolute";

		var ifrm = document.createElement('iframe');
		ifrm.setAttribute('src', 'http://www.facebook.com/plugins/like.php?href=' + escape(url) + '&layout=button_count&show_faces=false&width=90&action=like&font=arial&colorscheme=light&height=20');
		ifrm.setAttribute('scrolling', 'no');
		ifrm.setAttribute('frameBorder', '0');
		ifrm.setAttribute('allowTransparency', 'true');
		
		currentLikeButton.appendChild(ifrm);
		document.body.appendChild(currentLikeButton);
	}
	else
	{
		var nestedFBML = document.createElement('fb:like');
		nestedFBML.setAttribute('layout', 'button_count');
		nestedFBML.setAttribute('font', 'arial');
		nestedFBML.setAttribute('href', url);
		if(metricsRef) nestedFBML.setAttribute('ref', metricsRef);	
		
		currentLikeButton.appendChild(nestedFBML);

		document.body.appendChild(currentLikeButton);
		
		FB.XFBML.parse(currentLikeButton);	
	}
	

}

function positionLikeScroller(y)
{
	if(currentLikeButton)
	{
		var ny = startingPos.y-y;
	
		if(!IE6 && !IE9) currentLikeButton.style.top = ny+"px";
		currentLikeButton.style.clip = 'rect(' + (0-(ny-gYOffset)) + 'px,' + $(window).width() + 'px,' + $(window).height() + 'px,0px)';
	}
}

function killLikeButton()
{
	likeID = undefined;
	
	if(currentLikeButton)
	{
		currentLikeButton.innerHTML = "";
		document.body.removeChild(currentLikeButton);
		//currentLikeButton.destroy();
		currentLikeButton = null;
	}
}

function hideLikeButton()
{
	if(currentLikeButton)
	{
		currentLikeButton.css("visibility","hidden");
	}

}

function showLikeButton()
{

	if(currentLikeButton)
	{
		currentLikeButton.css("visibility","visible");
	}

}

function reportLike(response)
{

	var om = s_gi(s_account);
	om.linkTrackVars='eVar43,events';
	om.linkTrackEvents='event12';
	if(likeID != undefined)
	{
		om.eVar43='fb_like_'+likeID;
	}
	else
	{
		om.eVar43='fb_page_like';
	}
	om.events='event12';
	om.tl(this,'o',om.eVar24);
	
}
