// JavaScript Document
	$(document).ready(function(){
		/*$(document).pngFix();*/
		$("#hdrTitlePage").pngFix();
		$(".titleHomeRight").pngFix();
		
		$(".listFlashItem").find("li.listItemOne:first > a").addClass("active");
		var flash01 = $(".listFlashItem > li").click(function(){ $(this).attr("class"); });	
		var flash02 = "listItemOne";
		var flash03 = "listItemTwo";
		var flash04 = "listItemThree";
		
		var lengItem = new Array();
		
		lengItem[0] = flash02;
		lengItem[1] = flash03;
		lengItem[2] = flash04;
		
		var immm = Math.floor(Math.random() * lengItem.length);
		
		AnamaiteFlash(lengItem[immm]);
		AnamaiteFlashClick(flash01);
		
		function AnamaiteFlash(flash){

			var flashSh = $(".listFlashItem > li."+ flash +" > a").attr("flash");
			var titleSh = $(".listFlashItem > li."+ flash +" > a").attr("title");
			var f = $("ul.listFlashItem").find("a.active").removeClass("active");
			$(".listFlashItem > li."+ flash +" > a").addClass("active");
			$("#contentFlashRight").html(flashSh);
			$(".titleHomeRight").html(titleSh);

		}
		
		function AnamaiteFlashClick(flash){
			$(".listFlashItem > li."+ flash +" > a").click(function(){
				var flashSh = $(this).attr("flash");
				var titleSh = $(this).attr("title");
				var f = $("ul.listFlashItem").find("a.active").removeClass("active");
				$(this).addClass("active");
				$("#contentFlashRight").html(flashSh);
				$(".titleHomeRight").html(titleSh);
			});
		}
		
		
		/***************************   STOCK   ***********************************/ 
		
		$(".columnStockHome a").hover(function(){
			$(".columnStockHome").find("div:first").css({visibility: 'visible',display: 'none'}).show();

		},function(){
			$(".columnStockHome").find('div:first').css({visibility: "hidden"}).hide();
			
		});			
		
		/**********************   COMPANY BUSINESS   *******************************/ 
		
		$("a#tabTransformers").click(function(){
			$("#Transformers").show();
			$("#Services").hide();
		});
		$("a#tabServices").click(function(){
			$("#Transformers").hide();
			$("#Services").show();
		});
		
		/**********************   MESSAGE CHAIRMAN   *******************************/ 
		
		$("a#tabChairman").click(function(){
			$("#tabChairmanContent").show();
			$("#tabCEOContent").hide();
		});
		$("a#tabCEO").click(function(){
			$("#tabChairmanContent").hide();
			$("#tabCEOContent").show();
		});
		
		/************************** COMPANY HISTORY    ****************************/ 
		var yearH = $("#companyHistoryYear").find("div > a:first").attr("year");
		var contH = $("#companyHistoryYear").find("div > a:first").attr("conHis");
		$("#textHistoryYear").text(yearH);
		$("#textHistoryContent").html(contH);
		
		$("#companyHistoryYear").find("div > a:first").addClass("yearActive");
		
		$("#companyHistoryYear  #hisYear  a").mouseover(function(){
			$("#companyHistoryYear").find(".yearActive").removeClass("yearActive");
			$(this).addClass("yearActive");
				
			var textYear = $(this).attr("year");
			$("#textHistoryYear").text(textYear);
				
			var textConHis = $(this).attr("conHis");
			$("#textHistoryContent").html(textConHis);		
		});
		
		/************************** PRODUCTS ****************************/ 
		
		$("#productBottom > a.pro_0").click(function(){
			$("#productContent > .pro_0").fadeIn();
			$("#productContent > .pro_1").hide();
			$("#productContent > .pro_2").hide();
			$("span.hidepro_0").hide();
			$("span.hidepro_1").show();
			$("span.hidepro_2").show();
		});
		$("#productBottom > a.pro_1").click(function(){
			$("#productContent > .pro_1").fadeIn();
			$("#productContent > .pro_0").hide();
			$("#productContent > .pro_2").hide();
			$("span.hidepro_1").hide();
			$("span.hidepro_0").show();
			$("span.hidepro_2").show();
		});
		$("#productBottom > a.pro_2").click(function(){
			$("#productContent > .pro_2").fadeIn();
			$("#productContent > .pro_0").hide();
			$("#productContent > .pro_1").hide();
			$("span.hidepro_2").hide();
			$("span.hidepro_0").show();
			$("span.hidepro_1").show();
		});
		
		
		
		/************************** FLASH TITLE ****************************/ 
		
		$.sifr({
			path: 'src/flash/',
			save: true
		});
		$('#hdrTitlePageFlashen').sifr({ font: 'sifr_headerEN' });
		$('#hdrTitlePageFlashth').sifr({ font: 'sifr_headerTH' });
		//$('#headerCSRNews').sifr({ font: 'sifr_textTitleTH' });
		
		
		/************************** AWARDS & CERTIFICATIONS ****************************/ 
		
		var title = $("#thumbs > li:first").attr("title");
		$(".titleAwardText").html(title);
		
		$("#thumbs > li").click(function(){
			var title = $(this).attr("title");
			$(".titleAwardText").html(title);
			$("#thumbs").find(".active").removeClass("active");
			$(this).addClass("active");
			
		});
		
		var titleCer = $("#thumbsCer > li:first").attr("title");
		var fromCer = $("#thumbsCer > li:first").attr("from");
		var imgCer = $("#thumbsCer > li:first").attr("bigCer");
		var cerDetail = $("#thumbsCer > li:first").attr("detail");
		$(".titleCerText").html(titleCer);
		$(".fromCerText").html(fromCer);
		$("#imageCer").html(imgCer);
		$("#imageCerDetail").html(cerDetail);
		
		$("#thumbsCer > li").click(function(){
			
			var titleCer = $(this).attr("title");
			var fromCer = $(this).attr("from");
			var imgCer = $(this).attr("bigCer");
			var cerDetail = $(this).attr("detail");
			$(".titleCerText").html(titleCer);
			$(".fromCerText").html(fromCer);
			$("#imageCer").html(imgCer);
			$("#imageCerDetail").html(cerDetail);
			
			$("#thumbsCer").find(".active").removeClass("active");
			$(this).addClass("active");
			
		});
		
		
		
		/***************************** CSR *************************/
		
		/*$("#CSRNewsList").click(function(){
			var list = $(this).attr("class");
			$("."+list+"_show").fadeIn();
			$(this).hide();
		
			$("#CSRNewsListShow > .btCSRNewsBack > a").click(function(){
				$("."+list+"_show").hide();
				$("#CSRNewsList").fadeIn();
			});
		});*/
		
		function news_list(list){
			$("." + list + " > .CSRTitle > .CSRMore").click(function(){
				$("#csrActivityContent > ." + list + "_show").fadeIn();	
				$("#csrActivity").hide();
				$(".btCSRNewsBack").show();						
			});

		}
		
		$(".btCSRNewsBack").click(function(){
			$("#csrActivity").fadeIn();
			$("#csrActivityContent > div").hide();
			$(this).hide();			
		});
			
		var list_no = $("#csrActivity").find("#CSRNewsList").length;
			
		for(i = 1 ; i <= list_no ; i++){
			news_list("csr0"+i);
		}	
		
		
		
		/***************************** COMPETENCY *************************/
		
		var technical = "technical";
		var business  = "business";
		var customer  = "customer";
		
		function hideContent(id){
			$("."+ id + "Content").hide();
			$("a#"+ id).css("color","#565656");
		}
		function showContent(id){
			$("."+ id + "Content").show();
			$("a#"+ id).css("color","#007bbf");
			
		}
		function swapContent(id){		
			if(id == "technical"){
				showContent(technical);
				hideContent(business);
				hideContent(customer);
			}
			else if(id == "business"){
				showContent(business);
				hideContent(technical);
				hideContent(customer);
			}
			else if(id == "customer"){
				showContent(customer);
				hideContent(technical);
				hideContent(business);
			}
		}
		$("a#technical").css("color","#007bbf");
		$("#technical").click(function(){
			swapContent(technical);
		});
		$("#business").click(function(){
			swapContent(business);
		});
		$("#customer").click(function(){
			swapContent(customer);
		});	
		
		
		/*************************** CAREER ***********************************/
		
		function careers_list(list){
			$("." + list + " > .careers_more").click(function(){
				$("#careers_content > ." + list + "_show").fadeIn();	
				$("#careers_container_list").hide();
				$(".careers_bt_back").show();						
			});
			$(".careers_bt_back").click(function(){
				$("#careers_container_list").fadeIn();
				$("#careers_content > ." + list + "_show").hide();
				$(this).hide();			
			});
		}
		
			
		var list_no = $("#careers_container_list").find("#careers_list").length;
		
			
		for(i = 1 ; i <= list_no ; i++){
			careers_list("careers0"+i);
		}

		
		
		

	});
	
	/*************************** MARQUEE ********************************/
	
	var move_marquee;
	var marquee_status;
	var marquee_move;
	var marquee_speed;
	var marquee_step;
	var marquee_direction;
	var newLeft;
	var obj;
	$(function(){
		
		var divCover_w=$(".containMarquee").width(); // หาความกว้างพื้นที่ส่วนแสดง marquee
		var divMarquee_w=$(".obj_marquee").width(); //หาความกว้างของเนื้อหา marquee
		obj=$(".obj_marquee"); // กำหนดเป็น ตัวแปร jQuery object
		marquee_direction=1; /* กำหนดการเลื่อนซ้ายขวา 1 = จากขวามาซ้าย 2 = จากซ้ายไปขวา */
		marquee_speed=10; // กำหนดความเร็วของเวลาในการเคลื่อนที่ ค่ายิ่งมาก จะช้า
		marquee_step=1; // กำหนดระยะการเคลื่อนที่ ค่ายิ่งมาก จะเร็ว
		
		obj.css("left",(marquee_direction==1)?divCover_w:-divMarquee_w);
		marquee_move=function(obj){
			marquee_status=setTimeout(function(){
				move_marquee(obj)
			},marquee_speed);		
		}
		move_marquee=function(obj){
			var condition_mq=(marquee_direction==2)?'newLeft<divCover_w':'newLeft>-divMarquee_w';
			var initLeft=(marquee_direction==1)?divCover_w:-divMarquee_w;
			newLeft=(marquee_direction==1)
			?parseInt(obj.css('left'))-marquee_step
			:parseInt(obj.css('left'))+marquee_step;
			if(eval(condition_mq)){
				obj.css({
					'left':newLeft+'px'
				});
			}else{
				obj.css("left",initLeft);
			}				
			marquee_move(obj);
		}	
		marquee_move(obj);
	
	
		$(".containMarquee").mouseover(function(){
			clearTimeout(marquee_status);
		}).mouseout(function(){
			marquee_move(obj);
		});
	
		
	});
	
	
	/*************************** POPUP ***********************************/
	
	Shadowbox.init({
		skipSetup: true,
		players: ["html"]
	});
	
	function shadowbox(pHeaderOne,pHeaderTwo,pImage,pCapacity,pContactEmial){
			var content = '<table width="530" border="0" cellpadding="0" cellspacing="0" id="tableProductList"><tr><td colspan="3" valign="top"><div id="headerProductPopup"><div class="pheader_one">'+pHeaderOne+'</div><div class="pheader_two">'+pHeaderTwo+'</div></div></td></tr><tr><td colspan="2" rowspan="3" valign="top"><div class="imgProduct"><img src="'+pImage+'"/ width="270" height="181" ></div></td><td width="259" valign="top"><div class="capacity"><span>Capacity</span><br/>'+pCapacity+'</div></td></tr><tr><td valign="top"><div class="contactProduct"><span>ติดต่อฝ่าย Distribution</span><br /><a href="mailto:'+pContactEmial+'">'+pContactEmial+'</a></div></td></tr><tr><td>&nbsp;</td></tr></table>';
			Shadowbox.open({
				content:    content,
				player:     "html",
				height:     360,
				width:      570
			});

	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
