var swfVersionStr = "10.1.0";
var xiSwfUrlStr = filePath + "playerProductInstall.swf";

var flashvars = {};
flashvars.preview = "true";

var params = {};
params.quality = "high";
params.bgcolor = "#FFFFFF";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
params.menu = 'false';
params.scale = 'noscale';
params.salign="tl";
params.wmode="transparent";

var attributes = {};
attributes.id = "application";
attributes.name = "index";
attributes.align = "none";

var SWFFile = filePath + "index.swf" + "?" + (new Date()).getTime();
var SWFWidth = "100%";
var SWFHeight = "100%";

var SWFResizeMode = true;

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

$(document).ready( function() {
	swfobject.embedSWF(SWFFile, 'flashContent', SWFWidth, SWFHeight, swfVersionStr, xiSwfUrlStr, flashvars, params, attributes, embedSWFComplete);
	$('#flashContent').css('display', 'block');
});
function embedSWFComplete(event) {
	$(document).mousewheel( function(event, delta) {
		var SWFObjectReference = swfobject.getObjectById('application');
		if(SWFObjectReference != null) {
			if (typeof (SWFObjectReference.mouseWheel) == 'function') {
				SWFObjectReference.mouseWheel(delta);
			}
		}
	});
	setResizeMode(SWFResizeMode);
	$(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');
}
