function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = false;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = false;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
		    mainInstance.toggleMenu(this.parentNode);
		}
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
    }
    for (var i = 0; i < this.submenus.length; i++)
        if (this.submenus[i].className != "collapsed")
            this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};



//var myMenu;
var source = [];
var MyMar;
var MyMar1;
var MyMar3
window.onload = function () {
    //    myMenu = new SDMenu("my_menu");
    //    myMenu.init();


    jQuery(window).ready(function () {
        jQuery("#navigation").Smartmenu({ animationDuration: 350 });
    });
    SyntaxHighlighter.all();
    var box = document.getElementById("div1");
    var can = true;


    var box2 = document.getElementById("TopPd");
    if (box2 != null) {
        window.onscroll = scall;
        window.onresize = scall;
        window.onload = scall;
        var t_count = 0;
        $.ajax({
            type: "post",
            url: "/Home/GetFloatAdvList",
            success: function (data, textStatus) {
                if (data != "") {
                    var list = data.split("%");
                    var Target = "";
                    var FloatLocation = "";
                    var FloatType = "";
                    var TimeSpan = 0;
                    var altmsg = "";
                    var selist;
                    var thlist;
                    var index;
                    
                    for (i = 0; i < list.length; i++) {
                        source = [];
                        selist = list[i].split("|");
                        Target = selist[0];
                        FloatLocation = selist[1];
                        FloatType = selist[2];
                        TimeSpan = selist[3];
                        altmsg = selist[4];
                        index = 0;

                        if (FloatType == "1") {
                            switch (FloatLocation) {
                                case 'Left': var LeftClose = document.getElementById("LeftClose"); LeftClose.style.visibility = "visible"; break;
                                case 'Bottom': var BottomClose = document.getElementById("BottomClose"); BottomClose.style.visibility = "visible"; break;
                                case 'Right': var RightClose = document.getElementById("RightClose"); RightClose.style.visibility = "visible"; break;
                            };
                        }

                        thlist = selist[5].split(";");
                        if (thlist.length > 1) {
                            for (j = 0; j < thlist.length; j++) {
                                source[index] = { src: '../../ClientRazor/Content/UploadFolder/Images/Float/' + thlist[j], title: altmsg, href: 'http://' + Target, target: '_blank' };
                                index = index + 1;
                            }
                            $('#' + FloatLocation + 'Pd').crossSlide({
                                sleep: parseInt(TimeSpan),
                                fade: 2
                            }, source);
                            if (FloatLocation == 'Top') {
                                slideAd('TopPd', TimeSpan, 'down');
                            }
                        }
                        else {
                            var Html = "<a href= 'http://" + Target + "' target='_blank' ><img style='border:0px;' id='" + FloatLocation + "Pic' title='" + altmsg + "' src='../../ClientRazor/Content/UploadFolder/Images/Float/" + thlist[0] + "'/></a>";
                            switch (FloatLocation) {
                                case 'Top': var TopPd = document.getElementById("TopPd"); TopPd.innerHTML = Html; var TopPic = document.getElementById("TopPic"); TopPic.width = TopPd.clientWidth; slideAd('TopPd', TimeSpan, 'down', TopPic.height, 2.5); break;
                                case 'Left': var LeftPd = document.getElementById("LeftPd"); LeftPd.innerHTML = Html; var LeftPic = document.getElementById("LeftPic"); LeftPic.height = LeftPd.clientHeight; LeftPic.width = LeftPd.clientWidth; break;
                                case 'Bottom': var BottomPd = document.getElementById("BottomPd"); BottomPd.innerHTML = Html; var BottomPic = document.getElementById("BottomPic"); BottomPic.height = BottomPd.clientHeight; BottomPic.width = BottomPd.clientWidth; break;
                                case 'Right': var RightPd = document.getElementById("RightPd"); RightPd.innerHTML = Html; var RightPic = document.getElementById("RightPic"); RightPic.height = RightPd.clientHeight; RightPic.width = RightPd.clientWidth; break;
                            };
                        }
                    }
                }
            }
        });

        ///边广告

        lastScrollY = 0;
        function heartBeat() {
            var diffY;
            if (document.documentElement && document.documentElement.scrollTop)
                diffY = document.documentElement.scrollTop;
            else if (document.body)
                diffY = document.body.scrollTop;
            else
            { /*Netscape stuff*/ }
            //alert(diffY);
            percent = .1 * (diffY - lastScrollY);
            if (percent > 0) percent = Math.ceil(percent);
            else percent = Math.floor(percent);
            document.getElementById("LeftAd").style.top = parseInt(document.getElementById("LeftAd").style.top) + percent + "px";
            document.getElementById("RightAd").style.top = parseInt(document.getElementById("RightAd").style.top) + percent + "px";
            lastScrollY = lastScrollY + percent;
            //alert(lastScrollY);
        }
        window.setInterval(heartBeat, 1);

        ////
        ///TOP广告
        var intervalId = null;
        function slideAd(id, nStayTime, sState, nMaxHth, nMinHth) {
            this.stayTime = nStayTime * 1000 || 3000;
            this.maxHeigth = nMaxHth || 460;
            this.minHeigth = nMinHth || 2.5;
            this.state = sState || "down";
            var obj = document.getElementById(id);
            if (intervalId != null) window.clearInterval(intervalId);
            function openBox() {
                var h = obj.offsetHeight;
                obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2)) + "px";
                if (obj.offsetHeight > this.maxHeigth) {
                    window.clearInterval(intervalId);
                    intervalId = window.setInterval(closeBox, this.stayTime);
                }
                if (obj.offsetHeight < this.minHeigth) {
                    window.clearInterval(intervalId);
                    obj.style.display = "none";
                }
            }
            function closeBox() {
                slideAd(id, this.stayTime, "up", nMaxHth, nMinHth);
            }
            intervalId = window.setInterval(openBox, 20);
        }
    }


    if ((box != null) && (box != undefined)) {
        box.innerHTML += box.innerHTML;
        box.onmouseover = function () { can = false; };
        box.onmouseout = function () { can = true; };
        new function () {
            var stop = box.scrollTop % 35 == 0 && !can;
            if (!stop) box.scrollTop == parseInt(box.scrollHeight / 2) ? box.scrollTop = 0 : box.scrollTop++;
            setTimeout(arguments.callee, box.scrollTop % 35 ? 10 : 1500);
        };
        $.ajax({
            type: "get",
            url: "/Home/GetPicNewsList",
            success: function (data, textStatus) {
                if (data != "") {
                    var list = data.split("%");
                    var id = "";
                    var altmsg = "";
                    var selist;
                    var thlist;
                    var index = 0;
                    for (i = 0; i < list.length; i++) {
                        selist = list[i].split("|");
                        id = selist[0];
                        altmsg = selist[1];
                        thlist = selist[2].split(";");
                        for (j = 0; j < thlist.length; j++) {
                            //                            source[index] = { src: '../../ClientRazor/Content/UploadFolder/Images/PictureNews/' + thlist[j], alt: altmsg, href: '/PictureNews/ShowPictureNewsInfo?NewsID=' + id, style: 'width:685px;height:176px' };
                            source[index] = { src: '../../ClientRazor/Content/UploadFolder/Images/PictureNews/' + thlist[j], title: altmsg, style: 'width:685px;height:176px' };
                            index = index + 1;
                        }
                    }

                    $('#slideshow').crossSlide({
                        sleep: 3,
                        fade: 2
                    }, source);
                }
            }
        });

    };

    var speed3 = 100;
    var foot = document.getElementById("butong_net_left");
    if (foot != null) {
        var foot1 = document.getElementById("butong_net_left1");
        var foot2 = document.getElementById("butong_net_left2");
        foot2.innerHTML = foot1.innerHTML;
        function Marquee3() {
            if (foot2.offsetWidth - foot.scrollLeft <= 0)
                foot.scrollLeft -= foot1.offsetWidth;
            else {
                foot.scrollLeft++;
            }
        }
        MyMar3 = setInterval(Marquee3, speed3);
        foot.onmouseover = function () { clearInterval(MyMar3); };
        foot.onmouseout = function () { MyMar3 = setInterval(Marquee3, speed3); };
    }


    SetInfoList();

};
function ClosedivBottom() {
    var BottomAd = document.getElementById("BottomAd");
    BottomAd.innerHTML = "";
    BottomAd.style.visibility = "hidden";
    window.onscroll = null;
}
function ClosedivLeft() {
    var LeftAd = document.getElementById("LeftAd");
    LeftAd.innerHTML = "";
    LeftAd.style.visibility = "hidden";
}
function ClosedivRight() {
    var RightAd = document.getElementById("RightAd");
    RightAd.innerHTML = "";
    RightAd.style.visibility = "hidden";
}
function ChangeMenuCass(obj) {

}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
    eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
    if (restore) selObj.selectedIndex = 0;
}
function SetInfoList() {

    
    var speed1 = 100;
    var colee2 = document.getElementById("colee2");
    var colee1 = document.getElementById("colee1");
    var colee = document.getElementById("colee");
    if (colee != null) {
        colee2.innerHTML = colee1.innerHTML; //克隆colee1为colee2
        function Marquee1() {
            //当滚动至colee1与colee2交界时
            if (colee2.offsetTop - colee.scrollTop <= 0) {
                colee.scrollTop -= colee1.offsetHeight; //colee跳到最顶端
            } else {
            colee.scrollTop++;
            }
        }
        MyMar1 = setInterval(Marquee1, speed1)//设置定时器
        //鼠标移上时清除定时器达到滚动停止的目的
        colee.onmouseover = function () { clearInterval(MyMar1); };
        //鼠标移开时重设定时器
        colee.onmouseout = function () { MyMar1 = setInterval(Marquee1, speed1); };

    }

    var speed = 10;
    var atab = document.getElementById("www_qpsh_com");
    if (atab != null) {
        var atab1 = document.getElementById("www_qpsh_com1");
        var atab2 = document.getElementById("www_qpsh_com2");
        atab2.innerHTML = atab1.innerHTML;
        function Marquee() {
            if (atab2.offsetWidth - atab.scrollLeft <= 0) {
                if (atab.scrollLeft != 0) {
                    atab.scrollLeft -= atab1.offsetWidth;
                }
            }
            else {
                atab.scrollLeft++;
            }
        }
        MyMar = setInterval(Marquee, speed);
        atab.onmouseover = function () { clearInterval(MyMar); };
        atab.onmouseout = function () { MyMar = setInterval(Marquee, speed); };
    }
    else {
        clearInterval(MyMar);
    }
}

