﻿function yincang(type)
{		
		
		if(type=="meishi")
		{
			document.getElementById('meishi').className = 'menu-title-hover';
			document.getElementById('yule').className = 'menu-title';
			document.getElementById('meirong').className = 'menu-title';
			document.getElementById('meishi_div').style.display = 'block';
			document.getElementById('yule_div').style.display = 'none';
			document.getElementById('meirong_div').style.display = 'none';
		}	
		if(type=="yule")
		{
			document.getElementById('meishi').className = 'menu-title';
			document.getElementById('yule').className = 'menu-title-hover';
			document.getElementById('meirong').className = 'menu-title';
			document.getElementById('meishi_div').style.display = 'none';
			document.getElementById('yule_div').style.display = 'block';
			document.getElementById('meirong_div').style.display = 'none';
		}	
		if(type=="meirong")
		{
			document.getElementById('meishi').className = 'menu-title';
			document.getElementById('yule').className = 'menu-title';
			document.getElementById('meirong').className = 'menu-title-hover';
			document.getElementById('meishi_div').style.display = 'none';
			document.getElementById('yule_div').style.display = 'none';
			document.getElementById('meirong_div').style.display = 'block';
		}
}

function obj() {
	this.intervalHandle = null;
	this.curIndex = 0;
	this.count = 0;
	this.moveHandel = null;
	this.switchTime = 8000;
}
var para = new obj();

$(function(){
	var url = window.location.href;
	var city = -1;
	
	if (url.indexOf('guangzhou') > 0) {
		city = 720;
	} else if (url.indexOf('shenzhen') > 0) {
		city = 606;
	} else if (url.indexOf('shanghai') > 0) {
		 city = 1;
	}
	
	//由于缓存的原因,在控制器设置cookie操作不被执行,故需要根据url来设置cookie
	if (city > 0) {
		setCookie('city_id', city);
	}
	
	para.count = $("#idNum li").size();
	
	$('#idSlider li').hover(
		function() {
			para.curIndex = $(this).index();
			clearInterval(para.intervalHandle);
			clearInterval(para.moveHandel);
			showImg();
		},
		function(){para.intervalHandle = setInterval("changeShow()", para.switchTime);}
	);
	
	$('#idNum li').hover(
		function() {
			if (!$(this).hasClass('on')) {
				para.curIndex = $(this).index();
				clearInterval(para.intervalHandle);
				clearInterval(para.moveHandel);
				showImg();
			}
		},
		null
	);
	
//	$('#idSlider li').css({position:'absolute',top:'390px'});
//	$('#idSlider li').eq(0).css({top:'0px'});
	$('#idSlider').css({top:'0px'});
	
	$('#idNum li').eq(0).attr('class', 'on');
	
	if (para.count > 1) {
		para.intervalHandle = setInterval("changeShow()", para.switchTime);
		
	    $("#idNum").hover(
	    	function(){clearInterval(para.intervalHandle)}, 
	    	function(){para.intervalHandle = setInterval("changeShow()", para.switchTime);}
	    );
	}
    updateRecommendCateBusi();
    
    updateLatestCouponDownload();
});


function changeShow() {
	para.curIndex = (para.curIndex >= (para.count - 1)) ? 0 : para.curIndex + 1;
    showImg(); 
}

function showImg() {
	$('#idNum li').removeClass();
	$('#idNum li').eq(para.curIndex).addClass('on');
	/*
	var time = 800;
	$('#idSlider li').filter(function(i) {return $(this).css('top') == '0px';}).animate({top: "-390"}, time, function(){$(this).css('top', '390px');});
	$('#idSlider li').eq(para.curIndex).animate({top: "0"}, time);
	*/
	
	var top = -390 * para.curIndex;

//	$("#idSlider").animate({top: "-" + top}, 800);
	var oldTop = Math.ceil($("#idSlider").css('top').replace('px', '') || 0);
	
	var step = (oldTop - top) / 15;
	
	para.moveHandel = setInterval(
		function(){
			oldTop -= step;
			
			if (oldTop * step <= top * step) {
				clearInterval(para.moveHandel);
				oldTop = top;
			}
			
			$("#idSlider").css({'top' : oldTop });
		}
		,50
	);
}

function updateLatestCouponDownload() {
	$.ajax({
		url : '/index.php/index/latest_download_coupon',
		type : 'get',
		success : function(msg) {
			$('#latestdlc').html(msg);
			
			setTimeout("updateLatestCouponDownload()", 20000);
		}
	});
}

function updateRecommendCateBusi() {
	$.ajax({
		url : '/index.php/index/recommend_cate_busi',
		type : 'get',
		success : function(msg) {
			$('#recomendCateDiv').html(msg);
		}
	});
}

