// Author By Joassa
jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
    this.css("display", "block");
    this.css("z-index", "11")
    return this;
}
jQuery.fn.loadthumb = function (options) {
    options = $.extend({
        src: ""
    }, options);
    var _self = this;
    _self.hide();
    var img = new Image();
    $(img).load(function () {
        _self.attr("src", options.src);
        _self.fadeIn("slow");
    }).attr("src", options.src);
    return _self;
}
var attrLeft = 0;
var timer = 500;
var constWid = 657;
$(function () {
	$.autoFn(obj);
    $("#showCeng").height($(document).height());
    $(document).pngFix();
    var obj_a = $(".cpbanner");
    var n = 0;
    var maxn = 2;
    $.left = function (e) {
        n = n == 0 ? maxn : (n -= 1);
        $.showImg(e);
    }
    $.right = function (e) {
        n = n == maxn ? 0 : (n += 1);
        $.showImg(e);
    }

    $.showImg = function (a) {
        $(a).hide().eq(n).fadeIn();
    }



    var wid = 0;
    var len = $(".imgMove").length;
    for (var i = 0; i < len; i++) {
        wid += constWid;
    }
    setInterval(function () {
        attrLeft -= constWid;
        setTimeout($("#innerDiv").animate({ left: attrLeft + 'px' }, timer), timer * 2);
        if (attrLeft <= -wid) {
            attrLeft = 0;
            $("#innerDiv").animate({ left: attrLeft + 'px' }, timer)
        }
        return false;
    }, timer * 10);
    $("#innerDiv").css("width", wid + "px");
    $(".filter").fadeTo("fast", 0.5, function () {
        $(this).prev().find("h5").show(timer);
        return false;
    });
})

function right() {
    var len = $(".imgMove").length;
    attrLeft -= constWid;
    if (attrLeft <= (-constWid * len)) {
        $("#innerDiv").animate({ left: '0px' }, timer);
        attrLeft = 0;
        return false;
    }
    else {
        $("#innerDiv").animate({ left: attrLeft + 'px' }, timer);
        return false;
    }
}
function left() {
	
    var len = $(".imgMove").length;
    attrLeft += constWid;
    if (attrLeft >= constWid) {
        $("#innerDiv").animate({ left: (-attrLeft * (len - 1)) + 'px' }, timer);
        attrLeft = -attrLeft * (len - 1);
        return false;
    }
    else {
        $("#innerDiv").animate({ left: attrLeft + 'px' }, timer);
        return false;
    }
}
function leftOn(e) {
    $(e).hover(function () {
        $(e).attr("src", "images/left_on.png");
    }, function () {
        $(e).attr("src", "images/left.png");
    });
}
function rightOn(e) {
    $(e).hover(function () {
        $(e).attr("src", "images/right_on.png");
    }, function () {
        $(e).attr("src", "images/right.png");
    });
}

function show_img_x(src_x) {
    $("#showCeng").css("display", "block").fadeTo(500, 0.5, function () {
        $("#showinfo").center().find("img:first").attr("src", src_x);
    });
}

function close_img() {
    $("#showCeng").fadeTo(500, 0).css("display", "none");
    $("#showinfo").css("display", "none");
}

var i = 0;
var timer = 500;
var obj = ".cpbanner";


$.autoFn = function (e) {
    setInterval(function () {
        setTimeout($(e).animate({ opacity: '0.6' }, timer, function () {
            $(e).css("display", "none").eq(i).css("display", "block").animate({ opacity: '1' }, timer);
        }), timer * 10);
		//alert(i)
        ++i;
        if (i == 3) {
            i = 0;
            $(e).animate({ opacity: '1' }, '', function () {
                $(e).eq(i).fadeIn();
            })
        }
    }, timer * 10)
}


function turnleft()
{
	i = i>0 ? (i-=1) : 0;
	$(obj).css("display", "none").eq(i).css("display", "block").animate({ opacity: '1' }, timer);
}

function turnright()
{
	i = i<2 ? (i+=1) : 2;
	$(obj).css("display", "none").eq(i).css("display", "block").animate({ opacity: '1' }, timer);
}

