function uniqueID(lng){
	var str = "";
	var b = "";
	if (!lng) {
		var lng = 40;
	}
	for (var i = 0; i < lng; i++) {
		b = Math.round(Math.random() * 36).toString(36);
		str += Math.round(Math.random() * 2) ? b.toUpperCase() : b.toLowerCase();
	}
	return str;
}

var minWidth = 800;
var minHeight = 600;
var maxWidth = 1600;
var maxHeight = 1200;

function displayResized(){
	var size = displaySize();
	var content = document.getElementById("content");
	
	content.style.width = (size[0] < minWidth) ? minWidth + "px" : (size[0] > maxWidth) ? maxWidth : size[0] + "px";
	content.style.height = (size[1] < minHeight) ? minHeight + "px" : (size[1] > maxHeight) ? maxHeight : size[1] + "px";
	
	if (size[0] > maxWidth) {
		content.style.left = "50%";
		content.style.marginLeft = -Math.round(maxWidth * .5) + "px";
	}
	else {
		content.style.left = "0px";
		content.style.marginLeft = "0px";
	}
	
	if (size[1] > maxHeight) {
		content.style.top = "50%";
		content.style.marginTop = -Math.round(maxHeight * .5) + "px";
	}
	else {
		content.style.top = "0px";
		content.style.marginTop = "0px";
	}
	
}

function displaySize(){
	var size = [0, 0];
	if (typeof window.innerWidth != "undefined") {
		size = [window.innerWidth, window.innerHeight];
	}
	else 
		if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
			size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
		}
		else {
			size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
		}
	
	return size;
}

function addFlashContent(reload, lang, langXML, configXML, location, showStoreLocator, pos, country){

	var flashFile;
	var flashVersion;
	
	switch (lang)
	{
		case "zhs": 
			flashVersion = "10.0";
			flashFile = "main_zhs.swf"; 
			break;
		case "zht": 
			flashVersion = "10.0";
			flashFile = "main_zht.swf"; 
			break;
		case "ja": 
			flashVersion = "10.1";
			flashFile = "main_ja.swf"; 
			break;
		case "ko": 
			flashVersion = "10.0";
			flashFile = "main_ko.swf"; 
			break;
		default: 
			flashVersion = "10.0";
			flashFile = "main.swf"; 
			break;
	}
	
	var flashvars = {
		configXML: configXML,
		lang: lang,
		langXML: langXML,
		location: location,
		showStoreLocator: showStoreLocator,
		pos: pos,
		country : country
	};
	
	var params = {
		bgcolor: '#000000',
		allowscriptaccess: "always",
		allownetworking: "all",
		allowFullScreen: true
	};
	
	var attributes = { 
			id:'iwcebook', 
			name:'iwcebook' 
	};
	
	swfobject.embedSWF('/swf/'+flashFile+'?' + '&cacheKiller=' + reload, 'content', '100%', '100%', flashVersion, '/swf/expressinstall.swf', flashvars, params, attributes);
	if (!swfobject.hasFlashPlayerVersion("10")) {
		document.body.className = 'fallback';
	}
	
	swfmacmousewheel.registerObject(attributes.id);
	
	displayResized();
}

function openLegal(url)
{
	window.open(url, 'legal', 'width=615,height=770,resizable=no,scrollbars=yes,locationbar=no');
	return false;	
}

function openContact(url)
{
	window.open(url, 'contact', 'width=750,height=820,resizable=no,scrollbars=yes,locationbar=no');
	return false;	
}

function open360(url, title)
{
	window.open(url, 'viewer', 'width=735,height=730,resizable=no,scrollbars=no,locationbar=no');
	return false;	
}

function shareOnFacebook(url)
{

	window.open(url, 'Facebook', 'width=760,height=500,resizable=no,scrollbars=no,locationbar=no');
	return false;	
}
