// JavaScript Document

/**************** 初始化 *******************/

 var hasuser =  true;
var hasmail =  true;
$(document).ready(function() {
	var galleries = $('.ad-gallery').adGallery();
	$(".buyButton").hover(function(){
			$(this).find(".bt").animate({left:'43px'},100);
			$(this).find(".t1").css('color','#FFF');
			$(this).find(".t2").css('color','#728a00');
		},function(){
			$(this).find(".bt").animate({left:'1px'},100);
			$(this).find(".t2").css('color','#FFF');
			$(this).find(".t1").css('color','#728a00');
		});
	$(".details").fancybox({
		'titlePosition'	: 'inside',
		'padding' : '25',
		'overlayColor' : '#ffffff',
		'overlayOpacity': 0,
		'centerOnScroll':true,
                'scrolling':"no",
		ajax : {
		    type	: "GET"
		}
	});
        
        $(".exchange").click(function(){
            var points = $(this).attr("rel");
            var url = $(this).attr("href");
            var userPoints = $(".cpoints").html();
              if(userPoints - points >= 0){
                  var a = confirm("本操作将消耗您的"+points+"点积分，要继续么？");
                  if (!a) return false;
                  $.get(url, function(data) {
                      $(".cpoints").html(data);
                      alert("兑换成功，请耐心等待我们联系您！");
                    });                  
              }else{
                  alert("抱歉您没有足够的积分来兑换本礼品！")
              }            
            return false;
        })
	
	$(".listCon h4").click(function(){
		$current = $(this).find(".switch");
		if($current.hasClass("switchoff")){
			$current.removeClass("switchoff").addClass("switchon");
			$(this).parent().find("ul").slideUp(500,"easeOutExpo",function(){
				
				});
		}else{
			$current.removeClass("switchon").addClass("switchoff");
			$(this).parent().find("ul").slideDown(500,"easeOutExpo",function(){
				
				});
		}
			
		});
		
		showSideMenu();
		showShopList();
               
        
        $("input#user_login").change(function(){
        $.get('user.php?act=check&user='+$("input#user_login").val(), function(data) {
          if(data == "0"){
              hasuser = true;
          }else{
              hasuser = false;
          }
        });
        })
        $("input#email").change(function(){
        $.get('user.php?act=check&mail='+$("input#email").val(), function(data) {
          if(data == "0"){
              hasmail = true;
          }else{
              hasmail = false;
          }
          //alert(hasmail)
        });
        })
                
});

function showSideMenu(){
	$(".listCon h4").each(function(index) {
		$current = $(this).find(".switch");
		if( $current.hasClass("switchon")){
			 $current.removeClass("switchon").addClass("switchoff");
			 $(this).parent().find("ul").delay(700*index).slideDown(700,"easeOutExpo");
		}
  	});
}

function showShopList(){
	$(".shoplist li").hide();
	$(".wp-pagenavi").hide().delay(100*$(".shoplist li").length).fadeIn(500,"swing");
	$(".shoplist li").each(function(index) {
		$(this).delay(100*index).fadeIn(500,"swing");
	});
	
}

function highlightAbout(){
	$('#nav li:first').addClass('current-post-ancestor');
}


function checkUser(){
    str = $("input#user_login").val();
    if(str==""){
        alert("请填写昵称");
        $("input#user_login").select();
        return false;
    }else if(hasuser){
        alert("用户名已被注册");
        $("input#user_login").select();
        return false;
    }else{
         return true;
    }
}


function checkPhone(){
    str = $("input#tel").val();
    if(str==""){
        alert("请填写联系电话");
        $("input#tel").select();
        return false;
    }else{
        return true;
    }
}

function checkName(){
    str = $("input#nickname").val();
    if(str==""){
        alert("请填写真实姓名");
        $("input#nickname").select();
        return false;
    }else{
        return true;
    }
}
function checkCity(){
    str = $("input#city").val();
    if(str==""){
        alert("请填写城市");
        $("input#city").select();
        return false;
    }else{
        return true;
    }
}

function checkAddress(){
    str = $("input#address").val();
    if(str==""){
        alert("请填写详细地址");
        $("input#address").select();
        return false;
    }else{
        return true;
    }
}

function checkZip(){
    str = $("input#zipcode").val();
    if(str==""){
        alert("请填写邮政编码");
        $("input#zipcode").select();
        return false;
    }else{
        return true;
    }
}

function emailCheck(){
        email = $("input#email").val();
	if ((email.length > 128) || (email.length < 6)){
                alert("请填写正确的邮件地址");
                 $("input#email").select();
		return false;
	}

	var format = /^[A-Za-z0-9+]+[A-Za-z0-9\.\_\-+]*@([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+$/;

	if (!(format).test(email)) {
                 alert("请填写正确的邮件地址");
                 $("input#email").select();
		 return false;
	}

        if(hasmail){
            alert("邮箱已被注册");
            $("input#email").select();
            return false;
        }
 	return true;
}


function checkPass(){
    pass = $("input#pass1").val();
	if ((pass.length > 20) || (pass.length < 6)){
                alert("密码必须大于等于6位小于20位");
                 $("input#pass1").select();
		return false;
	}
        return true;
}

function checkrePass(){
    pass = $("input#pass1").val();
    pass1 = $("input#pass2").val();
    if (pass != pass1){
                alert("两次输入的密码不一致");
                 $("input#pass2").select();
		return false;
	}
        return true;
}



(function($){
 $.fn.extend({
 
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);







