/* return fullpath with lang */
function base_url()
{
	var hostName = document.location.hostname;
	var pathName = document.location.pathname;
	
	// get lang
	var temp = pathName.split('/');
	return 'http://' + hostName + '/' + temp[1] + '/';
}

function getLang()
{
	var pathName = window.location.pathname;
	return pathName.substr(1, 2);
}

function changeLang(lang)
{
	var hostName = document.location.hostname;
	var pathName = window.location.pathname;
	var attrVal = window.location.search;
	var realPath = pathName.substr(4, pathName.length-1);
	
	window.location = 'http://' + hostName + '/' + lang + '/' + realPath + attrVal;
}
function popWin(url,w,h) {
	var winl=(screen.width-w) / 2;
	var wint=(screen.height-h) / 2;
	var newWindow
	newWindow = window.open(url,"nWin","scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,directories=no,resizable=yes,width="+w+",height="+h+",top="+wint+",left="+winl+"")
}

function setNav()
{
	var pathName = window.location.pathname;
	var realPath = pathName.substr(4, pathName.length-1);
	
	$('#page-navigate a').css({opacity: 0});
	
	switch(realPath){
		case 'home.php':
			break;
		case 'investor.php':
			$('#page-navigate a').eq(1).addClass('active').css({opacity: 1});
			break;
		case 'product.php':
			$('#page-navigate a').eq(2).addClass('active').css({opacity: 1});
			break;
		case 'news.php':
		case 'news_detail.php':
			$('#page-navigate a').eq(3).addClass('active').css({opacity: 1});
			break;
		case 'dish.php':
		case 'dish_detail.php':
			$('#page-navigate a').eq(4).addClass('active').css({opacity: 1});
			break;
		case 'job.php':
			$('#page-navigate a').eq(5).addClass('active').css({opacity: 1});
			break;
		case 'aboutus.php':
			$('#page-navigate a').eq(0).addClass('active').css({opacity: 1});
			break;
	}
}

jQuery.fn.extend({
	embedSWF: function(settings , pluginOptions ){
			var o = jQuery.extend({ expressInstall:"js/swfobject/expressInstall.swf",version:'8.0.0'}, settings);
			if(swfobject.flagSwitchOff){
				swfobject.switchOffAutoHideShow();
				swfobject.flagSwitchOff = false;
			}
			for(var key in o.flashvars) o.flashvars[key] = encodeURIComponent(o.flashvars[key]);
			
			return this.each(function() {
				
				var swfId = this.id||("swfobject_"+Math.round(Math.random()* 1000));
				var swfName = this.name||swfId;
				var swfWidth = o.width||$(this).width();
				var swfHeight = o.height||$(this).height();
				swfobject.embedSWF(o.src, swfId, swfWidth, swfHeight, o.version,o.expressInstall ,o.flashvars,$.extend({wmode:o.wmode||"opaque"},o.params));
			});
		}
});

function contactForm_Default(name,valueshow){
	var show_txt = $(name).val();
	if(show_txt == ""){
		$(name).val(valueshow);
	}
	$(name).click(function(){
		var show_set = $(name).val();
		if(show_set == valueshow){
			$(name).val("");
		}
	});
	$(name).blur(function(){
		var show_set = $(name).val();
		if(show_set == ""){
			$(name).val(valueshow);
		}
	});
}

