
var scroll_num=3;//滚动的栏数
var scroll_count=0;//滚动的次数
var scroll_speed="3000";//滚动速度
var intervalID; 
$(document).ready(function(){
    var list = new ScrollList();
    list.init();
    search_city=$.query.get("city");
    $("#index_nav").addClass('hover');
  //邮件订阅
	$("#email").focus(
    		function()
    		{
    			var content=$.trim($(this).val());
    			if(!check_email(content))
    			{
    				$(this).val('');
    			}
    		});
    $("#email").blur(
    		function()
    		{
    			var content=$.trim($(this).val());
    			if(!content)
    			{
    				$(this).val('输入邮箱');
    				return false;
    			}
    		});
    //
    
    scroll_num=$("#supermarket_banner>ul>li").length;
	if(scroll_num>1)
	{
		scroll_begin();
	}
	$("#supermarket_banner>ul>li").mouseover(
			function ()
			{
				stop_scroll();
				var index=$("#supermarket_banner>ul>li").index(this);
				change_scroll(index);
				scroll_count=index;
			}
	);
	$("#supermarket_banner>ul>li").mouseout(
			function ()
			{
				scroll_begin();
			}
	);
    //
});	

function scroll_begin()
{
	intervalID=setInterval("auto_scroll()",scroll_speed);
}

function scroll_begin()
{
	intervalID=setInterval("auto_scroll()",scroll_speed);
}

//自动切换焦点图内容
function auto_scroll()
{
	scroll_count++;
	var i=scroll_count%scroll_num;
	change_scroll(i);
}

//停止滚动
function stop_scroll()
{
	clearInterval(intervalID);
}

//焦点图滚动替换内容
function change_scroll(i)
{
	var li="#supermarket_banner>ul>li:eq("+i+")";
	var div="#supermarket_banner>div:eq("+i+")";
	if(!$(li).hasClass("hover"))
	{
		//$("#supermarket_banner>ul>li").removeClass("hover");
		$(li).addClass('hover').siblings().removeClass('hover');
		
		//$("#supermarket_banner>div").animate({opacity:'hide'},500);
		$(div).stop(true,true).animate({opacity:'show'},500).siblings('div').animate({opacity:'hide'},500);
	}
}

//点击分类切换内容
function change(css,index,type,ob)
{
	var id="#"+css+"_"+index;
	$("div.coupon_main_ul").each
	(
			function ()
			{
				var tmp_id=$(this).attr('id');
				if(tmp_id.indexOf(css)>=0 && $(this).css('display')=="block")
				{
					$(this).hide();
				}
			}
	);
	$(id).show();
	$(ob).parent().parent().find('a').removeClass('hover');
	$(ob).addClass("hover");
	var more_id="#"+css+"_more";
	var url="/front/coupon?city="+search_city+"&type="+type;
	
	$(more_id).attr('href',url);
	
}

function get_coupon(coupon_id)
{
	var res=get_coupon_common(coupon_id,search_city,search_biz,'',"coupon_list");
}

//超市商场优惠券翻页
function get_shop_coupon(shop_id,merchant_type,ob)
{
	var page=parseInt($(ob).parent().next().val());
	
	if($(ob).hasClass("index_next"))//下一页
	{
		page++;
	}
	else//上一页
	{
		page--;
	}
	var tmp_page=page;
	$.post("/front/index/ajax_shop_coupon",{shop_id:shop_id,page:page,merchant_type:merchant_type},function(data)
			{
				var page=tmp_page;
				var res=jQuery.parseJSON(data);
				var coupons=res.item;
				var str='';
				for(var i=0;i<coupons.length;i++)
				{
					var coupon=coupons[i];
					//构造url
					var offset=res.merchant_index_coupon_num*page+i+1;
					var shop_page=Math.ceil(offset/res.merchant_coupon_num)-1;
					var url=shop_id+"?page="+shop_page+"#coupon_"+coupons[i]['id'];
					if(merchant_type==4)
					{
						url="/front/shop/detail/"+url;
					}
					else
					{
						url="/front/shop/merchant_detail/"+url;
					}
					//
					str+="<a href=\""+url+"\">";
					if(coupon['bid_name'])
					{
						var bid_name=coupon['bid_name'];
						if(coupon['bid_name'].length>12)
						{
							coupon['bid_name']=coupon['bid_name'].substring(0,12)+"..";
						}
						str+="<h3 title=\""+bid_name+"\">["+coupon['bid_name']+"]</h3>";
					}
					var coupon_name=coupon['name'];
					if(coupon_name.length>28)
					{
						coupon['name']=coupon_name.substring(0,28)+"..";
					}
					str+="<p title=\""+coupon_name+"\">"+coupon['name']+"</p></a>";
				}
				if(page==0)
				{
					$(ob).hide();
				}
				else
				{
					$(ob).next().show();
				}
				if(page==res.page_num-1)
				{
					$(ob).hide();
				}
				else
				{
					$(ob).prev().show();
				}
				$(ob).parent().next().val(page);
				$(ob).parent().prev().html(str);
			}
	);
}
