﻿(function($){
		$.fn.slide = function(options){
		var defaults = {
			slideWidth: 890,
			autoplay: true,
			duration: 15000,
			showSlideIndex: false
		};
		var options = $.extend(defaults, options);
		return this.each(function(){
		  	var slideshow = $(this);
			var o = options;
			var currentPosition = 0;
			var slides = $('.slide');
			var numberOfSlides = slides.length;
			  
			// Remove scrollbar in JS
			$('#slidesContainer').css('overflow', 'hidden');

			// Wrap all .slides with #slideInner div
			slides.wrapAll('<div id="slideInner"></div>')
			
			// Float left to display horizontally, readjust .slides width
			.css({
				 'float' : 'left',
				 'width' : o.slideWidth
			});
			
			// Insert a clone of first slide 
			$('.slide:first').clone().appendTo('#slideInner');
			  
			// Set #slideInner width equal to total width of all slides
			$('#slideInner').css('width', o.slideWidth * (numberOfSlides+1));

			// Insert controls in the DOM
			slideshow
				.prepend('<span class="control" id="leftControl"></span>')
				.append('<span class="control" id="rightControl"></span>');

			// Insert slides index
			if(o.showSlideIndex==true)
			{
				slideshow.append('<div id="slideIndex"></div>');
				for(var i=1; i<= numberOfSlides; i++)
				{
					$('#slideIndex').append('<span id="slide-' + i + '" class="numbers">' + i + '</span>' );
				}
				$('.numbers').click(function(){ goto( ($(this).attr('id')).replace('slide-','') - 1, false)});
			}
	
			// Create event listeners for .controls clicks
			$('#leftControl').click(function(){ prev()});
			$('#rightControl').click(function(){ next()});
		  
			// Start
			init();
			
			//Init function
			function init()
			{
				manageControls(currentPosition);
				if(o.autoplay==true) setNextTimeOut(o.duration);
			}
			
			// Next
			function next()
			{
				currentPosition++;
				if(currentPosition >= numberOfSlides) currentPosition=0;
				slideTo(currentPosition, true);
			}
		  
			// Previous
			function prev()
			{
				currentPosition--;
				if(currentPosition <0) currentPosition=numberOfSlides-1;
				slideTo(currentPosition, false);
			}
			
			// Go to a slide 
			function goto(position)
			{
				currentPosition=position;
				slideTo(currentPosition, false);
			}
			
			// Set time out for next slide
			function setNextTimeOut(time)
			{
				$('#slidesContainer').stop();
				// Just a crap animation to get timer, I got problem with setTimeout
				$('#slidesContainer').animate({optical: 1}, time, '', function(){next();});
			}
		  
			// Slide
			function slideTo(position, continuously)
			{
				$('#slideInner').stop();
				// usual cases
				if(continuously==false || o.autoplay==false || position!=0)
				{
					$('#slideInner').animate({'marginLeft' : o.slideWidth*(-position)},'', '', 
						function(){ 
							manageControls(position);
							if(o.autoplay==true) setNextTimeOut(o.duration);
						}
					)
				}
				// autoplay: slide from last to first one continuously
				else
				{
					// slide to the 'fake' first slide (actually at the last)
					$('#slideInner').animate({'marginLeft' : o.slideWidth*(-numberOfSlides)},'', '', 
						function(){ 
							//immediately change to the 'true' first slide
							$('#slideInner').css('marginLeft',0);
							manageControls(position)
							if(o.autoplay==true) setNextTimeOut(o.duration);
						}
					)
				}
			}
			
			// manageControls: Hides and Shows controls depending on currentPosition
			function manageControls(position)
			{
				// Hide left arrow if position is first slide
				if(position==0){ $('#leftControl').show() } else{ $('#leftControl').show() };
				// Hide right arrow if position is last slide
				if(position==(numberOfSlides-1)){ $('#rightControl').show() } else{ $('#rightControl').show() };
				// Hilight the current page
				if(o.showSlideIndex==true)
				{
					// remove active class from all pages
					$('.numbers').removeClass("active");
					// add only to the current page
					$('#slide-' + (position +1)).addClass("active");
				}
			}
		});
		};
})(jQuery);