function contactForm_Check(lang){
	if(lang == "th"){
		var word_show = {name:"ชื่อ-สกุล*",email:"อีเมล์*",detail:"ความคิดเห็น*"}
		var response_show = {title:"กรุณากรอก \n",name:"- ชื่อ-สกุล\n",email:"- อีเมล์\n",emailvalid:"- รูปแบบอีเมลล์  ไม่ถูกต้อง \n",detail:"- ความคิดเห็น\n"}
	}else{
		var word_show = {name:"Name-Lastname*",email:"Email Address*",detail:"Comment here*"}
		var response_show = {title:"Please Enter \n",name:"- Name-Lastname\n",email:"- Email\n",emailvalid:"- Email must be a valid e-mail\n",detail:"- Detail\n"}
	}
	
	
	var name = $("#contactName").val();
	var emailaddress = $("#emailAddress").val();
	var detail = $("#contactDetail").val();
	var pattern=/^((\s)*([0-9a-z]+[-._+&])*[0-9a-z]+@[a-z][a-z0-9\_\-]*(\.[a-z][a-z0-9\_\-]*)+(,)?(\s)*)+$/i;
	var str = "";
	
	if(name == "" || name == word_show["name"]){
		str += response_show["name"];
	}
	if(emailaddress == "" || emailaddress == word_show["email"]){
		str += response_show["email"];
	}else{
		if(!pattern.test(emailaddress)){
			str += response_show["emailvalid"];
		}
	}
	if(detail == "" || detail == word_show["detail"]){
		str += response_show["detail"];
	}
	if(str != ""){
		alert(response_show["title"] + str);
		return false;
	}else{
		return true;
	}
}

$(document).ready(function(){
	
	//if(jQuery.browser.safari){
	//	//$(".page-content").css("background-position","51px 3px");
	//}else if($.browser.msie){
	//	if($.browser.version==8){
	//		$(".page-content").css("background-position","57px 9px ");
	//	}
	//}
	
	// sifr
	// -----------------------------------------------------------
	var supermarket = {
		// src: 'js/sifr3/font/supermarket.swf'
		src: base_url() + 'js/sifr3/font/supermarket.swf'
		// src: '/supermarket.swf'
	};
	sIFR.activate(supermarket);
	
	sIFR.replace(supermarket, {
		selector: '#news-content h2',
		tuneHeight: -17,
		offsetTop: -5,
		opaque: true,
		css: {
			'.sIFR-root': { 'background-color': '#FFFDFA'}
		}
	});
	
	sIFR.replace(supermarket, {
		selector: '#footer-warp h3',
		wmode: 'transparent',
		tuneHeight: -11,
		offsetTop: -3,
		opaque: true,
		css: {
			'.sIFR-root': { 'color': '#FFFFFF' }
		}
	});
	
	sIFR.replace(supermarket, {
		selector: '#content-header h1',
		tuneHeight: -18,
		offsetTop: -10,
		opaque: true,
		css: {
			'.sIFR-root': { 'color': '#444444', 'font-size': '28px', 'background-color': '#FFFDFA' }
		}
	});
	
	sIFR.replace(supermarket, {
		selector: '#investor-information h2, #document h2, .position-content h2',
		tuneHeight: -11,
		offsetTop: -3,
		opaque: true,
		css: {
			'.sIFR-root': { 'color': '#E1000D', 'background-color': '#FFFDFA' }
		}
	});
	
	sIFR.replace(supermarket, {
		selector: 'h2.title_detail',
		tuneHeight: -11,
		offsetTop: -3,
		opaque: true,
		css: {
			'.sIFR-root': { 'color': '#444444', 'background-color': '#FFFDFA' }
		}
	});
	
	$("#main").css("background-position","left top");
/*	if(typeof sIFR == "function"){
		var font = base_url() + "js/sIFR/supermarket.swf";
		
		// all of h2
		sIFR.replaceElement("#news-content h2", font, "#000000", null, null, null, 0, 0, 0, 0);
		
		// page header
		sIFR.replaceElement("#content-header h1", font, "#000000", null, null, null, 0, 0, 0, 0);
		
		// investor
		sIFR.replaceElement("#investor-information h2", font, "#E1000D", null, null, null, 0, 0, 0, 0);
		sIFR.replaceElement("#document h2", font, "#E1000D", null, null, null, 0, 0, 0, 0);
		
		sIFR.replaceElement("h2.title_detail", font, "#444444", null, null, null, 0, 0, 0, 0);
		sIFR.replaceElement(".comment_left h2", font, "#444444", null, null, null, 0, 0, 0, 0);
		
		sIFR.replaceElement(".content-data h2", font, "#E1000D", null, null, null, 0, 0, 0, 0);
	}; */
});
