var mainFlashIndex = 0;
var mainFlashMax   = 0;


function getMainFlash(index){
  	
  $('.main_flash').hide();
  
  if($.browser.msie){
	$('.mainFlash').html($('.main_flash').eq(index).html());
  }
  /*
  if(index == 0)
  {
    $('.mainFlash').css('cursor','pointer');  
    $('.mainFlash').click(function(){
      window.location ="/โปรโมชั่น/";
    });
  }
  else if(index == 1)
  {
    $('.mainFlash').css('cursor','none');  
    $('.mainFlash').click(function(){
      window.location ="/โปรโมชั่น/";
    });
  }
  else if(index == 2)
  {
    $('.mainFlash').css('cursor','none');  
  }
  */
  
  $('.mainFlash').css('cursor','none');
  
	if($.browser.mozilla){
		$('.main_flash').eq(index).show();
	}
	else if ( $.browser.webkit && !$.browser.opera && !$.browser.msie && !$.browser.mozilla ) {
		var userAgent = navigator.userAgent.toLowerCase();
		if ( userAgent.indexOf("chrome") != -1 ) {
			$('.main_flash').eq(index).show();
		}
	}

  
  $('#main_flash_nav li').css('color','#FFFFFF');
  $('#main_flash_nav li').eq(index).css('color','#BE1E1E');
  (mainFlashMax==index)?mainFlashIndex=0:mainFlashIndex++;

  //timer = setTimeout("getMainFlash(mainFlashIndex);",5000);
  
  if(index == 0)
  {
    timer = setTimeout("getMainFlash(mainFlashIndex);",30000);
  }
  else if(index == 1)
  {
    timer = setTimeout("getMainFlash(mainFlashIndex);",30000);
  }
  else if(index == 2)
  {
    timer = setTimeout("getMainFlash(mainFlashIndex);",30000); 
  }  
  
}




$(document).ready(function() {
  mainFlashMax = $('.main_flash').length - 1;
  getMainFlash(mainFlashIndex);
	
   $('#main_flash_nav li').click(function(){
      clearTimeout(timer);
      mainFlashIndex=parseInt($(this).html())-1;
      getMainFlash(mainFlashIndex);
   });
   
   
   $('.btLogin').click(function(){
    alert('ระบบสมาชิกจะเปิดใช้งานเร็วๆนี้');
   });
   
   $('.btContact').click(function(){
      var contact_name = $('#contact_name').attr('value');
      var contact_tel = $('#contact_tel').attr('value');
      var contact_title =  $('#contact_title').attr('value');
      var contact_detail =  $('#contact_detail').attr('value');
      $.ajax({
      type: "POST",
      url: "/contact.php",
      data: {"contact_name":contact_name,"contact_tel":contact_tel,"contact_title":contact_title,"contact_detail":contact_detail},
      success: function(data){
         if(data == "1")
         {
           $('.contact .contactBtBox').remove();
           $('.contactBox').css('background','none');
           $('.contactBox').html('<img src="/bg_contact_thank.jpg" border"0">');
         }
         else
         {
           $('.contact .contactBtBox').remove();
           $('.contactBox').css('background','none');
           $('.contactBox').html('<h1 class="red">ระบบมีปัญหา กรุณาติดต่อ 088-400-8001 ถึง 7</h1>');
          
         }
        }
      }); 
   });

   
});



