﻿/*
 * Class Constructor Engine - v0.1
 */
var object={isA:function(a){var b=this;while(b){if(b==a)return true;b=b.Base}return false}};function Class(a,b){function c(){this.Base=a;for(var d in b)this[d]=b[d]}c.prototype=a;return new c()}function New(a,b){function c(){this.Base=a;if(a.Create)a.Create.apply(this,b)}c.prototype=a;return new c()};

$(document).ready(function() {
    /* 菜单效果 */
    $("#nav-one > li").hover(
	    function() { $("ul", this).fadeIn("fast"); },
	    function() { $("ul", this).stop(true,true).fadeOut(); }
    );
    if (document.all) {
        $("#nav-one > li").hover(
		    function() { $(this).addClass("sfHover"); },
		    function() { $(this).removeClass("sfHover"); }
	    );
    }
    $("#nav-one > li > a[rel]").each(function(i) {
        $(this).parent().find("ul a").width($(this).attr("rel"));
    });
});

function LoginLayer(){
    var obj=$("#loginLayer");
    var show=false;
    var divshow=false;
    $("#loginLayer").hover(
        function(){divshow=true;obj.stop(true,true).fadeIn("fast")},
        function(){obj.stop(true,true).fadeOut("slow");divshow=false}
    );
    $("#loginButton img:first").hover(
        function(){if(divshow)return;show=true;obj.stop(true,true).fadeIn("fast")},
        function(){setTimeout(function(){if(divshow)return;show=false;obj.stop(true,true).fadeOut("slow")},0)}
    );
}

function Favorite(sURL,sTitle){
    if(window.sidebar)
        window.sidebar.addPanel(sTitle,sURL,"");
    else
        window.external.AddFavorite(sURL,sTitle);
}

function SearchInit(e){
    e.title="自动过滤字符“{ } [ ] ( ) ' \" . + \\ | ^ $ * ?”";
    e.onmouseover=null;
    SearchInit=null;
}

