﻿/*
 * 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()};

(function($){
    //给jquery扩展的方法
    $.extend({
        postJSON:function(url,data,callback){jQuery.post(url, data, callback, "json")},
        nowTicks:function(){return +new Date},
        noCacheURL:function(url){var ts=this.nowTicks();var ret=url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+ts+"$2");return ret+((ret==url)?(url.match(/\?/)?"&":"?")+"_="+ts:"");},
        isHex:function(num){return /^[0-9a-f]+$/i.test(num)},
        isMail:function(mail){return /^[a-z](?:[a-z0-9]*[-_]?[a-z0-9]+)*@(?:[a-z0-9]*[-_]?[a-z0-9]+)+\.[a-z]{2,3}(?:\.[a-z]{2})?$/i.test(mail)},
        isMobile:function(mo){return /^1[358][0-9]{9}$/i.test(mo)},
        openWindow:function(url,winname,width,height,top,left){
            if(!top)top=0.5;
            if(!left)left=0.5;
            if(!width)width=640;
            if(!height)height=420;
            if(top<=1)top=(window.screen.availHeight-height)*top;
            if(left<=1)left=(window.screen.availWidth-width)*left;
            window.open(url,winname,"width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",toolbar=no,menubar=no,resizable=no,location=no,status=no");
        },
        closeWindow:function(noConfirm){
            if(noConfirm){window.opener=null;window.open("","_self");}
            window.close();
        },
        loadPlayer:function(id,data){
            if(typeof data.url=="string"){
                $.getJSON(data.url,function(json){
                    data.url=json;
                    $.loadPlayer(id,data);
                });
            }else{
                var list=[];
                var urls=data.url;
                if(data.img)list=[{url:data.img,autoPlay:true}];
                for(var i=0;i<urls.length;i++)list.push({url:urls[i]});
                if(data.img){
                    list[1].autoPlay=!!data.autoPlay;
                    list[1].autoBuffering=!!data.autoBuffering;
                }else{
                    list[0].autoPlay=!!data.autoPlay;
                    list[0].autoBuffering=true;
                }
                $f(id,{src:"/Upload/Video/flowplayer.swf?_="+Math.random(),wmode: 'opaque'},{
                    clip:{
                        autoPlay:true,
                        autoBuffering:true,
                        onPause:function(){
                            //player paused
                        },
                        onResume:function(){
                            //player resumed
                        },
                        onFinish:function(clip){
                            //clip.index
                        }
                    },playlist:list,plugins:{controls:{playlist:true}}
                });
            } 
        }
    });
})(jQuery);

$(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(speed,pasuetime){
    $.getJSON("/AjaxData.ashx?sid"+Math.random(),{Action:1,Index:1},function(json){
        var c=json.length;
        var aDemo = [];
        var aStand = [];
        var aOther = [];
        for(var k = 0; k < c; k++){
            switch(json[k].type){
                case 1 : 
                    aStand.push(json[k]);
                    break;
                case 2 : 
                    aDemo.push(json[k]);
                    break;
                case 0 : 
                    aOther.push(json[k]);
                    break;
                default :
            }
        }
    
        var iDemoLength = aDemo.length;
        var iStandLength = aStand.length;
        var iOtherLength = aOther.length;
        
        //模范客户
        var demoCustomers=$("#demon");
        for(var i=0;i<iDemoLength;i++){
            if(i%5==4)
                demoCustomers.append("<li class=\"right\"><a href='javascript:void(0)' onclick='ShowDetail("+aDemo[i].id+")'><img src='"+aDemo[i].url+"' width='125' height='40' alt='' /></a></li>");
            else
                demoCustomers.append("<li><a href='javascript:void(0)' onclick='ShowDetail("+aDemo[i].id+")'><img src='"+aDemo[i].url+"' width='125' height='40' alt='' /></a></li>");
        }
        if(iDemoLength<6) {}
        else{
            var demoChilds=demoCustomers.find("li");
            var demoMax=Math.ceil(iDemoLength/5);
            if(iDemoLength<demoMax*5){
                for(var i=0,j=demoMax*5-iDemoLength-1;i<j;i++){
                    demoCustomers.append("<li style='visibility:hidden'></li>");
                }
                demoCustomers.append("<li class='right' style='visibility:hidden'></li>");
            }
            demoChilds.slice(0,5).clone().appendTo(demoCustomers);
            var demoFloorH=54;// (44 + 10)//demoChilds.eq(5).position().top - demoChilds.eq(0).position().top;
            var demoFloor=1;
            function demoMove(){
                if(demoCustomers.scrollTop() >= demoFloorH*demoFloor - 1){
                    clearInterval(demoTimer);
                    demoCustomers.scrollTop(demoFloorH*demoFloor);
                    demoFloor++;
                    if(demoFloor>demoMax){
                        demoFloor=1;
                        demoCustomers.scrollTop(0);
                    }
                    setTimeout(function(){
                        demoTimer=setInterval(demoMove,speed);
                    },pasuetime);
                }else{
                    demoCustomers.scrollTop(demoCustomers.scrollTop()+2);
                }
            }
            var demoTimer;
            setTimeout(function(){
                demoTimer=setInterval(demoMove,speed);
            },pasuetime);
        }
        
        //以下为标杆客户
        var standardCustomers=$("#standard");
        for(var i=0;i<iStandLength;i++){
            if(i%5==4)
                standardCustomers.append("<li class=\"right\"><a href='javascript:void(0)' onclick='ShowDetail("+aStand[i].id+")'><img src='"+aStand[i].url+"' width='125' height='40' alt='' /></a></li>");
            else
                standardCustomers.append("<li><a href='javascript:void(0)' onclick='ShowDetail("+aStand[i].id+")'><img src='"+aStand[i].url+"' width='125' height='40' alt='' /></a></li>");
        }
        if(iStandLength<6) {}
        else{
            var standChilds=standardCustomers.find("li");
            var standMax=Math.ceil(iStandLength/5);
            if(iStandLength<standMax*5){
                for(var i=0,j=standMax*5-iStandLength-1;i<j;i++){
                    standardCustomers.append("<li style='visibility:hidden'></li>");
                }
                standardCustomers.append("<li class='right' style='visibility:hidden'></li>");
            }
            standChilds.slice(0,5).clone().appendTo(standardCustomers);
            var standFloorH=54;// (44 + 10) //standChilds.eq(5).position().top - standChilds.eq(0).position().top;
            var standFloor=1;
            function standMove(){
                if(standardCustomers.scrollTop() >= standFloorH*standFloor - 1){
                    clearInterval(standTimer);
                    standardCustomers.scrollTop(standFloorH*standFloor);
                    standFloor++;
                    if(standFloor>standMax){
                        standFloor=1;
                        standardCustomers.scrollTop(0);
                    }
                    setTimeout(function(){
                        standTimer=setInterval(standMove,speed);
                    },pasuetime);
                }else{
                    standardCustomers.scrollTop(standardCustomers.scrollTop()+2);
                }
            }
            var standTimer;
            setTimeout(function(){
                standTimer=setInterval(standMove,speed);
            },pasuetime);
        }
        
        //其他客户
        var otherCustomers=$("#other");
        for(var i=0;i<iOtherLength;i++){
            if(i%5==4)
                otherCustomers.append("<li class=\"right\"><a href='javascript:void(0)' onclick='ShowDetail("+aOther[i].id+")'><img src='"+aOther[i].url+"' width='125' height='40' alt='' /></a></li>");
            else
                otherCustomers.append("<li><a href='javascript:void(0)' onclick='ShowDetail("+aOther[i].id+")'><img src='"+aOther[i].url+"' width='125' height='40' alt='' /></a></li>");
        }
        if(iOtherLength<6) {}
        else{
            var otherChilds=otherCustomers.find("li");
            var otherMax=Math.ceil(iOtherLength/5);
            if(iOtherLength<otherMax*5){
                for(var i=0,j=otherMax*5-iOtherLength-1;i<j;i++){
                    otherCustomers.append("<li style='visibility:hidden'></li>");
                }
                otherCustomers.append("<li class='right' style='visibility:hidden'></li>");
            }
            otherChilds.slice(0,5).clone().appendTo(otherCustomers);
            var otherFloorH=54;// (44 + 10) //otherChilds.eq(5).position().top - otherChilds.eq(0).position().top;
            var otherFloor=1;
            function otherMove(){
                if(otherCustomers.scrollTop() >= otherFloorH*otherFloor - 1){
                    clearInterval(otherTimer);
                    otherCustomers.scrollTop(otherFloorH*otherFloor);
                    otherFloor++;
                    if(otherFloor>otherMax){
                        otherFloor=1;
                        otherCustomers.scrollTop(0);
                    }
                    setTimeout(function(){
                        otherTimer=setInterval(otherMove,speed);
                    },pasuetime);
                }else{
                    otherCustomers.scrollTop(otherCustomers.scrollTop()+2);
                }
            }
            var otherTimer;
            setTimeout(function(){
                otherTimer=setInterval(otherMove,speed);
            },pasuetime);
        }
    });
};

function showUL(type){
    switch (type){
        case 1 : 
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(0).attr("class","mow");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(1).removeAttr("class");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(2).removeAttr("class");
            $("#standard").hide();
            $("#other").hide();
            $("#demon").show();
            break;
        case 2 :
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(1).attr("class","mow");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(0).removeAttr("class");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(2).removeAttr("class");
            $("#demon").hide();
            $("#other").hide();
            $("#standard").show();
            break;
        case 0 :
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(2).attr("class","mow");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(0).removeAttr("class");
            $("ul li",$("#e6customersDisplayINDEX").get(0)).eq(1).removeAttr("class");
            $("#demon").hide();
            $("#standard").hide();
            $("#other").show();
            break;
        default : 
    }
};