/*
* Top page
* 
* Flash Min Size: 345px
* Flash Max Size: 588px
* Header : 126px;
* Footer : 138px;
*
**************************************/
var flashvars = {};
var params = {};
params.allowScriptAccess = "sameDomain";
params.allowFullScreen = false;
params.wmode = "window";
params.scale = "noscale";
params.bgcolor = "#ebebeb";
var attributes = {};

swfobject.embedSWF("/en/swf/main.swf", "flashexternal", "100%", "100%", "9.0.0", "/en/shared/swf/expressInstall.swf", flashvars, params, attributes);

function setElement(){
	var wHeight = $.browser.msie ? document.documentElement.clientHeight : window.innerHeight;
	if (wHeight <= 609){
		$("#content").css("height", "345px");
		$("#footerBlock").css("top", "471px");
	} else if (wHeight > 609 && wHeight <= 852){
		var contentHeight = wHeight - 126 - 138;
		$("#content").css("height", contentHeight + "px");
		var footerTop = contentHeight + 126;
		$("#footerBlock").css("top", footerTop + "px");
	} else {
		$("#content").css("height", "588px");
		$("#footerBlock").css("top", "714px");
		var footerHeight = wHeight - 714;
		$("#footerBlock").css("height", footerHeight + "px");
	}
}

function resetElement(){
	var wHeight = $.browser.msie ? document.documentElement.clientHeight : window.innerHeight;
	if (wHeight <= 609){
		$("#content").css("height", "345px");
		$("#footerBlock").css("top", "471px");
	} else if (wHeight > 609 && wHeight <= 852){
		var contentHeight = wHeight - 126 - 138;
		$("#content").css("height", contentHeight + "px");
		var footerTop = contentHeight + 126;
		$("#footerBlock").css("top", footerTop + "px");
	} else {
		$("#content").css("height", "588px");
		$("#footerBlock").css("top", "714px");
		var footerHeight = wHeight - 714;
		$("#footerBlock").css("height", footerHeight + "px");
	}
}

function setNews(){
	var newsNum = 0;
	var currentNews = 1;
	var newsData;
	var newsTimer;
	
	$.getJSON("/en/topnews.js", null, function(data){
		newsData = data;
		var img = new Array();
		for(i in data){
			img[i] = new Image();
			img[i].src = data[i].image;
			newsNum++;
		}
		if(newsNum > 1){
			newsTimer = setInterval(changeNews, 8000);
		}
	});
	
	function changeNews(){
		if(currentNews == newsNum){
			currentNews = 1;
		} else {
			currentNews++;
		}
		dataId = "news" + currentNews;
		$("div.pBlockTop2").fadeOut("fast", function(){
			$("div.pBlockTop2 div.col1 img").attr("src", newsData[dataId].image);
			$("div.pBlockTop2 div.col1 a").attr("href", newsData[dataId].url);
			$("div.pBlockTop2 div.col2 span.date").empty().append(newsData[dataId].date);
			$("div.pBlockTop2 div.col2 span.title").empty().append(newsData[dataId].title);
			$("div.pBlockTop2 div.col2 span.excerpt").empty().append(newsData[dataId].excerpt);
			$("div.pBlockTop2 div.col2 a").attr("href", newsData[dataId].url);
			$("div.pBlockTop2").fadeIn("fast");
		});
//$("#searchWord").attr("value", document.getElementById("footer").clientHeight);
	}
}

function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

$(document).ready(function(){
	setElement();
	window.onresize = resetElement;
	setNews();
/*	$("a[href]").click(function(){
		getMovie("flashexternal").setExternalCall(); 
	});*/
});
