(function($){
	$.fn.extend({
	        Scroll:function(opt,callback){
	                //参数初始化
	                if(!opt) var opt={};
	                var _btnUp = $("#"+ opt.up);//Shawphy:向上按钮
	                var _btnDown = $("#"+ opt.down);//Shawphy:向下按钮
	                var timerID;
	                var _this=this.eq(0).find("ul:first");
	                var     lineH=_this.find("li:first").height(), //获取行高
	                        line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
	                        speed=opt.speed?parseInt(opt.speed,10):500; //卷动速度，数值越大，速度越慢（毫秒）
	                        timer=opt.timer; //?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）
	                if(line==0) line=1;
	                var upHeight=0-line*lineH;
	                //滚动函数
	                var scrollUp=function(){
	                        _btnUp.unbind("click",scrollUp); //Shawphy:取消向上按钮的函数绑定
	                        _this.animate({
	                                marginTop:upHeight
	                        },speed,function(){
	                                for(i=1;i<=line;i++){
	                                        _this.find("li:first").appendTo(_this);
	                                }
	                                _this.css({marginTop:0});
	                                _btnUp.bind("click",scrollUp); //Shawphy:绑定向上按钮的点击事件
	                        });
	                }
	                //Shawphy:向下翻页函数
	                var scrollDown=function(){
	                        _btnDown.unbind("click",scrollDown);
	                        for(i=1;i<=line;i++){
	                                _this.find("li:last").show().prependTo(_this);
	                        }
	                        _this.css({marginTop:upHeight});
	                        _this.animate({
	                                marginTop:0
	                        },speed,function(){
	                                _btnDown.bind("click",scrollDown);
	                        });
	                }
	               //Shawphy:自动播放
	                var autoPlay = function(){
	                        if(timer)timerID = window.setInterval(scrollUp,timer);
	                };
	                var autoStop = function(){
	                        if(timer)window.clearInterval(timerID);
	                };
	                 //鼠标事件绑定
	                _this.hover(autoStop,autoPlay).mouseout();
	                _btnUp.css("cursor","pointer").click( scrollUp ).hover(autoStop,autoPlay);//Shawphy:向上向下鼠标事件绑定
	                _btnDown.css("cursor","pointer").click( scrollDown ).hover(autoStop,autoPlay);

	        }       
	});
})(jQuery);


