var errorMsgEn="Fields marked with star keys * are compulsory.";
var errorMsgCn="请正确填写带*号栏目，谢谢！";
var successMsgCn="发送成功！我们将在1个工作日内与您联系。";
var successMsgEn="Submit successfully! We'll contact you within 24 hours.";


$(function(){
		   
		 $(document).bind("contextmenu", function() { return false; });
		   
		$("a").bind("focus",function(){
            if(this.blur){ 
                this.blur(); 
             }
        });
		
		easyTab($(".leftColumn"));
		
		 $("#letter").focus(function(){ 
        	 if ($(this).val() == $(this).attr('title')) {
 	  			$(this).val("");
				}
		}).blur(function(){ 
			if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
			}
	})
		$(".newsletter .button").click(function(){
			mail = $("#letter").val();
			if(emailCheck(mail)){
				url = "newsletter.php?action=save&email="+mail;
				$.get(url, function(data){
					$("#letter").val($("#letter").attr('title'));
					alert(data);
				});
			}else{
				$("#letter").val("please enter a email");
			}
			})
		
		$(".history li").hover(function(){
			$(this).addClass("over");
			$(this).find(".remove").show();
		},function(){
			$(this).removeClass("over");
			$(this).find(".remove").hide();
			})
	  	$(".history li .remove").click(function(){
			var id = $(this).parent().attr("id").replace("history","");
			$(this).parent().fadeOut(700,function(){$(this).remove()});
			$.get("modifyCookie.php?id="+id,function(data){
				
				})
			})
		
		$("#printthispage").click(function(){
			window.print();		   
		 });
		
		$('#sendtofrineds').openDOMWindow({
			windowSourceID:'#sendmail',
			height:287, 
			width:502, 
			eventType:'click', 
			overlayOpacity:0,
			borderSize:0,
			windowBGColor:'#f2f2e5',
			windowPadding:9,
			functionCallOnClose:resetSendmailForm
		})
		resetSendmailForm();
		
		
		var Sendmailoptions = { 
			beforeSubmit:  showRequestSendmail,  // pre-submit callback 
			success:       showResponseSendmail  // post-submit callback 
    	}; 
		$('#sendtofriends-form').ajaxForm(Sendmailoptions); 
		
		setInterval( "slideSwitch()", 6000 );
		
		//$(document).bind("contextmenu",function(){return false;});
    	//$(document).bind("selectstart",function(){return false;}); 
    	//$(document).keydown(function(){return key(arguments[0])}); 
		
		$('.hoverItem').hover(function(){
			$(this).animate({
						      top: "-200px"
						    },{duration: 300, easing:"easeOutExpo",queue:false});
			
			$(this).find(".imgout").animate({
						      opacity: 0
						    },{duration: 300,queue:false});
			},function(){
			$(this).animate({
						      top: "-60px"
						    }, {duration: 300, easing:"easeOutExpo",queue:false});
			
			$(this).find(".imgout").animate({
						      opacity: 1
						    },{duration: 300,queue:false});
		})
		
		
		

});


function getCurrentBed(){
	
}
function resetSendmailForm(){
	$("#sendtofriends-form li.button div.loading").hide();
	$("#sendtofriends-form li.button input").attr("disabled","");
}


// pre-submit callback 
function showRequestSendmail(formData, jqForm, options) { 
   	var form = jqForm[0]; 
	if (!emailCheck(form.urmail.value)) { 
        alert('Please enter a valid email address.');
		form.urmail.focus();
        return false; 
    } 
	if (!emailCheck(form.urfriendsmail.value)) { 
        alert('Please enter a valid email address.'); 
		form.urfriendsmail.focus();
        return false; 
    }
  
  
	$("#sendtofriends-form li.button div.loading").show();
	$("#sendtofriends-form li.button input").attr("disabled","disabled");
	
    return true; 
} 
 
// post-submit callback 
function showResponseSendmail(responseText, statusText)  { 
   
	resetSendmailForm();
	
	 if(statusText =="success"){
		 if(responseText.indexOf("success")>-1){
			alert('Submit successfully!');	
		 	$('#sendtofrineds').closeDOMWindow();
		 }else{
			alert(responseText);	 
		}
	  }else{
		  alert(statusText);
     }
} 

function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1500, function() {
            $active.removeClass('active last-active');
        });
}


  
  function easyTab($tab){
						var tabContainers = $tab.find('.tabs > div');
                        tabContainers.hide().filter(':first').show();
                         $tab.find('.tabs ul.tabNavigation a').click(function () {
							 	if($(this).hasClass('selected')){
									return false;
								}
                                tabContainers.hide();
                                tabContainers.filter(this.hash).fadeIn();;
                                $tab.find('.tabs ul.tabNavigation a').removeClass('selected');
                                $(this).addClass('selected');
                                return false;
                        }).filter(':first').click();
}








