/**
 * 图片轮播
 */
function slider(property){
    this.wrap = property.wrap;
    this.sliderBox = property.sliderBox;
    this.sliderNumBox = property.sliderNum;
    this.curClass = property.curClass;
    this.speed = property.speed ? this.speed = property.speed : this.speed;
    this.thumbnail = property.thumbnail;
    this.init();
}
slider.prototype = {
    counter : 0,
    speed : 3000,
    outBox : null,
    sliderBox : null,
    sliderNumBox : null,
    sliderSize : function(){return $(this.sliderBox + ' li').length},
    objHeight : function(){return $(this.sliderBox + ' li').height()},
    delayed : null,
    thumbnail : false,
    init : function(){
        $('<ul id="'+this.sliderNumBox.substring(1)+'"></ul>').appendTo($(this.wrap));
        for(var i=1; i < this.sliderSize() + 1; i++){
            if(this.thumbnail){
                var imgSrc = $(this.sliderBox + ' li img').eq(i-1).attr('src');
                $('<li id="'+i+'"><img src="'+imgSrc+'" alt="" /></li>').appendTo($(this.sliderNumBox));
            }else{
                $('<li id="'+i+'">'+i+'</li>').appendTo($(this.sliderNumBox)); 
            }
        }
        $(this.sliderNumBox + ' li:first').addClass(this.curClass);
        this.auto();
    },
    slider : function(){
        var thisObj = this;
        if(this.counter <= $(this.sliderBox + ' li').length - 2){
            thisObj.counter++;
            $(thisObj.sliderNumBox + ' li').removeClass();
            $(thisObj.sliderNumBox + ' li').eq(thisObj.counter).addClass(this.curClass);
            $(this.sliderBox).animate({top : '-=' + thisObj.objHeight() + 'px'},'fast');  
        }else{
            thisObj.counter = 0;  
            $(thisObj.sliderNumBox + ' li').removeClass();
            $(thisObj.sliderNumBox + ' li').eq(thisObj.counter).addClass(this.curClass);
            $(this.sliderBox).animate({top : '0px'},'slow');
        }
    },
    auto : function(){
        var thisObj = this;
        thisObj.delayed = setInterval(function(){thisObj.slider()},thisObj.speed);
        $(thisObj.sliderNumBox + ' li').hover(
            function(){
                clearInterval(thisObj.delayed);
                thisObj.counter = $(this).attr('id');
                $(thisObj.sliderNumBox + ' li').removeClass();
                $(this).addClass(thisObj.curClass);
                if(thisObj.counter > 1){
                    $(thisObj.sliderBox).animate({top : '-' + thisObj.objHeight() * (thisObj.counter - 1) + 'px'},'fast');  
                }else{
                    $(thisObj.sliderBox).animate({top : '0px'},'fast');   
                }
            },
            function(){
                thisObj.counter--;
                thisObj.delayed = setInterval(function(){thisObj.slider()},thisObj.speed);  
            }
        );
    }
}
/**
 * 选项卡
 */
function tabHandler(tabMenu,tabCon,curClass){
	$(tabMenu).mouseover(function(){
		$(tabMenu).removeClass();
		$(this).addClass(curClass);
		$("div[id^='"+ tabCon +"']").hide();
		$("#"+tabCon+this.id).show();
	});
}

/**
 * Accordion
 */
function accordion(){
	$("#sideWrap h4").click(function(){
		$("#sideWrap h4 span").removeClass().addClass("aclose");
		$(this).find("span").removeClass().addClass("aopen");
		$("#sideWrap .accCon").hide();
		$(this).next(".accCon").show();
	});
}
/**
 * Get DDZ data
 */
var newestTrends = {
	speed : 3000,
	count : 0,
	container : "#roll ul",
	listContainer : ".topNewsList",
	delayed : null,
	init : function(){
		var to = this;
		this.getData();
		this.delayed = setInterval(function(){to.roll()},to.speed);
	},
	getData : function(){
		var to = this;
		$.getScript("http://ddz.lianzhong.com/Open/DynamicMessagesTop.aspx",function(){
			to.showList(wghAjaxResult.value);
		});
	},
	showList : function(data){
		var to = this;
		var s = "";
		$.each(data,function(i,j){
			s += "<li class='og-clear' id='"+i+"'><div class='headPic'><img src='"+j.Header+"' alt='"+j.UserID+"' /></div><div class='newsSum'><span class='pLink'>"+j.UserID+"</span><p class='msgBox'>"+ j.Message +"</p></div></li>";
		});
		if($(to.listContainer).html() != ""){
			$(to.listContainer).html($(to.listContainer).html() + s);
		}else{
			$(to.listContainer).html(s);
		}
		$("#testbb").html(s);
		/*$(to.container+ " li").hover(
			function(){
				clearInterval(to.delayed);	
				return false;
			},
			function(){
				to.delayed = setInterval(function(){to.roll()},to.speed);
				return true;
			}	
		);*/
	},
	roll : function(){
		var to = this;
		$(this.container).animate({top : "-="+83+"px"},"slow",function(){
			to.count++;
			var l = $(to.container+" li").length - 3;
			if(to.count==l){
				to.getData();
				$(to.container+" li").slice(0,l).remove();
				$(to.container).css("top","0px");
				to.count = 0;
			}
		});
		
	}
	
}


