﻿
var center_text = new Array();
var center_index=0,center_showTimer, center_movetime = 5000;;

function Look_Select(obj, index) {//我看过的
    if (index == 1)
    {
        document.getElementById("imglook2").src = "public/images/look_out2.gif";
        document.getElementById("divclear").style.display='';
        GetCookie2(true,"shop");
    }
    if (index == 2)
    {
        document.getElementById("imglook1").src = "public/images/look_out1.gif";
        document.getElementById("divclear").style.display='none';
        GetHot2(true, "shop");
    }
    obj.src = "public/images/look_over" + index + ".gif";
}

/***********食客推荐************/
function Center_TimeShow()//
{
    center_index++;
    if(center_index>6)center_index=0;
    Center_TimeOver(document.getElementById("index_c"+(center_index+1)),center_index+1);
}
function Center_TimeOver(obj, index) {//食客推荐菜单自动得到焦点
    Center_OutAll();
    if (index == 1) {
        obj.className = "index_c1_ts_f index_c1_f";
    }
    else {
        obj.className = "index_c1_ts index_c1_f";
    }
    Center_DataShow(index);
}
function Center_Show() {//创建食客推荐菜单
    var div_str;
    div_str = "<div id='index_c1' class='index_c1_ts_f index_c1_f' onmouseover='Center_Over(this,1);' onmouseout='Center_Out();'>中餐</div>";
    div_str += "<div id='index_c2' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,2);' onmouseout='Center_Out();'>西餐</div>";
    div_str += "<div id='index_c3' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,3);' onmouseout='Center_Out();'>特色菜</div>";
    div_str += "<div id='index_c4' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,4);' onmouseout='Center_Out();'>茶艺馆</div>";
    div_str += "<div id='index_c5' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,5);' onmouseout='Center_Out();'>养生</div>";
    div_str += "<div id='index_c6' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,6);' onmouseout='Center_Out();'>甜品小食</div>";
    div_str += "<div id='index_c7' class='index_c1_to index_c1_f' onmouseover='Center_Over(this,7);' onmouseout='Center_Out();'>快餐</div>";
    div_str += "<div id='index_cb' class='index_c1_b' onmouseover='window.clearInterval(center_showTimer);' onmouseout='center_showTimer = window.setInterval(Center_TimeShow, center_movetime);'></div>";
    document.write(div_str);
    center_showTimer = window.setInterval(Center_TimeShow, center_movetime);
}
function Center_Over(obj, index) {//食客推荐菜单得到焦点
    window.clearInterval(center_showTimer);
    center_index=index-1;
    Center_OutAll();
    if (index == 1) {
        obj.className = "index_c1_ts_f index_c1_f";
    }
    else {
        obj.className = "index_c1_ts index_c1_f";
    }
    Center_DataShow(index);
}
function Center_Out(){//食客推荐菜单失去焦点
    center_showTimer = window.setInterval(Center_TimeShow, center_movetime);
}
function Center_OutAll() {//食客推荐菜单失去焦点
    document.getElementById("index_c1").className = "index_c1_to_f index_c1_f";
    for (i = 2; i <= 7; i++) {
        document.getElementById("index_c" + i).className = "index_c1_to index_c1_f";
    }
}
function Center_DataShow(index) {//食客推荐栏目跳转
    if (center_text.length >= 6) {
        document.getElementById("index_cb").innerHTML = center_text[index - 1];
    }
}

