var SWFResizeMode = false;

var windowMinWidth = -1;
var windowMinHeight = -1;
var windowScrollXDelta = 0;
var windowScrollYDelta = 0;


		
function embedSWFComplete(event) {
	$(document).mousewheel(function(event, delta) {
		var SWFObjectReference = swfobject.getObjectById('application');
		if(SWFObjectReference != null)
		{
			if (typeof (SWFObjectReference.mouseWheel) == 'function') 
			{
				SWFObjectReference.mouseWheel(delta);
			}
		}
	});
	$(window).bind('resize', windowResizeHandler);	
	$(window).bind('scroll', windowScrollHandler);
}

function windowResizeHandler() {	
	var newWidth, newHeight, minWidth, minHeight, currentWidth, currentHeight;
	currentWidth = document.body.offsetWidth;
	currentHeight = document.body.offsetHeight;

	if (windowMinWidth == -1) {
		minWidth = '0px';
		newWidth = '100%';
	} else {
		minWidth = windowMinWidth + 'px';
		newWidth = currentWidth < windowMinWidth ? windowMinWidth + 'px' : '100%';
	}

	if (windowMinHeight == -1) {
		minHeight = '0px';
		newHeight = '100%';
	} else {
		minHeight = windowMinHeight + 'px';
		newHeight = currentHeight < windowMinHeight ? windowMinHeight + 'px' : '100%';
	}

	if (SWFResizeMode) {
		$('#htmlContainer').css({'min-width':'0px', 'min-height':'0px', 'width':'100%', 'height':'100%'});
		$('#flashContainer').css({'min-width':minWidth, 'min-height':minHeight, 'width':newWidth, 'height':newHeight});
	} else {
		$('#flashContainer').css({'min-width':'0px', 'min-height':'0px', 'width':'100%', 'height':'100%'});
		$('#htmlContainer').css({'min-width':minWidth, 'min-height':minHeight, 'width':newWidth, 'height':newHeight});
	}
	
	var SWFObjectReference = swfobject.getObjectById('application');
	if(SWFObjectReference != null)
	{
		if (typeof (SWFObjectReference.windowResize) == 'function') 
		{
			SWFObjectReference.windowResize(windowPropertiesObject());
		}
	}
}

function windowScrollHandler(){
	var SWFObjectReference = swfobject.getObjectById('application');
	if(SWFObjectReference != null)
	{
		if (typeof (SWFObjectReference.windowScroll) == 'function') 
		{
			SWFObjectReference.windowScroll(windowPropertiesObject());
		}
	}
}

function setResizeMode(resizeMode) {
	SWFResizeMode = resizeMode;
	if (SWFResizeMode) {
		$('#htmlContainer').css({'overflow':'hidden', 'position':'fixed'});
		$('#flashContainer').css({'overflow':'visible', 'position':'absolute'});
	} else {
		$('#flashContainer').css({'overflow':'hidden', 'position':'fixed'});
		$('#htmlContainer').css({'overflow':'visible', 'position':'absolute'});
	}
	windowResizeHandler();
}

function setWindowMinimumSize(minWidth, minHeight)
{
	windowMinWidth = minWidth;
	windowMinHeight = minHeight;
	windowResizeHandler();
}

function windowPropertiesObject(){
	var left, top, bottom, right, currentWidth, currentHeight, iebody;
	iebody=(document.compatMode && document.compatMode != 'BackCompat') ? document.documentElement : document.body;
	currentWidth = document.body.offsetWidth;
	currentHeight = document.body.offsetHeight;
			
	left = document.all ? iebody.scrollLeft : window.pageXOffset;
	top = document.all ? iebody.scrollTop : window.pageYOffset;	
	right = windowMinWidth - currentWidth - left;
	bottom = windowMinHeight - currentHeight - top;
	windowScrollXDelta = Math.round(100 * (left / (windowMinWidth - currentWidth))) / 100;
	windowScrollYDelta = Math.round(100 * (top / (windowMinHeight - currentHeight))) / 100;
	
	if(windowMinWidth == -1 || left < 0 || right < 0)
	{
		windowScrollXDelta = left = right = 0;
	}
	
	if(windowMinHeight == -1 || top < 0 || bottom < 0)
	{
		windowScrollYDelta = top = bottom = 0;
	}
	
	return {'width':document.body.offsetWidth, 'height':document.body.offsetHeight, 'top':top, 'left':left, 'bottom':bottom, 'right':right, 'windowScrollXDelta':windowScrollXDelta, 'windowScrollYDelta':windowScrollYDelta};
}

function setScrollPosition(xPos, yPos)
{
	window.scrollTo(xPos, yPos);
}

function showVerticalScrollBar(){
	$('html').css('overflow-y', 'scroll');
}

function hideVerticalScrollBar(){
	$('html').css('overflow-y', 'visible');
}

function showHorizontalScrollBar(){
	$('html').css('overflow-x', 'scroll');
}

function hideHorizontalScrollBar(){
	$('html').css('overflow-x', 'visible');
}