function sc1() {
    var BottomAd = document.getElementById("BottomAd");
    BottomAd.style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - BottomAd.offsetHeight) - 10 + "px";
    BottomAd.style.left = document.documentElement.scrollLeft + (document.documentElement.clientWidth - BottomAd.offsetWidth) - 20 + "px";
    
}

function scall() {
    sc1();
}

function SeachNewsData(obj) {
    obj.href = "/Home/ShowSeachResult?val=" + textfield.value;
}

function buildsubmenus() {
    var menuids = ["suckertree1"];  //Enter id(s) of SuckerTree UL menus, separated by commas
    for (var i = 0; i < menuids.length; i++) {
        var ultags = document.getElementById(menuids[i]).getElementsByTagName("ul");
        for (var t = 0; t < ultags.length; t++) {
            ultags[t].parentNode.getElementsByTagName("a")[0].className = "subfolderstyle";
            ultags[t].parentNode.onmouseover = function () {
                this.getElementsByTagName("ul")[0].style.display = "block";
            }
            ultags[t].parentNode.onmouseout = function () {
                this.getElementsByTagName("ul")[0].style.display = "none";
            }
        }
    }
}
function submitbl(s) {
    $("#selInfoID").val(s);
    $('#frmSaveInfo').trigger('submit');
}