function Center_ListCssSelect(obj, img) {//食客推荐选择时
    var obj_a = document.getElementById("index_cb").getElementsByTagName("A");
    for (i = 0; i < obj_a.length; i++) {
        obj_a[i].className = '';
    }
    obj.className = "index_c1_list_select";
    //document.getElementById("index_c1_img").src = img;
    loadImg2(img);
}
function loadImg2(url) {
    var img = new Image(),
	    showTimer,
	    player = document.getElementById("smallplayer"),
	    pic = document.getElementById("index_c1_img");
	    //opaStep = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.7, 1],
//	    opaStep = [0, 0.1,  0.2, 0.3, 0.4, 0.5, 0.7, 1],
    //bg = ["#888", "#fff", "#bbb", "#888", "#444", "#222", "#000", "#000", "#000", "#000", "#000"],
//	    bg = ["#000", "#000", "#000", "#000", "#000", "#000", "#000", "#000", "#000", "#000", "#000"],
//	    p = 0,
//	    c = 0;
//	img.onerror="nofind();";
//	img.id="index_c1_img";
//    img.className = "img2";
    pic.src = url;
    pic.filters[0].Stop();
    pic.filters[0].Apply();
    pic.filters[0].transition = GetRandomNum(4,22);
    pic.filters[0].Play(); 
//    player.innerHTML = "<img src=\"public/images/loading.gif\" style=\"margin-top:86px;margin-left:114px;\"/>";
//    if (img.width > 0) initImg();
//    else img.onload = initImg;
//    function initImg() {
//        var width = img.offsetWidth,
//		    height = img.offsetHeight;
//        setStyle(player, { width: width + "px", height: height + "px" });
//        setOpacity(img, 0);            
//        player.innerHTML = "";
//        player.appendChild(img);
//        showTimer = window.setInterval(show, 20);
//    }
//    function show() {
//        //setStyle(player, "background", bg[p]);
//        setOpacity(img, opaStep[p++]);
//        if (p >= opaStep.length) window.clearInterval(showTimer);
//    }
}
/*******************************/

function DivMapShow(imgID, state) {//hot和new的显示,imgID是要显示的图片ID,state是要显示的状态(new/hot)
    var objdiv = document.createElement("div");
    document.getElementById("div_hotnew").appendChild(objdiv);
    if (state == "new") objdiv.className = 'new_png';
    else if (state == "hot") objdiv.className = 'hot_png';
    var obj = document.getElementById(imgID); 
    var objtop = Object_GetTop(obj);
    var objleft = Object_GetLeft(obj) + obj.offsetWidth - objdiv.offsetWidth; 
    objdiv.style.top = objtop;
    objdiv.style.left = objleft;
    
}
function Object_GetTop(obj) {//对象的top距离
    var offsetTop = obj.offsetTop;
    while (obj = obj.offsetParent) {
        offsetTop += obj.offsetTop;
    }
    return offsetTop;
}
function Object_GetLeft(obj) {//对象的left距离
    var offsetLeft = obj.offsetLeft;
    while (obj = obj.offsetParent) {
        offsetLeft += obj.offsetLeft;
    }
    return offsetLeft;
}
function nofind() {//没有图片时
    var img = event.srcElement;
    img.src = "public/images/nopicture.jpg";
}   

function ajax(pageaspx) {

    string = "";
    //建立对象
    var objXMLHTTP = null;
    if (window.ActiveXObject) {
        try {
            objXMLHTTP = new ActiveXObject("MSXML2.XMLHTTP");
        }
        catch (e) {
            try {
                objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2) { }
        }
    } else if (window.XMLHttpRequest) {
        objXMLHTTP = new XMLHttpRequest();
    }
    //发送数据
    objXMLHTTP.open("GET", pageaspx, false);
//    objXMLHTTP.setrequestheader("content-length", string.length);
//    objXMLHTTP.setrequestheader("content-type", "application/x-www-form-urlencoded");
    objXMLHTTP.send(null);
    //得到服务器端返加值
    return objXMLHTTP.responseText;
}

//清除cookie历史记录
function ClearCookie(state,action) {
    var flag;
    if (state)
        flag = ajax("ajax/command.ashx?cmd=ClearCookie&action="+action);
    else
        flag = ajax("../ajax/command.ashx?cmd=ClearCookie&action="+action);
    document.getElementById("spanlook").innerHTML = flag;
}

//读取cookie历史记录
function GetCookie(state,action,width)
{
    var flag;
    if (state)
        flag = ajax("ajax/command.ashx?cmd=LoadCookies&width="+width+"&count=6&action="+action);
    else
        flag = ajax("../ajax/command.ashx?cmd=LoadCookies&width="+width+"&count=6&action="+action+"&state=1");
    document.getElementById("spanlook").innerHTML = flag;    
}

//读取热门的
function GetHot(state,action,width)
{
    var flag;
    if (state)
        flag = ajax("ajax/command.ashx?cmd=LoadHot&width="+width+"&count=6&action="+action);
    else
        flag = ajax("../ajax/command.ashx?cmd=LoadHot&width="+width+"&count=6&action="+action);
    document.getElementById("spanlook").innerHTML = flag;
}