function getInfo(dotype) {

    $.get("/ajax/time.aspx", { ids: dotype, datatype: 'ajax', 'rand': Math.random() },
			   function (data) {
			       if (data) {
			           eval('var dataobj=' + data);

			           document.getElementById("lefttime").innerHTML=parseDataAction(dataobj);
			       }
			   }
			);
        
        setTimeout(function () { getInfo(dotype); }, 1000);

    }

    function parseDataAction(ms) {
        if (ms <= 0) return "已经结束";
        var rr = "";
        if (ms >= 86400) {
            rr = rr + String(Math.floor(ms / 86400)) + "天";
            ms = ms % 86400;
        }
        if (ms >= 3600) {
            rr = rr + String(Math.floor(ms / 3600)) + "时";
            ms = ms % 3600;
        }

        if (ms >= 60) {
            rr = rr + String(Math.floor(ms / 60)) + "分";
            ms = ms % 60;
        }
        rr = rr + String(ms) + "秒";
        return rr;
    }

    var userAgent = navigator.userAgent.toLowerCase();
    var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
    var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
    var is_safari = (userAgent.indexOf('webkit') != -1 || userAgent.indexOf('safari') != -1);
    var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);
function CenterWindowcase(id, height, width) {
        showcDiv("<div style=\" width:100px; margin:0 auto;\">loading...</div>", width);

        jQuery.get("/ajax/caseview.aspx", { ids: id, heights: height, widths: width, time: (new Date().getTime()) },
    function (data) {
        var returnvalue = data;
        if (returnvalue.indexOf("??") > -1)
            showcDiv('Error', width);
        else
            var tempstr = returnvalue;
        showcDiv(tempstr, width);
    });
}
function CenterWindowbaodao(id, height, width) {
    showcDiv("<div style=\" width:100px; margin:0 auto;\">loading...</div>", width);

    jQuery.get("/ajax/baodaoview.aspx", { ids: id, heights: height, widths: width, time: (new Date().getTime()) },
    function (data) {
        var returnvalue = data;
        if (returnvalue.indexOf("??") > -1)
            showcDiv('Error', width);
        else
            var tempstr = returnvalue;
        showcDiv(tempstr, width);
    });
}
function CenterWindowdevice(id, height, width) {
    showcDiv("<div style=\" width:100px; margin:0 auto;\">loading...</div>", width);

    jQuery.get("/ajax/deviceview.aspx", { ids: id, heights: height, widths: width, time: (new Date().getTime()) },
    function (data) {
        var returnvalue = data;
        if (returnvalue.indexOf("??") > -1)
            showcDiv('Error', width);
        else
            var tempstr = returnvalue;
        showcDiv(tempstr, width);
    });
}
function showcDiv(content, width) {

    var objDiv = document.getElementById("s_id");
    if (objDiv == null) {
        objDiv = document.createElement("div");
        objDiv.id = "s_id";
    }
    objDiv.className = "selectStyle";
    objDiv.style.position = "absolute";
    objDiv.style.zIndex = 100;

    var isIE5 = (navigator.appVersion.indexOf("MSIE 5") > 0) || (navigator.appVersion.indexOf("MSIE") > 0 && parseInt(navigator.appVersion) > 4);
    var isIE55 = (navigator.appVersion.indexOf("MSIE 5.5") > 0);
    var isIE6 = (navigator.appVersion.indexOf("MSIE 6") > 0);
    var isIE7 = (navigator.appVersion.indexOf("MSIE 7") > 0);

    objDiv.style.width = width + "px";

    objDiv.innerHTML = content;

    var scrolltop = document.documentElement.scrollTop;
    if (scrolltop == 0) {
        scrolltop = document.body.scrollTop;
    }
    var ofHeight = document.documentElement.clientHeight;
    if (ofHeight > window.screen.availHeight) ofHeight = window.screen.availHeight;
    var scrollTop = scrolltop;
    if (scrollTop == 0) {
        try {
            scrollTop = parent.document.documentElement.scrollTop;
        } catch (e) { }
    }
    var top = (ofHeight) / 2 - objDiv.offsetHeight / 2 + scrollTop - 50;
    var left = document.documentElement.offsetWidth / 2 - width / 2;
    objDiv.style.top = top + "px";
    objDiv.style.left = left + "px";

    var the = this;
    this.Zhezhao = true;
    if (the.Zhezhao) {
        //遮照层
        var divID = "s_id_zhezhao";
        var ExsitDivObj = document.getElementById(divID);
        if (ExsitDivObj != null) ExsitDivObj.parentNode.removeChild(ExsitDivObj);
        var objDiv1 = document.createElement("div");
        objDiv1.id = divID;
        objDiv1.style.position = "absolute";
        document.body.appendChild(objDiv1);
        var w = (document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth);
        var h = "";
        var _cHeight = document.documentElement.clientHeight;
        var _sHeight = document.documentElement.scrollHeight;
        if (_cHeight > _sHeight)
            h = _cHeight;
        else
            h = _sHeight;

        var x = 0;
        var y = 0;
        var z = 99;
        var backcolor = "#000000";
        objDiv1.style.filter = "alpha(opacity=70);";
        if (is_moz || is_opera || is_safari) {
            objDiv1.setAttribute("style", "position:absolute;width:" + w + "px;height:" + h + "px;top:" + y + "px;left:" + x + "px;z-index:" + z + ";background-color:#243768;-moz-opacity:0.7;opacity: 0.7;");
        }
        objDiv1.style.backgroundColor = backcolor;
        objDiv1.style.top = y + 'px';
        objDiv1.style.left = x + 'px';
        objDiv1.style.width = w + "px";
        objDiv1.style.height = h + "px";

        objDiv1.style.zIndex = z;
    }
    objDiv.style.display = "";
    //document.ondblclick = function () { closediv() }
    document.body.appendChild(objDiv);
}