/* 显示客户信息 */
function ShowDetail(id){
    var c=$("#CustomerInfo");
    if(!document.layerarr){
        c.html("<div class=\"title\"><span><input class=\"buttonClose\" type=\"button\" /></span><h2>客户详情</h2></div><div class=\"content\" id=\"infomsg\"><h3></h3><strong>企业网站</strong><p></p><strong>企业简介</strong><p></p><strong>企业使用易流GPS情况</strong><p class=\"bottom\"></p></div>");
        c.find("input:first").eq(0).hover(
            function(){$(this).attr("class","buttonCloseover");},
            function(){$(this).attr("class","buttonClose");}
        ).click(function(){
            HideDetail();
        });
        document.layerarr=new Array();
        document.layerarr.push(c.find("h3"));
        var p=c.find("p");
        document.layerarr.push(p.eq(0));
        document.layerarr.push(p.eq(1));
        document.layerarr.push(p.eq(2));
    }
    document.layerarr[0].text("");
    document.layerarr[1].text("");
    document.layerarr[2].html("");
    document.layerarr[3].html("");
    $("#layerbgid").width($(document).width());
    $("#layerbgid").height($(document).height());
    $("#layerbgid").show();
    var v=Math.random();
    document.layerajax=v;
    $(document).keydown(function(event){
        if(event.keyCode==27){
            HideDetail();
        }
    });
    var size = GetPageSize();
    c.css("left",(size[0]-c.width())/2+$(document).scrollLeft());
    c.css("top",100+$(document).scrollTop());
    c.fadeIn("fast");
    $.getJSON("/AjaxData.ashx?sid="+Math.random(),{Id:id},function(info){
        if(document.layerajax!=v)return;
        document.layerarr[0].text(info.CompanyName);
        document.layerarr[1].text(info.CompanyUrl);
        document.layerarr[2].html(info.Summary);
        document.layerarr[3].html(info.UseGps);
    });
}
function HideDetail(){
    $("#CustomerInfo").hide();
    $("#layerbgid").hide();
    document.layerajax=0;
}
function GetPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {	
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    if(xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

/* 随机展示客户信息 */
function RandShowCustomer(id,urls){
    var obj=$(id);
    for(var i=0;i<4;i++){
        var tr=obj.append("<tr></tr>").find("tr:last");
        for(var j=0;j<5;j++){
            tr.append("<td><img alt='' /></td>");
        }
    }
    var imgs=$(id+" img");
    var c=urls.length;
    for(var i=0;i<20;i++){
        var k=GetRnd(c-i);
        imgs[i].src=urls[k];
        urls[k]=urls[c-i-1];
        urls.pop();
    }
    
    var lastindex=-1;
    setImage();
    function setImage(){
        c=urls.length;
        var k=GetRnd(c);
        var nextimg=urls[k];
        urls[k]=urls[c-1];
        urls.pop();
        var i=GetRnd(20);
        while(lastindex==i)i=GetRnd(20);
        lastindex=i;
        var img=imgs.eq(i);
        img.fadeOut(600,function(){
            urls.push(img.attr("src"));
            img.attr("src",nextimg);
            setTimeout(setImage,0);
            img.fadeIn(1000);
        });
    }
    function GetRnd(i){
        return Math.floor(Math.random()*i);
    }
}
/* 折叠效果 */
function SlideUpDown(css){
    $(css).click(function(){
        var a=$(this).find("a");
        if(a.attr("class")=="open"){
            $(this).nextAll().slideDown("slow");
            a.attr("class","away");
        }else{
            $(this).nextAll().slideUp("slow");
            a.attr("class","open");
        }
    }).eq(0).nextAll().show();
}

/* tab切换 */
function Tab(cn,mcn){
    var as=$("div."+cn+" a");
    var lis=$("div."+cn+" li");
    var divs=$("div."+cn+"").nextAll("div."+mcn);
    var dl=divs.length;
    var lastindex=0;
    as.click(function(){
        var index=as.index(this);
        if(lastindex==index)return;
        lastindex=index;
        lis.removeClass("now");
        $(lis[index]).addClass("now");
        if(dl>index){
            divs.hide();
            $(divs[index]).show();
        }
    });
}

/* 滚动客户展示 */
function Marquee(id,speed){
    $.getJSON("/AjaxData.ashx?sid"+Math.random(),{Action:1},function(json){
        var c=json.length;
        var obj=$(id);
        var child=obj.find("ul");
        for(var i=0;i<c;i++){
            child.append("<li><a href='javascript:void(0)' onclick='ShowDetail("+json[i].id+")'><img src='"+json[i].url+"' width='125' height='40' alt='' /></a></li>");
        }
        var h=child.height();
        if(obj.height()>=h)return;
        child.clone().appendTo(obj);
        function move(){
            if(obj.scrollTop()>=h)obj.scrollTop(0);
            else obj.scrollTop(obj.scrollTop()+1);
        }
        var timer=setInterval(move,speed);
        obj.hover(
            function(){clearInterval(timer);},
            function(){timer=setInterval(move,speed);}
        );
    });
}

function MaqueePasue(id,speed,pasuetime){
    $.getJSON("/AjaxData.ashx?sid"+Math.random(),{Action:1,Index:1},function(json){
        var c=json.length;
        var obj=$(id);
        for(var i=0;i<c;i++){
            if(i%5==4)
                obj.append("<li class=\"right\"><a href='javascript:void(0)' onclick='ShowDetail("+json[i].id+")'><img src='"+json[i].url+"' width='125' height='40' alt='' /></a></li>");
            else
                obj.append("<li><a href='javascript:void(0)' onclick='ShowDetail("+json[i].id+")'><img src='"+json[i].url+"' width='125' height='40' alt='' /></a></li>");
        }
        if(c<6)return;
        var childs=obj.find("li");
        var max=Math.ceil(c/5);
        if(c<max*5){
            for(var i=0,j=max*5-c-1;i<j;i++){
                obj.append("<li style='visibility:hidden'></li>");
            }
            obj.append("<li class='right' style='visibility:hidden'></li>");
        }
        childs.slice(0,6).clone().appendTo(obj);
        var floorH=childs.eq(5).position().top-childs.eq(0).position().top;
        var floor=1;
        function move(){
            if(obj.scrollTop()>=floorH*floor-1){
                obj.scrollTop(floorH*floor);
                clearInterval(timer);
                floor++;
                if(floor>max){
                    floor=1;
                    obj.scrollTop(0);
                }
                setTimeout(function(){
                    timer=setInterval(move,speed);
                },pasuetime);
            }else{
                obj.scrollTop(obj.scrollTop()+2);
            }
        }
        var timer;
        setTimeout(function(){
            timer=setInterval(move,speed);
        },pasuetime);
    });
}
