// 	Cufon
try {
	Cufon.set('selector', jQuery);
	Cufon.replace('.replace-font', { fontFamily: 'PSLxEmpireExtra' });
	Cufon.replace('.replace-subheader', { fontFamily: 'PSLxDisplay' });
	Cufon.replace('#main-navigation>ul>li>a', {hover: true});
} catch (e) {}
var tmpIDName = '';
var tmpActiveName = '';
var globalIssetMapEarthquake = false;
// JavaScript Document
$(document).ready(function(){

	//init
	 $('.toggle-navigation .tab1').addClass('active');
	 $('.tab1-detail').addClass('active');
	 $.getScript("/js/base.js", function(){ dropDownMenu('');});
	 $.getScript("/js/featuredcontentglider.js");
	$(".dropdown-navigation").hover(
		function () {
		  $(this).children().show();
		  $(this).addClass('show');
		},
		function () {
		  $(".dropdown-navigation ul").hide();
		  $(this).removeClass('show');
		}
	  );

	// Toggle-navigation-global
    $('.toggle-navigation .tab1').click(function() {
		$(this).parent().children('.tab2').removeClass('active');
		$(this).parent().children('.tab3').removeClass('active');
		$(this).parent().children('.tab4').removeClass('active');
		$(this).parent().children('.tab5').removeClass('active');
		$(this).parent().next().children('.tab2-detail').removeClass('active');
		$(this).parent().next().children('.tab3-detail').removeClass('active');
		$(this).parent().next().children('.tab4-detail').removeClass('active');
		$(this).parent().next().children('.tab5-detail').removeClass('active');
		$(this).addClass('active');
		$(this).parent().next().children('.tab1-detail').addClass('active');
    });

    $('.toggle-navigation .tab2').click(function() {
		$(this).parent().children('.tab1').removeClass('active');
		$(this).parent().children('.tab3').removeClass('active');
		$(this).parent().children('.tab4').removeClass('active');
		$(this).parent().children('.tab5').removeClass('active');
		$(this).parent().next().children('.tab1-detail').removeClass('active');
		$(this).parent().next().children('.tab3-detail').removeClass('active');
		$(this).parent().next().children('.tab4-detail').removeClass('active');
		$(this).parent().next().children('.tab5-detail').removeClass('active');
		$(this).addClass('active');
		$(this).parent().next().children('.tab2-detail').addClass('active');
    });

    $('.toggle-navigation .tab3').click(function() {
		$(this).parent().children('.tab2').removeClass('active');
		$(this).parent().children('.tab1').removeClass('active');
		$(this).parent().children('.tab4').removeClass('active');
		$(this).parent().children('.tab5').removeClass('active');
		$(this).parent().next().children('.tab2-detail').removeClass('active');
		$(this).parent().next().children('.tab1-detail').removeClass('active');
		$(this).parent().next().children('.tab4-detail').removeClass('active');
		$(this).parent().next().children('.tab5-detail').removeClass('active');
		$(this).addClass('active');
		$(this).parent().next().children('.tab3-detail').addClass('active');
		if (!globalIssetMapEarthquake) {
			initializeMapEarthquake();
			globalIssetMapEarthquake = true;
		}
    });

    $('.toggle-navigation .tab4').click(function() {
		$(this).parent().children('.tab2').removeClass('active');
		$(this).parent().children('.tab3').removeClass('active');
		$(this).parent().children('.tab1').removeClass('active');
		$(this).parent().children('.tab5').removeClass('active');
		$(this).parent().next().children('.tab2-detail').removeClass('active');
		$(this).parent().next().children('.tab3-detail').removeClass('active');
		$(this).parent().next().children('.tab1-detail').removeClass('active');
		$(this).parent().next().children('.tab5-detail').removeClass('active');
		$(this).addClass('active');
		$(this).parent().next().children('.tab4-detail').addClass('active');
    });

     $('.toggle-navigation .tab5').click(function() {
		$(this).parent().children('.tab2').removeClass('active');
		$(this).parent().children('.tab3').removeClass('active');
		$(this).parent().children('.tab1').removeClass('active');
		$(this).parent().children('.tab4').removeClass('active');
		$(this).parent().next().children('.tab4-detail').removeClass('active');
		$(this).parent().next().children('.tab2-detail').removeClass('active');
		$(this).parent().next().children('.tab3-detail').removeClass('active');
		$(this).parent().next().children('.tab1-detail').removeClass('active');
		$(this).addClass('active');
		$(this).parent().next().children('.tab5-detail').addClass('active');
    });

	//Select search type
	$("#search-box #textsearch").focus(function() {
		$(".search-type").show();
		$(this).addClass("active");
    });
    $("#search-box .close a").click(function() {
		$(".search-type").hide();
    });


	 $("#reloadCapha").click(function(){$("#validate_img").attr({src: "/images/captcha.png?"+Math.random()});})
	 $("#validate_img").click(function(){$(this).attr({src: "/images/captcha.png?"+Math.random()});})
	// $("#economic div.thirdPartyInfo ,#business div.thirdPartyInfo").html('<iframe width="200px" height="194px" frameborder="0" scrolling="no" src="http://weblink.settrade.com/banner/banner3.jsp"></iframe>');


	//$('.exchange-rate .toggle-navigation .tab4').click();
 });

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

function decode(encoded){
	return decodeURIComponent(encoded.replace(/\+/g,  " "));
}

function getTruehitsName(default_name){
	var this_url = parseUri(window.location.href+'');
	var page = '';

	var paths = decode(this_url['directory']).split('/');
	var paths_length = paths.length - 2;
	if(paths_length > 0){
		if(paths_length >= 1){
			page = paths[1];
			if(paths[2] != '' && isNaN(paths[2])) page = page +'_'+paths[2];
		}else{
			page = paths[1];
		}
	}else{
		page = paths[1] || this_url['file'];
	}

	if(page == '') page = default_name || 'homepage';

	return page;
}

function chkIsArchiveSearch (val) {
	if (val == 1) {
		if ($('#textsearch').val() == 'ค้นหาข่าว') {
			$('#textsearch').val('');
		}
		$('#search-box').attr('action' , '/archive/search');
	} else {
		if ($('#textsearch').val() == 'ค้นหาข่าว') {
			$('#textsearch').val('');
		}
		$('#search-box').attr('action' , '/web-search');
	}
}