//读取cookie历史记录
function GetCookie2(state,action)
{
    var flag;
    if (state)
        flag = ajax("ajax/command.ashx?cmd=LoadCookies&width=200px&count=4&action="+action);
    else
        flag = ajax("../ajax/command.ashx?cmd=LoadCookies&width=200px&count=4&action=" + action + "&state=1");
    document.getElementById("spanlook").innerHTML = flag;    
}

//读取热门的
function GetHot2(state,action)
{
    var flag;
    if (state)
        flag = ajax("ajax/command.ashx?cmd=LoadHot&width=200px&count=4&action="+action);
    else
        flag = ajax("../ajax/command.ashx?cmd=LoadHot&width=200px&count=4&action="+action);
    document.getElementById("spanlook").innerHTML = flag;
}

//实现推荐
function SetTop(state,id) {
    var mess="推荐错误！",did=id,num=parseInt(document.getElementById("topnum").innerHTML);
    if(did=="")return;
    if (state == 2) mess = ajax("../../ajax/command.ashx?cmd=SetFoodTop&id=" + did);
    else mess = ajax("../../ajax/command.ashx?cmd=SetTop&id=" + did);
    if(mess=="true")
    {
        document.getElementById("topnum").innerHTML=num+1;
        alert("推荐,成功！");
    }
    else alert(mess);
}

//实现推荐
function SetTop2(state,id) {
    var mess="推荐错误！",did=id,num=parseInt(document.getElementById("topnum"+id).innerHTML);
    if(did=="")return;
    if(state==2) mess = ajax("ajax/command.ashx?cmd=SetFoodTop&id="+did);
    else mess = ajax("ajax/command.ashx?cmd=SetTop&id="+did);
    if(mess=="true")
    {
        document.getElementById("topnum"+id).innerHTML=num+1;
        alert("推荐,成功！");
    }
    else alert(mess);
}

//写入cookies
function SetCookies(id, name, action) {
    var mess = "写入错误！";
    if (id == "") return;
    mess = ajax("../../ajax/command.ashx?cmd=SetCookie&id=" + id + "&name=" + name + "&action=" + action);
}

//获取地址参数
function getUrlPara(paraName){ 
 var sUrl  =  location.href;
 var sReg  =  "(?:\\?|&){1}"+paraName+"=([^&]*)"
 var re=new RegExp(sReg,"gi");
 re.exec(sUrl);
 if(RegExp.$1=="compatible")
 return "";
 else
 return RegExp.$1;
}


/****************层操作***************/
//文字显示
function ShowFontOver(name,text,width,height){
    var obj = document.getElementById(name);
    obj.innerHTML = "<div class='divpic' style='width:"+width+";height:"+height+";text-align:left;'>"+text+"</div>";
    Font_Mouse_Show(obj);
}
//文字隐藏
function ShowFontOut(name) {
    var obj = document.getElementById(name);
    Div_Hide(obj);
}
function Font_Mouse_Show(obj) {//显示文字层
//    var x = document.body.scrollLeft + GetLeft();
//    var y = document.body.scrollTop + GetTop();
    var x =  GetLeft();
    var y =  GetTop();
    obj.style.top = y-9;
    obj.style.left = x+10;
    obj.style.display = "block";    
    obj.innerHTML+="<div style='top:2px;left:-13px;POSITION: absolute;'><img src='images/arrow.gif'/></div>";
}

//图片显示
function ShowimgOver(name, img,width,height) {
    var obj = document.getElementById(name);
    obj.innerHTML = "<div class='divpic'><img src='" + img + "' width='"+width+"' height='"+height+"'/></div>";
    Div_Mouse_Show(obj,height+12);
}
//内容隐藏
function ShowimgOut(name) {
    var obj = document.getElementById(name);
    Div_Hide(obj);
}
function Div_Hide(obj) {//隐藏层
    obj.style.display = "none";
}

function Div_Mouse_Show(obj,height) {//显示层
    var clientheight=document.documentElement.clientHeight+document.documentElement.scrollTop;//IE显示内容高度
    var arrow_top=5;
    var x =  GetLeft();
    var y =  GetTop();
    obj.style.top = y+0;
    obj.style.left = x+10;
    if((y+height)>clientheight)
    {
        obj.style.top = clientheight-height;
        arrow_top= y + height - clientheight + 5;
    }
    obj.style.display = "block";    
    obj.innerHTML+="<div style='top:"+arrow_top+"px;left:-13px;POSITION: absolute;'><img src='public/images/arrow.gif'/></div>";
}

