function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function loadFlashIndex(){
		var flashvars = {};
		var params = {};
		params.quality = "high";
		params.wmode = "transparent";
		params.swliveconnect = "true";
		params.allowscriptaccess = "always";
		var attributes = {};
		attributes.id = "test";
		attributes.name = "test";
		swfobject.embedSWF("test.swf", "example", "685", "562", "8.0.0", "expressInstall.swf", flashvars, params, attributes);
		swfobject.createCSS("#test","outline:none"); 
}

function test_DoFSCommand(command, args){
    switch (command) {
        case "msg":
			alert(args);
            break;
		case "swap":
			for(var i=0; i<=6; i++){
				$("#t"+i).hide();
			};
			$("#t"+args).show();
			$("#contact").hide();
			window.onresize = null;
			break;
		case "login":
			window.open("ftp://"+args+"@file.productsolutions.com.hk/");
			break;
		case "showContact":
			var offset = $("#test").offset();
			$("#contact").css("top", parseInt(offset.top)+101+"px").css("left", offset.left);
			$("#contact").show();
			$(".cdLeft, .cdRight").css("margin-top", parseInt(offset.top)+300+"px"); 
			window.onresize = function(){
				var offset = $("#test").offset();
				$("#contact").css("top", parseInt(offset.top)+101+"px").css("left", offset.left);
			};
			break;
		case "hideContact":
			$("#contact").hide();
			window.onresize = null;
			break;
		case "showNews":
			$("#newsFrame").attr("src", "news/news.html");
			$('#news').jqmShow();
			$(".jqmWindow").css("left", parseInt($("#test").offset().left) + 25);
			$(".jqmWindow").css("top", 82);
			break;
    }
}

function showHK(){
	$('#hk').jqmShow();
	$(".jqmWindow").css("left", parseInt($("#test").offset().left) + 25);
	$(".jqmWindow").css("top", 82);
}

function showUK(){
	$('#uk').jqmShow();
	$(".jqmWindow").css("left", parseInt($("#test").offset().left) + 25);
	$(".jqmWindow").css("top", 82);
}

$(document).ready(function(){
	loadFlashIndex();
	$('#news').jqm({ 
		modal: true, 
		onTop: true,
		onHide: function(hash){
			$("#newsFrame").attr("src", "news/empty.html");
			hash.w.hide();
			hash.o.remove(); 
		}
	});
	$('#uk').jqm({ modal: true, onTop: true });
	$('#hk').jqm({ modal: true, onTop: true });
	if(location.href.split("#section=")[1]=="contact"){
		test_DoFSCommand("showContact");
	};
	$("#btnContact").click(function(){
		var flash = getFlashMovie("test");
		try{
			flash.jsSwitchSection(5);
		}catch(e){};
	});
});
