(function () {
	function $(id) {
		return typeof(id) == 'string' ? document.getElementById(id) : id;
	}
    function $C(o){
        return document.createElement(o);
    }
	var FocusPic = {
		MaxScreen : 7,
		CurScreen : 0,
		Width : 240,
		Height : 200,
		changeTime : 5000,
		FocusObj : null,
		Pics : "",
		Titles : "",
		STitles : "",
		Links : "",
		lnum : 0,
		_obj_pic : null,
		_obj_num : null,
		_obj_tit : null,
		refreshTimer : 0,
		init : function(){
			this.lnum ++;
			this.FocusObj = $(this.FocusObj);
			this.Pics = this.Pics.split("|");
			this.Titles = this.Titles.split("|");
			this.STitles = this.STitles.split("|");
			this.Links = this.Links.split("|");
			if(this.Titles.length < this.MaxScreen) this.MaxScreen = this.Titles.length;
			
			this.CreateStyle();
			this.CreatePicBox();
			this.switchPic(this.CurScreen);
			this.refreshSwitchTimer = setTimeout('FocusPic.reSwitchPic();', this.changeTime);
		},
		CreateStyle : function(){
			var styleStr = "";
			styleStr += ".gee_foucspic_box { height:"+this.Height+"px; width:"+this.Width+"px; position:relative; }";
			styleStr += ".gee_foucstit { position:absolute; overflow:hidden; bottom:0;_bottom:-1px; width:100%; left:0; padding:0px 0 0px; margin-bottom:17px; z-index:998;}";
			styleStr += ".gee_foucstit:after {content:\".\";display:block;height:0;clear:both;visibility:hidden;}";
			
			styleStr += ".gee_foucstit_mask { height:"+this.Height+"px; position:absolute;left:0;top:0;width:100%;z-index:999;text-indent:-999em; background:#000; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50); -moz-opacity:.5; opacity:0.5;}";
			
			styleStr += ".gee_foucstit_n { position:relative;z-index:1000;float:left; display:inline;}";
			styleStr += ".gee_foucstit_n h3{ line-height:28px; height:25px; font-size:18px; overflow:hidden; display:inline; padding:0 12px; margin:0; font-family:\"黑体\"; font-weight:lighter;}";
			styleStr += ".gee_foucstit_n p{ line-height:20px; font-size:12px; padding:0 12px; margin:0;}";
			styleStr += ".gee_foucstit_n a { color:#FFF !important; text-decoration:none;}";
			styleStr += ".gee_foucstit_n a:hover { text-decoration:underline;}";
			
			styleStr += ".gee_foucspic,.gee_foucspicnum { margin:0; padding:0; list-style:none; position:absolute;}";
			styleStr += ".gee_foucspic { left:0;}";

			styleStr += ".gee_foucspic ul,.gee_foucspic li { display:inline;}";
			
			styleStr += ".gee_foucspicnum { height:16px; line-height:16px; right:0; bottom:0;_bottom:-1px; z-index:1001; }";
			styleStr += ".gee_foucspicnum li { float:left; font-size:12px; font-family:Verdana; margin-left:1px; display:inline;}";
			styleStr += ".gee_foucspicnum li a { color:#FFF !important; padding:0 6px; text-decoration:none; font-size:10px; background:#000; display:block;}";
			styleStr += ".gee_foucspicnum li a:hover { text-decoration:none; background:#FF0000;}";
			styleStr += ".gee_foucspicnum li.at a { background:#FF0000;}";

			
			var styleId = "FocusPicSheet";
			var _head = document.getElementsByTagName("head").item(0);
			var _old = document.getElementById(styleId);
			if (_old) _head.removeChild(_old);
			var mystyle = document.createElement("style");
			mystyle.type = "text/css";
			mystyle.id = styleId;
			if(mystyle.styleSheet){// IE
				mystyle.styleSheet.cssText = styleStr;
			} else {// w3c
				var cssText = document.createTextNode(styleStr);
				mystyle.appendChild(cssText);
			}
			_head.appendChild(mystyle);
		},
		CreatePicBox : function(){
			var PicBox = $C("div");
			PicBox.className = "gee_foucspic_box";
			//图片显示
			this._obj_pic = $C("ul");
			this._obj_pic.id = "_foucspic_ul_" + this.lnum;
			this._obj_pic.className = "gee_foucspic";
			var liHtml = "";
			for(var i in this.Pics){
				if(i <= 0) liHtml += "<li>";
				else  liHtml += "<li style=\"display:none;\">";
				liHtml += "<a href=\"" + this.Links[i] + "\" target=\"_blank\"><img src=\"" + this.Pics[i] + "\" width=\"" + this.Width + "\" height=\"" + this.Height + "\" border=\"0\" onmouseover=\"FocusPic.pause();\" onmouseout=\"FocusPic.goon();\" /></a></li>";
			}
			this._obj_pic.innerHTML = liHtml;
			PicBox.appendChild(this._obj_pic);
			//滚动数字
			this._obj_num = $C("ul");
			this._obj_num.id = "_foucspicnum_ul_" + this.lnum;
			this._obj_num.className = "gee_foucspicnum";
			var NavStr = "" ;
			for (i = 1; i <= this.MaxScreen; i++) {
				if (i == 1) {
					NavStr += '<li onmouseover="FocusPic.pause();" onmouseout="FocusPic.goon();" onclick="FocusPic.goSwitch('+(i-1)+');" class="at"><a href="javascript:void(0);" target="_self">'+i+'</a></li>' ;
				}
				else {
					NavStr += '<li onmouseover="FocusPic.pause();" onmouseout="FocusPic.goon();" onclick="FocusPic.goSwitch('+(i-1)+');"><a href="javascript:void(0);" target="_self">'+i+'</a></li>' ;
				}
				
			}
			this._obj_num.innerHTML = NavStr;
			PicBox.appendChild(this._obj_num);
			//标题部分
			var titDiv = $C("div");
			titDiv.className = "gee_foucstit";
			
			var maskDiv = $C("div");
			maskDiv.className = "gee_foucstit_mask";
			titDiv.appendChild(maskDiv);
			
			this._obj_tit = $C("div");
			this._obj_tit.id = "_foucspictit_" + this.lnum;
			this._obj_tit.className = "gee_foucstit_n";
			titDiv.appendChild(this._obj_tit);
			
			PicBox.appendChild(titDiv);
			
			this.FocusObj.appendChild(PicBox);
		},
		switchPic : function (index) {
			if (index > this.MaxScreen) {
				index = 1 ;
			}
			var _obj_pic_li = this._obj_pic.getElementsByTagName("li");
			for (var i = 0; i < this.MaxScreen; i++) {
				_obj_pic_li[i].style.display = "none";
			}
			_obj_pic_li[index].style.display = "block";
			this.showSwitchNav(index);
			this.showSwitchTitle(index);
			this.CurScreen = index;
		},
		showSwitchTitle : function(index) {
			var titlestr = "";
			if(this.Titles[index]!="" && this.Titles[index].length>0){
				titlestr += "<h3><a href=\""+this.Links[index]+"\" target=\"_blank\">" + this.Titles[index] + "</a></h3>";
				if(this.STitles!="" && this.STitles.length > 0){
					titlestr += '<p><a href="'+this.Links[index]+'" target="_blank">' + this.STitles[index] + '</a></p>';
				}
				this._obj_tit.parentNode.firstChild.style.display = "";
			}else{
				this._obj_tit.parentNode.firstChild.style.display = "none";
			}
			this._obj_tit.innerHTML = titlestr;
		},
		showSwitchNav : function(index){
			var _obj_num_li = this._obj_num.getElementsByTagName("li");
			for (var i = 0; i < this.MaxScreen; i++) {
				_obj_num_li[i].className = "";
			}
			_obj_num_li[index].className = "at";
		},
		reSwitchPic : function () {
			this.refreshSwitchTimer = null;
			this.CurScreen = this.CurScreen + 1;
			if(this.CurScreen >= this.MaxScreen) this.CurScreen = 0;
			this.switchPic(this.CurScreen);
			this.refreshSwitchTimer = setTimeout('FocusPic.reSwitchPic();', this.changeTime);
		},
		pause : function(){
			clearTimeout(this.refreshSwitchTimer);
		},
		goon : function(){
			clearTimeout(this.refreshSwitchTimer);
			this.refreshSwitchTimer = setTimeout('FocusPic.reSwitchPic();', this.changeTime);
		},
		goSwitch : function (index) {
			clearTimeout(this.refreshSwitchTimer);
			this.CurScreen = index - 1;
			this.reSwitchPic();
		}
	};
	window.FocusPic = FocusPic;
})();
