var fHeight = 0;
var scrollY = 0;

/*
	update flash height
*/
//called from flash to set new document height
function updateFlashHeight(height){
	 fHeight = height;
	 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', '100%');
}


//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 shell to reposition
//flash content so it never gets past 2000 pixels
function scrollFlashRelative(scrollY){
	if(!getFlash('cbFlash').scrollFromJS){
		return;
	}
	getFlash('cbFlash').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
*/
/*
	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];
     }
 }