function resizeimg(ImgD,iwidth,iheight) { 
	var image=new Image(); 
	image.src=ImgD.src; 
	if(image.width>0 && image.height>0){ 
		if(image.width/image.height>= iwidth/iheight){ 
			if(image.width>iwidth){
			ImgD.width=iwidth; 
			ImgD.height=(image.height*iwidth)/image.width; 
			}else{
			ImgD.width=image.width; 
			ImgD.height=image.height; 
			} 
			ImgD.alt=image.width+"×"+image.height; 
		} 
		else{ 
			if(image.height>iheight){ 
				ImgD.height=iheight; 
				ImgD.width=(image.width*iheight)/image.height; 
			}else{ 
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height; 
		}
		ImgD.style.marginTop=(iheight-ImgD.height)/2 + 'px';
		ImgD.style.marginLeft=(iwidth-ImgD.width)/2 + 'px';
		//ImgD.style.cursor= "pointer"; //改变鼠标指针 
		//ImgD.onclick = function() { window.open(this.src);}//点击打开大图片 
//		if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器，如果是IE 
//			ImgD.title = "请使用鼠标滚轮缩放图片，点击图片可在新窗口打开"; 
//			ImgD.onmousewheel = function img_zoom() //滚轮缩放 
//			{
//				var zoom = parseInt(this.style.zoom, 10) || 100; 
//				zoom += event.wheelDelta / 12; 
//				if (zoom> 0)this.style.zoom = zoom + "%"; 
//					return false; 
//			 }
//		 } else { //如果不是IE 
//			ImgD.title = "点击图片可在新窗口打开"; 
//		} 
	}
}

/*
计算时间差
*/

Date.prototype.diff=function (date)
{

	var y=date-this,x=Math.abs(y),d,h,m,s;

	d=parseInt(x/86400000);
	x%=86400000;
	h=parseInt(x/3600000)
	x%=3600000;
	m=parseInt(x/60000);
	x%=60000;
	s=parseInt(x/1000);

	return {
		text:(d+'天0'+h+'小时0'+m+'分0'+s+'秒').replace(/0(\d\d)/g,'$1')
		,value:y
	};

}

/*
计时器类
*/

timer=function (from,shower)
{

	var T=document.getElementById(from).value;
	T=new Date(T.replace(/-/g,'/'));
	var P=document.getElementById(shower);
	(function ()
	{
		var diff=new Date().diff(T);
		if(diff.value<0){
			P.innerHTML="<span class=\"dkblueText tb\">已经结束</span>";
			//return //alert('end!')
		}
		else{
			P.innerHTML=diff.text;
		}
		setTimeout(arguments.callee,1000);
	})();
};

function showInfo(infostr,nexturl){
	//document.write('<div id="sysInfoDialog" class="dialogCtn" title="系统提示">'+infostr+'</div>');
	var d=document.createElement("div") ; // 创建对象，下面就是设置属性了
	d.id="sysInfoDialog";
	d.title="系统提示";
	document.body.appendChild(d);
	$("#sysInfoDialog").html(infostr);
		
	$("#sysInfoDialog").dialog({
		height: 200,
		width:400,
		bgiframe: true,
		modal: true,
		autoOpen: false,
		resizable: false,
		buttons:{
			'确认':function(){
				$(this).dialog('close');
				if (nexturl!='')
					window.location.href=nexturl;
			}
		}
	});
	$("#sysInfoDialog").dialog('open');
}

$(document).ready(function(){
	//数量输入框基础校验
	$(".numericInput").keydown(function(event){
		if(!(event.keyCode==46)&&!(event.keyCode==8)&&!(event.keyCode==9)&&!(event.keyCode==37)&&!(event.keyCode==39))
			if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))
			 return false;
	});
	//金额输入框基础校验
	$(".moneyInput").keydown(function(event){
		if(!((event.keyCode>=   48&&event.keyCode   <=   57)||(event.keyCode==9)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)||(event.keyCode   ==   110)||(event.keyCode   ==   190)||(event.keyCode   ==   0xD)))
			return false;
		string=this.value;
		var strlength = string.length;
		var dotindex = string.indexOf('.');
		if(dotindex!=-1)
		{
			var afterdotstring = string.substring(dotindex+1,strlength);
			if (afterdotstring.length>=2){
				this.value=string.substring(0,dotindex+3);
			}
		}
		if(dotindex==0){
			this.value='';
		}
	}).blur(function(event){
		string=this.value;
		var strlength = string.length;
		var dotindex = string.indexOf('.');
		if(dotindex!=-1)
		{
			var afterdotstring = string.substring(dotindex+1,strlength);
			if (afterdotstring.length>=2){
				this.value=string.substring(0,dotindex+3);
			}
		}
		if(dotindex==0){
			this.value='';
		}
	});
	$(".titleInput").keydown(function(event){
//		if(event.keyCode==32)
//			return false;
	});
	$('#searchValue').click(function(){
		if ($('#searchValue').attr('value')=='请输入查询关键字'){
			$('#searchValue').attr('value','');
		}
	});
	$('#searchValue').blur(function(){
		if ($('#searchValue').attr('value')==''){
			$('#searchValue').attr('value','请输入查询关键字');
		}
	});
	$(".QQTalk").each(function(key, val) {
		$(this).html('<img class=\"QQImg\" border=\"0\" src=\"http://wpa.qq.com/pa?p=1:'+$(this).attr('qqid')+':1\" alt=\"请先添加好友\">');
		$(this).click(function(){window.location.href='tencent://message/?Menu=yes&uin='+$(this).attr('qqid')+'&Site=汉正街电子商务平台&Service=200&sigT=2a0e37386280486ada2b5d5e69ee49186ccae1257fd9e1c9598af1f0b9c916067002a57aaaec8c8d';});
	});
	$(".flashWord").each(function(key, val) {
		id=$(this).attr("id");
		setInterval("flashWord('"+id+"')",500);
	});
	$(".hotProductListCtn .saleProduct").each(function(key, val) {
		$(this).attr("width",'173');
		$(this).attr("height",'173');
	});
	$(".page").mouseover(function() {
		$(this).addClass("pageBg");
	});
	$(".page").mouseout(function() {
		$(this).removeClass("pageBg");
	});

});
function flashWord(obj){
	if($("#"+obj).hasClass("goldText"))
		$("#"+obj).removeClass("goldText");
	else
		$("#"+obj).addClass("goldText");
}
/**
 * 配置前台推荐品牌
 * @return
 */
function showbrand(){
	$.ajax( {
		type : 'post',
		url : '/brand/brand',
		dataType : 'json',
		data : "id=" + '' + "&order=" + '',
//		error : function() {
//			alert('系统错误，请稍后重试或与管理员联系！');
//		},
		success : function(json) {
			var html = '';
			var count = 0;
			$.each(json.resultdata,function(entryIndex, entry) {
					if(count == 4 || count == 7){
						html +='<div class="photoBoxbrand" style="float: left;"><a href="/brand/showdetail/brandid/'+entry['id']+'"><img src="'+ entry['logopath'] +'"/></a></div>';
					}else{
						html +='<div class="photoBoxbrand" style="float: left;"><a href="/brand/showdetail/brandid/'+entry['id']+'"><img src="'+ entry['logopath'] +'"/></a></div>';
					}
				count++;
			});	
			$("#brands").html(html);
			photobrand();
		}
	});
}

function photobrand(){
	$(".photoBoxbrand img").each(function(){
		resizeimg(this,98,40);
	});
}