$(document).ready(function(){
	// subNaviation
	if ($('#subNavigation').html() != "")
		subNavigation_init();	
	
	sukienGS_init();	
	drhuou_init();
	
	
	$('.fq_item:not(:first)').hide();
	
	$('.featureImg:not(:first)').hide();
	$('.paginate span').click(function(){
		$('.paginate span').removeClass('active');
		$(this).addClass('active');
									   
		$('.overlay_top').slideUp('fast');
		$('.overlay_bottom').hide();
		var chooseNode = $(this).text();
		chooseNode = parseInt(chooseNode) - 1;
		var i = parseInt(chooseNode);
		var y = i-1;
	
		$('.featureImg').fadeOut('slow');
		$('.featureImg:eq('+i+')').fadeIn('slow', function(){
			$('.overlay_top').slideDown('fast');
			$('.overlay_bottom').show();
		});	
	});
});


/* TAB CONTROL @HOMEPAGE */
function changeTab(obj, num){
	var curentTab=obj.id;
	var curentContent=curentTab.replace("tab","cont");

	var tabs=$('#' + curentTab).parent().children();
	var contents=$('#' + curentContent).parent().children();

	$(tabs).each( function(){								
		$(this).removeClass('active');
	});		
	
	$(contents).each( function(){								
		$(this).hide();
	});	
	
	$('#' + curentTab).addClass('active');
	$('#' + curentContent).show();
	
	/* remove divide between 2 tab header item */
	$(tabs).children().removeClass('not-divide');
	$('#' + curentTab).prev().children().addClass('not-divide');
}


/* SUKIEN GS */
var sukienGS_temp = 0;
var sukienGS_quote = new Array;
function sukienGS_init(){	
	if (($('.home-skgd').html() != '') && (sukienGS_quote)){
		if (sukienGS_temp > sukienGS_quote.length - 1) sukienGS_temp=0;
		$('#sukienGS').html(sukienGS_quote[sukienGS_temp]);
	}
	sukienGS_temp ++;
	var sukienGS_autoPlay = setTimeout("sukienGS_init()", 5000);
}


/* DR HUOU */
var timeDelay = 5000;
var fq_temp = 0;
function drhuou_init(){	
	$('.fq_item').hide();
	$('.fq_item:eq('+fq_temp+')').show();
	$('.paginate span').removeClass('active');
	$('.paginate span:eq('+fq_temp+')').addClass('active');
	
	fq_temp +=1;
	var item_length = $('.fq_item').length;
	if (fq_temp == item_length) {fq_temp=0;}
	
	var fq_drhuou = setTimeout("drhuou_init()", timeDelay);
	
	$('.paginate span').click(function(){
		var currentItem = parseInt($(this).html()) - 1;
		$('.fq_item').hide();
		$('.fq_item:eq('+currentItem+')').show();
		$('.paginate span').removeClass('active');
		$('.paginate span:eq('+currentItem+')').addClass('active');
		clearTimeout(fq_drhuou);
	});
}


/* Sub Navigation */
function subNavigation_init(){
	$('#navigation a.selected').parent().addClass('active');	
	$('#navigation img').parent().parent().hover(
		function () {
			$('#navigation .selected').removeClass('selected').addClass('unSelected');
			$('.active ul').addClass('unSelected_ul');
			//OMI - 13/08/2009 update - Disable this line
			//$('.active').removeClass('active');
			
			$('.unSelected_ul').hide();
			
			$(this).addClass('selected_li');
			$('.selected_li img').parent().addClass('selected');
			$('.selected_li ul:first').show();
		}, 
		function () {
			$('.selected_li a').removeClass('selected');
			$('#navigation .unSelected').removeClass('unSelected').addClass('selected');
			
			//OMI - 13/08/2009 update - Disable this line
			//$('.unSelected_ul').show();
			
			//OMI - 13/08/2009 update - Add this line
			$('.selected_li ul').hide();
			
			//OMI - 13/08/2009 update - Add this line
			$('.unSelected_ul').show();
			//OMI - 13/08/2009 update - Disable this line
			//$('.selected_li ul').hide();			
			$('.selected_li').removeClass('selected_li');
		}
    );
}