SHCY.index = {};
$(document).ready(function(){
    $.each($('.leftBoxTr2 a'),function(i,obj){
        $('.leftBoxTr2 a:eq('+i+")").bind('mouseover',function(){
            $('.leftBoxPt1:eq('+i+")").animate( { bottom:"-10px" } , 500 ) ;
            $('.leftBoxPt2:eq('+i+")").fadeIn(1000) ;
			$('.leftBox:eq('+i+")").css('background-image','url(/SHCY/entry/images/leftpg2.jpg)');
        });
        $('.leftBoxTr2 a:eq('+i+")").bind('mouseout',function(){
            $('.leftBoxPt1:eq('+i+")").animate( { bottom:"-40px" } , 500 ) ;
            $('.leftBoxPt2:eq('+i+")").fadeOut(300) ;
			$('.leftBox:eq('+i+")").css('background-image','url(/SHCY/entry/images/leftpg1.jpg)');
        });
    });
	
	SHCY.accesscontrol({},
        "/SHCY/entry/Index",null);
    SHCY.accesscontrol({},
        "/SHCY/entry/TitleNews",SHCY.index.setTitleNews);
    SHCY.accesscontrol({},
        "/SHCY/entry/PhotoNews",SHCY.index.setPhotoList);
});

SHCY.index.startTheTitleScroll = function(){
    SHCY.index.titleScr = {
        speed:100,
        distance:1,
        target:$('.titleNewsContent2'),
        maxHeight:$('.titleNewsContent2 table:first').height(),
        myI:null,
        start:function(){
            with (SHCY.index.titleScr) {
                if (target.scrollTop() >= maxHeight) {
                    //初始化
                    target.scrollTop(0);
                } else {
                    //下一个
                    target.scrollTop(target.scrollTop()+distance);
                }
                myI = setTimeout(start, speed);
            }
        },
        stop:function(){
            with (SHCY.index.titleScr) {
                clearTimeout(myI);
            }
        }
    }
    SHCY.index.titleScr.start();
    $('.titleNewsContent2 table a').bind('mouseover',SHCY.index.titleScr.stop);
    $('.titleNewsContent2 table a').bind('mouseout',SHCY.index.titleScr.start);
}

SHCY.index.setTitleNews =function(data){
    if(!data || typeof data !="object"){
        return;
    }
    var length = 13;
    var table = $(".titleNewsContent2 table");
    $.each(data,function(i,news){
    	var oldTitle = news.ttn_title;
    	
        if(news.ttn_title.length >length){
            news.ttn_title = news.ttn_title.substring(0,length)+"...";
        }
        var child = 
            "<tr><td>· <a title='"+oldTitle+"' href='/SHCY/news/news1.html?ttn_id="+news.ttn_id+"'>["
            +news.ttn_date+"] "+news.ttn_title+"</a></td></tr>";
        table.append(child);
    });
    
    if(data.length >=6){
        $('.titleNewsContent2').append('<table></table>');
        $('.titleNewsContent2 table:last-child').append($(".titleNewsContent2 table:first").html());
        SHCY.index.startTheTitleScroll();
    }
};

SHCY.index.setPhotoList=function(data){
    if(!data || typeof data !="object"){
        return;
    }
    var table = $("div.phcontainer");
    $.each(data,function(i,obj){
        var child = 
            "<div class='flash'><a href='/SHCY/news/news1.html?ttn_id="+obj.ttn_id+"'>"
            +"<img src='/SHCY/entry/PhotoNews?tnp_id="+obj.tnp_id+"'/></a></div>";
			// onload='SHCY.common.setSize(this,250,190,true);'设置图片大小的函数
        table.append(child);
		$('.tailContent a:eq('+i+')').removeClass('hideST');
    });
    
    $("div.photoBox").scrollable({
            vertical:true,
            size: 1,
            speed:1000})
            .circular()
            .autoscroll({autoplay: true,interval:4000})
            .navigator({navi:'.tailContent',activeClass:'navitive'});
};

