$(document).ready(function(){
	$(document).pngFix();
    initMenus();	
	$("span.excellent-loading").hide();
	$("ul#excellent-navi li").click(function(){
		$("ul#excellent-navi li[class*=active]").removeClass();
		$(this).addClass("active");
	});
	$("#main-logo-container").flash({
		swf: "flash/logo.swf",
		params: {
			quality: "high",
			wmode: "transparent"
		},
		width: 187,
		height: 107
	});
	$("#excellent-flash").flash({
		swf: "flash/excellent-menu.swf",
		params: {
			quality: "high",
			wmode: "transparent"
		},
		width: 670,
		height: 330
	});
	$("#our-service-flash").flash({
		swf: "flash/our_service_en.swf",
		params: {
			quality: "high",
			wmode: "transparent"
		},
		width: 680,
		height: 450
	});
	$("#banner-container").flash({
		//swf: "images/banner_flood_en.jpg",
		swf: "flash/banner_en_960x303.swf",
		//swf: "flash/banner_en_old.swf",
		//swf: "flash/banner2_960x283_ipo_en.swf",
		params: {
			quality: "high",
			wmode: "transparent"
		},
		width: 960,
		height: 303
	});
	excellent_content("ei");
	$("ul#excellent-navi").lavaLamp({
		fx: "backout",
		speed: 750,
		click: function(event, menuItem) {
			var id = $(this).attr("rel");
			excellent_content(id);
		}
	});
	var cHeight = $("#content-detail").height();
	var nHeight = $("#navi").height();
	if(cHeight > nHeight)
	{
		$("#navi").height(Math.round(cHeight + 15));
		$('ul[id="navi"]').height(cHeight + 15);
		$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
		$('ul[id="navi"]').css("height","auto!important");
	}
	$("#MFMD, .MD").click(function(){
		$("#MFMD").hide(250);
	});
	//$("#MFMD").scrollads({closer:".close", hsnap:"center", vsnap:"middle", smooth: "true"});
	/*
    $("ul#navi_containTab > li").click(function(event){  
		var menuIndex = $(this).index();
		$("ul#navi_containTab > li[class*='active']").removeClass("active");
		$(this).addClass("active"); 
		$("ul#detail_containTab > li:visible").hide();
		$("ul#detail_containTab > li").eq(menuIndex).show();
		cHeight = $("#content-detail").height();
		$("#navi").height(Math.round(cHeight + 15));
    }); 
	*/
});

