var fHeight = 0;
var scrollY = 0;

/*
	update flash height
*/
//called from flash to set new document height
function updateFlashHeight(height){
	 fHeight = height+30;
	 var windowHeight = getWindowHeight();
	 fHeight = fHeight > windowHeight ? fHeight : windowHeight;
	 setFlashElementHeight(fHeight)
}

//update flash height using browser
$(window).resize(function(){
	 var windowHeight = getWindowHeight();
	 if(windowHeight > fHeight){
	 	updateFlashHeight(windowHeight);
	 }
});

function setFlashElementHeight(h){
	$('#wrapper').css({height: h});
    $('#flashContent').css({height: h});
  	$('#flashContent embed').attr('height', h);
}


/*
	scroll flash
*/
//called from flash to scroll to specific images
function scrollFlashTo(position){
    $('html,body').stop(true, true);
    $('html,body').animate({scrollTop: position}, 400, "swing");
}

//scroll flash using browser to get around swf max height issues
$(window).scroll(function(){
  	if(scrollY == getScrollY()){
		return;
	}
	scrollY = getScrollY();
	scrollFlashRelative(scrollY);
});

//calls .scrollFromJS on pss-website-shell.swf to reposition
//flash content so it never gets past 2000 pixels
function scrollFlashRelative(scrollY){
	if(!getFlash('paperStoneScissorsFlash').scrollFromJS){
		return;
	}
	getFlash('paperStoneScissorsFlash').scrollFromJS(scrollY);
	if(scrollY > 2000){
		var nHeight = fHeight-(scrollY-2000);
		 $('#wrapper').css({'padding-top': scrollY-2000});
		setFlashElementHeight(nHeight);
	}
	else{
		 $('#wrapper').css({'padding-top': 0});
		setFlashElementHeight(fHeight)
	}
}


/*
	utils
*/
//cross-browser get window scroll position
function getScrollY(){
  	var y = 0;
  	if(typeof(window.pageYOffset) == 'number'){
    	y = window.pageYOffset;
  	} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
    	y = document.body.scrollTop;
  	} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
    	y = document.documentElement.scrollTop;
  	}
  	return y;
}

//cross-browser get window height
function getWindowHeight(){
	return windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
}

//cross browser get flash element
function getFlash(movieName) {
     if (navigator.appName.indexOf("Microsoft") != -1) {
         return window[movieName];
     } else {
         return document[movieName];
     }
 }


function checkRedirect(checkURL_array, redirectURL){

	var currentURL = document.URL;
	
	for(var i=0;i<checkURL_array.length; i++){
	
		if(checkURL_array[i] == currentURL){
			window.location = redirectURL;
		}
	}
}

var redirect_urls = new Array()

redirect_urls.push("http://www.paperstonescissors.com/")
redirect_urls.push("http://www.paperstonescissors.com")
redirect_urls.push("http://paperstonescissors.com/")
redirect_urls.push("http://paperstonescissors.com")
redirect_urls.push("http://paperstonescissors.com/#")
redirect_urls.push("http://www.paperstonescissors.com/#")
redirect_urls.push("http://www.paperstonescissors.com/#/")

//checkRedirect(redirect_urls, "http://www.paperstonescissors.com/news/")