drag = function (a, o) {
    var d = document; if (!a) a = window.event;
    if (!a.pageX) a.pageX = a.clientX;
    if (!a.pageY) a.pageY = a.clientY;
    var x = a.pageX, y = a.pageY;
    if (o.setCapture)
        o.setCapture();
    else if (window.captureEvents)
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    var backData = { x: o.style.top, y: o.style.left };
    d.onmousemove = function (a) {
        if (!a) a = window.event;
        if (!a.pageX) a.pageX = a.clientX;
        if (!a.pageY) a.pageY = a.clientY;
        var tx = a.pageX - x + parseInt(o.style.left), ty = a.pageY - y + parseInt(o.style.top);
        o.style.left = tx + "px";
        o.style.top = ty + "px";
        x = a.pageX;
        y = a.pageY;
    };

    d.onmouseup = function (a) {
        if (!a) a = window.event;
        if (o.releaseCapture)
            o.releaseCapture();
        else if (window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
        d.onmousemove = null;
        d.onmouseup = null;
        if (!a.pageX) a.pageX = a.clientX;
        if (!a.pageY) a.pageY = a.clientY;
        if (!document.body.pageWidth) document.body.pageWidth = document.body.clientWidth;
        if (!document.body.pageHeight) document.body.pageHeight = document.body.clientHeight;
        if (a.pageX < 1 || a.pageY < 1 || a.pageX > document.body.pageWidth || a.pageY > document.body.pageHeight) {
            o.style.left = backData.y;
            o.style.top = backData.x;
        }
    };
}
function closediv() {
    var objDiv = document.getElementById('s_id');
    if (objDiv != null && objDiv != "undefined") {
        document.body.removeChild(objDiv);
    }
    var div = document.getElementById("s_id_zhezhao");
    if (div) { div.parentNode.removeChild(div); }
}
function pubajax(url, id, divID) {
    $.ajax({
        type: "get",
        datatype: "json",
        data: "ids=" + id,
        url: url + "?time=" + (new Date().getTime()),
        error: function () {
            alert("读取数据有误,请稍候重试", "0");
        },
        success: function (d) {
            document.getElementById(divID).innerHTML = d;
        }
    });
}

function cookieajax(url, id) {
    $.ajax({
        type: "get",
        datatype: "json",
        data: "ids=" + id,
        url: url + "?time=" + (new Date().getTime()),
        error: function () {
            alert("读取数据有误,请稍候重试", "0");
        },
        success: function (d) {
            //document.getElementById(divID).innerHTML = d;
        }
    });
}
function showNav() {
    $(".openClose").toggle();
}
function closeNav() {
    $(".openClose").toggle();
}