function GetTop() {//上边距离
    var objtxt = window.event.srcElement;
    var offsetTop = objtxt.offsetTop;
    while (objtxt = objtxt.offsetParent) {
        offsetTop += objtxt.offsetTop;
    }
    return offsetTop;
}
function GetLeft() {//左边距离
    var objtxt = window.event.srcElement;
    var offsetLeft = objtxt.offsetLeft + objtxt.offsetWidth+5;
    while (objtxt = objtxt.offsetParent) {
        offsetLeft += objtxt.offsetLeft;
    }
    return offsetLeft;
}
/*************************************/


/************top5图片显示*************/
function OnSelect(name,tip)
{
    var obj_li = document.getElementById(name+tip),obj_tmp,obj_a,obj_b;
    for(var i=1;i<=5;i++)
    {
        obj_tmp=document.getElementById(name+i);        
        if(obj_li!=obj_tmp&&obj_tmp!=null)
        {            
            obj_tmp.className="index_top_out";
            obj_b=obj_tmp.getElementsByTagName("b");
            if(obj_b[0]!=null)obj_b[0].style.display="none";            
            if(obj_b[1]!=null)obj_b[1].style.display="";
            obj_a=obj_tmp.getElementsByTagName("a");
            if(obj_a[1]!=null)obj_a[1].className="";
        }
    }
    obj_li.className="index_top_over";
    obj_b=obj_li.getElementsByTagName("b");
    if(obj_b[0]!=null)obj_b[0].style.display="";            
    if(obj_b[1]!=null)obj_b[1].style.display="none"; 
    obj_a=obj_li.getElementsByTagName("a");
    if(obj_a[1]!=null)obj_a[1].className="index_top_a";
}
function OnSelect2(name,tip)
{
    var obj_li = document.getElementById(name+tip),obj_tmp,obj_a,obj_b;
    for(var i=1;i<=5;i++)
    {
        obj_tmp=document.getElementById(name+i);        
        if(obj_li!=obj_tmp&&obj_tmp!=null)
        {            
            obj_tmp.className="yellow_menu_out";
            obj_b=obj_tmp.getElementsByTagName("b");
            if(obj_b[0]!=null)obj_b[0].style.display="none";            
            if(obj_b[1]!=null)obj_b[1].style.display="";
            obj_a=obj_tmp.getElementsByTagName("a");
            if(obj_a[1]!=null)obj_a[1].className="";
        }
    }
    obj_li.className="yellow_menu_over";
    obj_b=obj_li.getElementsByTagName("b");
    if(obj_b[0]!=null)obj_b[0].style.display="";            
    if(obj_b[1]!=null)obj_b[1].style.display="none"; 
    obj_a=obj_li.getElementsByTagName("a");
    if(obj_a[1]!=null)obj_a[1].className="yellow_menu_a";
}
/*************************************/
/************top10图片显示*************/
function OnSelect3(name,tip)
{
    var obj_li = document.getElementById(name+tip),obj_tmp,obj_a,obj_b;
    for(var i=1;i<=10;i++)
    {
        obj_tmp=document.getElementById(name+i);        
        if(obj_li!=obj_tmp&&obj_tmp!=null)
        {            
            obj_tmp.className="yellow_menu_out";
            obj_b=obj_tmp.getElementsByTagName("b");
            if(obj_b[0]!=null)obj_b[0].style.display="none";            
            if(obj_b[1]!=null)obj_b[1].style.display="";
            obj_a=obj_tmp.getElementsByTagName("a");
            if(obj_a[1]!=null)obj_a[1].className="";
        }
    }
    obj_li.className="yellow_menu_over";
    obj_b=obj_li.getElementsByTagName("b");
    if(obj_b[0]!=null)obj_b[0].style.display="";            
    if(obj_b[1]!=null)obj_b[1].style.display="none"; 
    obj_a=obj_li.getElementsByTagName("a");
    if(obj_a[1]!=null)obj_a[1].className="yellow_menu_a";
}
/*************************************/

/*************取随机数**************/
function GetRandomNum(Min, Max) {
    var Range = Max - Min;
    var Rand = Math.random();
    return (Min + Math.round(Rand * Range));
}
/**********************************/


