$(document).ready(function(){
			jQuery.ajaxSetup({cache : false});
			
			
		
			//头条新闻
			$.ajax({
				type:'post',
				url:'/scpost/newAjax/news!findTitleNews.action',
				data:{recommend:'1'},
				dataType:'json',
				success:function(data){
					var news = data.newBeanCondition;
					if(news!=null){
						var newhtml='<a title='+news.newsTitle+' target="_blank" href="/scpost/news/news!findNewsBeanById.action?newsId='+news.newsId+'">'+news.newsTitle+'</a>';
						$('#titleNems').append(newhtml);
					}
				}
			});
		
			//首页加载新闻
			$.ajax({
				type:'post',
				url:'/scpost/newAjax/news!findNewsForList.action',
				data:{recommend:'1'},
				dataType:'json',
				success:function(data){
					if(data.newList.length!=0)
						{
						$('#newsList').empty();
						var news = data.newList;
						//alert(news.length)
						var newhtml = '';
						for(var i=0;i<news.length;i++)
							{
							newhtml+=' <li><a title='+news[i].newsTitle+' target="_blank" href="/scpost/news/news!findNewsBeanById.action?newsId='+news[i].newsId+'">'+news[i].newsTitle+'</a></li>';
							}
						$('#newsList').append(newhtml);
						}					
				},
				error:function(){
					alert("加载首页新闻失败!");
				}
			});
			// 图片新闻
			$.ajax({
				type:'post',
				url:'/scpost/newAjax/news!findImageNews.action',
				data:{recommend:'1'},
				dataType:'json',
				success:function(data){
					if(data.newList.length!=0)
					{
	
					var news = data.newList;
					var imageHtml = '';  //图片
					var imageIndex = ''; //下标
					var path = $('#path').val();
					for(var i=0;i<news.length;i++)
						{
						
						imageHtml += '<li>'
						            + '<a href="/scpost/news/news!findNewsBeanById.action?newsId='
						            + news[i].newsId +'"  target="_blank">'
						            + '<img  src='+news[i].indexImage+' style="width:509px;height:296px;"/>'
						            + '<p>'+news[i].newsTitle+'</p>'
					                + '</a>'
				                    + '</li>';
						imageIndex +='<span class="on">'+ (i+1) +'</span>';
						}
					$('#imageNews').empty().append(imageHtml);
                    $('#imageIndex').empty().append(imageIndex);
					var player1 = new player('focus');
					}
				}
			});
			
			//首页视频
			$.ajax({
				type:'post',
				url:'/scpost/videos_json/videos!findVideoIndex.action',
				data:{},
				dataType:'json',
				success:function(data){
					var videoItem = data.videoItem;

					if(videoItem==null)
						{
						$('#player1t').attr('href','/scpost/video/001.flv');
						}
					else
						{
						var path = $('#path').val();
						
						path = 'http://'+'localhost'+videoItem.videoPath;
					    $('#player1t').attr('href',path);
						}
					
					flowplayer("player1t", "/scpost/js/flowplayer-3.2.7.swf",{
						clip:{
								autoPlay:true,
								autoBuffering:true
							}	
						});
				}
			});
			 //查询单页管理
			$.ajax({
				type:'post',
				url:'/scpost/newAjax/news!findSingLepage.action',
				data:{},
				dataType:'json',
				success:function(data)
				{
					if(data.singBean.pageUrl == null)
						{
						return false;
						}
					if(data.singBean.pageUrl!=null)
						{
						$('#singLepage').attr("href",data.singBean.pageUrl);
						}
					
				}
			});	
    
			
			
});
(function(){
    if(!Function.prototype.bind){
        Function.prototype.bind = function(obj){
            var owner = this,args = Array.prototype.slice.call(arguments),callobj = Array.prototype.shift.call(args);
            return function(e){e=e||top.window.event||window.event;owner.apply(callobj,args.concat([e]));};
        };
    }
})();
var player = function(id){
    this.ctn = document.getElementById(id);
    this.adLis = null;
    this.btns = null;
    this.animStep = 0.2;//动画速度0.1～0.9
    this.switchSpeed = 3;//自动播放间隔(s)
    this.defOpacity = 1;
    this.tmpOpacity = 1;
    this.crtIndex = 0;
    this.crtLi = null;
    this.adLength = 0;
    this.timerAnim = null;
    this.timerSwitch = null;
    this.init();
};
player.prototype = {
    fnAnim:function(toIndex){
        if(this.timerAnim){window.clearTimeout(this.timerAnim);}
        if(this.tmpOpacity <= 0){
            this.crtLi.style.opacity = this.tmpOpacity = this.defOpacity;
            this.crtLi.style.filter = 'Alpha(Opacity=' + this.defOpacity*100 + ')';
            this.crtLi.style.zIndex = 0;
            this.crtIndex = toIndex;
            return;
        }
        this.crtLi.style.opacity = this.tmpOpacity = this.tmpOpacity - this.animStep;
        this.crtLi.style.filter = 'Alpha(Opacity=' + this.tmpOpacity*100 + ')';
        this.timerAnim = window.setTimeout(this.fnAnim.bind(this,toIndex),50);
    },
    fnNextIndex:function(){
        return (this.crtIndex >= this.adLength-1)?0:this.crtIndex+1;
    },
    fnSwitch:function(toIndex){
        if(this.crtIndex==toIndex){return;}
        this.crtLi = this.adLis[this.crtIndex];
        for(var i=0;i<this.adLength;i++){
            this.adLis[i].style.zIndex = 0;
        }
        this.crtLi.style.zIndex = 2;
        this.adLis[toIndex].style.zIndex = 1;
        for(var i=0;i<this.adLength;i++){
            this.btns[i].className = '';
        }
        this.btns[toIndex].className = 'on'
        this.fnAnim(toIndex);
    },
    fnAutoPlay:function(){
        this.fnSwitch(this.fnNextIndex());
    },
    fnPlay:function(){
        this.timerSwitch = window.setInterval(this.fnAutoPlay.bind(this),this.switchSpeed*1000);
    },
    fnStopPlay:function(){
        window.clearTimeout(this.timerSwitch);
    },
    init:function(){
        this.adLis = this.ctn.getElementsByTagName('li');
        this.btns = this.ctn.getElementsByTagName('cite')[0].getElementsByTagName('span');
        this.adLength = this.adLis.length;
        for(var i=0,l=this.btns.length;i<l;i++){
            with({i:i}){
                this.btns[i].index = i;
                this.btns[i].onclick = this.fnSwitch.bind(this,i);
                this.btns[i].onclick = this.fnSwitch.bind(this,i);
            }
        }
        this.adLis[this.crtIndex].style.zIndex = 2;
        this.fnPlay();
        this.ctn.onmouseover = this.fnStopPlay.bind(this);
        this.ctn.onmouseout = this.fnPlay.bind(this);
    }
};