function MFMD()
{
	$("#MFMD").show(250);	
}
function our_service(id)
{
	$("#our-service-container").hide();
	$("#i_containTab").show();
	var menuIndex = id; 
	$("ul#navi_containTab > li[class*='active']").removeClass("active");
	$("ul#navi_containTab > li").eq(menuIndex).addClass("active"); 
	$("ul#detail_containTab > li:visible").hide();
	$("ul#detail_containTab > li").eq(menuIndex).show();
	cHeight = $("#content-detail").height();
	$("#navi").height(Math.round(cHeight + 15));
}
function language(lang)
{
	$.ajax({
		type: "POST",
		url: "language.php",
		data: "lang=" + lang,
		dataType: "html",
		cache: false, 
		error: function() 
		{ 
			alert("Sorry, The Language System is inconvience.");
		},
		success: function(data) 
		{
			window.location.reload();									   
		}
	});
}
function initMenus() {
	$("ul.main-position ul").hide();
	$.each($("ul.main-position"), function(){
		$("#" + this.id + ".expandfirst ul:first").show();
	});
	$("ul.main-position li a").click(function() {
        $("ul.main-position li a[class*=active]").removeClass("active");
        $(this).addClass("active");
		var checkElement = $(this).next();
		var parent = this.parentNode.parentNode.id;
		if($("#" + parent).hasClass("noaccordion")) {
			$(this).find("ul.sub-position li ul").slideToggle("normal", function(){
                cHeight = $("#content-detail").height();          
                $("#navi").height(Math.round(cHeight + 15));
			});
			return false;
		}
		if((checkElement.is("ul")) && (checkElement.is(":visible"))) {
            $("ul.main-position li a[class*=active]").removeClass("active");
			if($("#" + parent).hasClass("collapsible")) {
				$("#" + parent + " ul:visible").slideUp("normal", function(){
                    cHeight = $("#content-detail").height();
                    $("#navi").height(Math.round(cHeight + 15));
				});
			}
			return false;
		}
		if((checkElement.is("ul")) && (!checkElement.is(":visible"))) {
			$("#" + parent + " ul:visible").slideUp("normal", function(){
                cHeight = $("#content-detail").height();
                $("#navi").height(Math.round(cHeight + 15));
						 
			});
			checkElement.slideDown("normal");
			return false;
		}
	});
}
function open_dilog(url, width, height)
{
    var popup = window.open(url, "", "location=0, status=1, scrollbars=1, width=" + width + ", height=" + height);
}
function csr_activity(id, lang)
{
    $("ul.csr li[id!=" + id + "]").animate({ height: 160}, 500, function(){
        cHeight = $("#content-detail").height();
        $("#navi").height(Math.round(cHeight + 15));
        $("ul.csr li#" + $(this).attr("id") + " .detail").load("data/corporate_responsibility/" + lang + "/csr_activity/" + $(this).attr("id") + "/title.html", function() {								  
        	var height = $("ul.csr li[id!=" + id + "] .detail div").height();
        	$("ul.csr li[id!=" + id + "] div.btn-read-news").css("background-position", "top");
            $("ul.csr li[id!=" + id + "] div.btn-read-news").removeClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
    });
	if($("#" + id + " div.btn-read-news-" + lang).hasClass("read"))
	{
        $("#" + id).animate({ height: 160}, 500, function(){
            cHeight = $("#content-detail").height();
            $("#navi").height(Math.round(cHeight + 15));
        });
        $("#" + id + " .detail").load("data/corporate_responsibility/" + lang + "/csr_activity/" + id + "/title.html", function() {								  
        	var height = $("#" + id + " .detail div").height();
        	
        	$("#" + id + " div.btn-read-news-" + lang).css("background-position", "top");
            $("#" + id + " div.btn-read-news-" + lang).removeClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
		$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
	}
	else
	{
        $("#" + id + " .detail").load("data/corporate_responsibility/" + lang + "/csr_activity/" + id + "/index.html", function() {								  
    		var height = $("#" + id + " .detail div").height();
    		$("#" + id).animate({ height: Math.round(height + 45) }, 500, function(){
    			$(this).css({
    				overflow: "hidden"
    			});	
                cHeight = $("#content-detail").height();
                $("#navi").height(Math.round(cHeight + 15));														   
    		});
    		$("#" + id + " div.btn-read-news-" + lang).css("background-position", "bottom");
    		$("#" + id + " div.btn-read-news-" + lang).addClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
		$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
	}
}
function our_activity(id, lang)
{
    $("ul.csr li[id!=" + id + "]").animate({ height: 160}, 500, function(){
        cHeight = $("#content-detail").height();
        $("#navi").height(Math.round(cHeight + 15));
        $("ul.csr li#" + $(this).attr("id") + " .detail").load("data/news_activities/" + lang + "/our_activity/" + $(this).attr("id") + "/title.html", function() {								  
        	var height = $("ul.csr li[id!=" + id + "] .detail div").height();
        	$("ul.csr li[id!=" + id + "] div.btn-read-news-" + lang).css("background-position", "top");
            $("ul.csr li[id!=" + id + "] div.btn-read-news-" + lang).removeClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
    });
	if($("#" + id + " div.btn-read-news-" + lang).hasClass("read"))
	{
        $("#" + id).animate({ height: 160}, 500, function(){
            cHeight = $("#content-detail").height();
            $("#navi").height(Math.round(cHeight + 15));
        });
        $("#" + id + " .detail").load("data/news_activities/" + lang + "/our_activity/" + id + "/title.html", function() {								  
        	var height = $("#" + id + " .detail div").height();
        	
        	$("#" + id + " div.btn-read-news-" + lang).css("background-position", "top");
            $("#" + id + " div.btn-read-news-" + lang).removeClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
		$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
	}
	else
	{
        $("#" + id + " .detail").load("data/news_activities/" + lang + "/our_activity/" + id + "/index.html", function() {								  
    		var height = $("#" + id + " .detail div").height();
    		$("#" + id).animate({ height: Math.round(height + 45) }, 500, function(){
    			$(this).css({
    				overflow: "hidden"
    			});	
                cHeight = $("#content-detail").height();
                $("#navi").height(Math.round(cHeight + 15));														   
    		});
    		$("#" + id + " div.btn-read-news-" + lang).css("background-position", "bottom");
    		$("#" + id + " div.btn-read-news-" + lang).addClass("read");
			$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
        });
		$('ul[id="navi"]').css("min-height", function(){ return cHeight + 15; });
	}
}
function newsletter_online(id, lang)
{
	$("#e-newsletter-display").html('<div style="width:220px;height:19px;margin-left:auto;margin-right:auto;margin-top:140px;"<img src="images/misc/loading.gif" width="220" height="19" /></div>');
	$("#e-newsletter-list .item").removeClass("active");
	$.ajax({
			type: "POST",
			url: "data/news_activities/newsletter_online/newsletter_online_data.php",
			data: "id=" + id + "&lang=" + lang,
			dataType: "html",
			cache: false, 
			error: function() 
			{ 
				alert("Sorry, The Content System is inconvience.");
			},
			success: function(data) 
			{
				$("#e-newsletter-display").html("").html(data);
				$("#e-newsletter-list #" + id).addClass("active");
			}
		});	
}
function excellent_content(id)
{
	$("#excellent-content div").hide(250, function(){
		$("span.excellent-loading").fadeIn(100);
		$.ajax({
			type: "POST",
			url: "excellent-content.php",
			data: "id=" + id,
			dataType: "html",
			cache: false, 
			error: function() 
			{ 
				alert("Sorry, The Content System is inconvience.");
			},
			success: function(data) 
			{
				$("span.excellent-loading").fadeOut(150, function(){
					$("#excellent-content div").html(data).show(500);
				});
			}
		});	
	});
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
