/* 
 * Create HTML5 elements for IE's sake
 * Reference: http://ejohn.org/blog/html5-shiv/
 * Reference: http://remysharp.com/2009/01/07/html5-enabling-script/
 */
document.createElement("article");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("nav");
document.createElement("section");
document.createElement("aside");

//分享代码
function goQQ(){
        window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)+'&uri='+encodeURIComponent(window.location.href)+'&jumpback=2&noui=1')
}
function goRenren(){
        window.open('http://share.renren.com/share/buttonshare.do?link='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&content='+encodeURIComponent(document.title))
}
function goDouban(){
        window.open('http://www.douban.com/recommend/?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title))
}
function goSina(){
        window.open('http://v.t.sina.com.cn/share/share.php?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title))
}
function goKaixin(){
       	window.open('http://www.kaixin001.com/~repaste/repaste.php?&rurl='+escape(document.location.href)+'&rtitle='+escape(document.title)+'&rcontent='+escape(document.title))
}

//图片自适应大小
var info_flag = false;
function AXImg(ximg,maxwidth,maxheight) {
    var image = new Image();
    var iwidth = maxwidth; //图片宽度
    var iheight = maxheight; //图片高度
    image.src = ximg.src;
    if (image.width > 0 && image.height > 0) {
        info_flag = true;
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ximg.width = iwidth;
                ximg.height = (image.height * iwidth) / image.width;
            } else {
                ximg.width = image.width;
                ximg.height = image.height;
            }
            //ximg.alt = image.width + "×" + image.height;
        } else {
            if (image.height > iheight) {
                ximg.height = iheight;
                ximg.width = (image.width * iheight) / image.height;
            } else {
                ximg.width = image.width;
                ximg.height = image.height;
            }
            //ximg.alt = image.width + "×" + image.height;
        }
    }
}

//flash focus 切换
/**
 *glide.layerGlide((oEventCont,oSlider,sSingleSize,sec,fSpeed,point);
 *@param auto type:bolean 是否自动滑动 当值是true的时候 为自动滑动
 *@param oEventCont type:object 包含事件点击对象的容器
 *@param oSlider type:object 滑动对象
 *@param sSingleSize type:number 滑动对象里单个元素的尺寸（width或者height）  尺寸是有point 决定
 *@param second type:number 自动滑动的延迟时间  单位/秒
 *@param fSpeed type:float   速率 取值在0.05--1之间 当取值是1时  没有滑动效果
 *@param point type:string   left or top
 */
 
var glide =new function(){
	function $id(id){return document.getElementById(id);};
	this.layerGlide=function(auto,oEventCont,oSlider,sSingleSize,second,fSpeed,point){
		var oSubLi = $id(oEventCont).getElementsByTagName('li');
		var interval,timeout,oslideRange;
		var time=1; 
		var speed = fSpeed 
		var sum = oSubLi.length;
		var a=0;
		var delay=second * 1000; 
		var setValLeft=function(s){
			return function(){
				oslideRange = Math.abs(parseInt($id(oSlider).style[point]));	
				$id(oSlider).style[point] =-Math.floor(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';		
				if(oslideRange==[(sSingleSize * s)]){
					clearInterval(interval);
					a=s;
				}
			}
		};
		var setValRight=function(s){
			return function(){	 	
				oslideRange = Math.abs(parseInt($id(oSlider).style[point]));							
				$id(oSlider).style[point] =-Math.ceil(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
				if(oslideRange==[(sSingleSize * s)]){
					clearInterval(interval);
					a=s;
				}
			}
		}
		
		function autoGlide(){
			for(var c=0;c<sum;c++){oSubLi[c].className='';};
			clearTimeout(interval);
			if(a==(parseInt(sum)-1)){
				for(var c=0;c<sum;c++){oSubLi[c].className='';};
				a=0;
				oSubLi[a].className="active";
				interval = setInterval(setValLeft(a),time);
				timeout = setTimeout(autoGlide,delay);
			}else{
				a++;
				oSubLi[a].className="active";
				interval = setInterval(setValRight(a),time);	
				timeout = setTimeout(autoGlide,delay);
			}
		}
	
		if(auto){timeout = setTimeout(autoGlide,delay);};
		for(var i=0;i<sum;i++){	
			oSubLi[i].onmouseover = (function(i){
				return function(){
					for(var c=0;c<sum;c++){oSubLi[c].className='';};
					clearTimeout(timeout);
					clearInterval(interval);
					oSubLi[i].className="active";
					if(Math.abs(parseInt($id(oSlider).style[point]))>[(sSingleSize * i)]){
						interval = setInterval(setValLeft(i),time);
						this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
					}else if(Math.abs(parseInt($id(oSlider).style[point]))<[(sSingleSize * i)]){
							interval = setInterval(setValRight(i),time);
						this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
					}
				}
			})(i)			
		}
	}
}

//以下为flash切换代码
$(function(){
    var $searchMenu =$(".searchType ul a");
	$searchMenu.mousemove(function(){
		 $(this).addClass("current")
		 .parent().siblings().children().removeClass("current"); 
         var index =  $searchMenu.index(this); 
		 $(".searchBody > div")
		 .eq(index).show()
		.siblings().hide();
	})
		   
		   
     $(".globleNav").mouseover(function(){
	     //$(".globleNavLink").removeClass("hover");										
		 //$(this).children(".globleNavLink").addClass("hover");
		 $(this).children(".subNavBox").show();
	 }).mouseout(function(){
	     //$(".globleNavLink").removeClass("hover");
		 $(this).children(".subNavBox").hide();
	 })	
	 $(".info_cityOpen").click(function(){
	     if($(".info_cityList").is(":visible")==false){
			  $(".info_cityList").show(500);
		 }else{
			 $(".info_cityList").hide(500);
		}									
	 })
	 $(".city_close").click(function(){
		$(".info_cityList").hide(500);							 
	 })
	 
	 $(".info_search_input").focus(function(){
			  $(this).css("color","#333");
			  if($(this).val() ==this.defaultValue){  
                  $(this).val("");           
			  } 
		}).blur(function(){
			  $(this).css("color","#999");
			  
			 if ($(this).val() == '') {
                $(this).val(this.defaultValue);
             }
	});
	 
	$(".customer_search").focus(function(){
			  $(this).css("color","#333");
			  if($(this).val() ==this.defaultValue){  
                  $(this).val("");           
			  } 
		}).blur(function(){
			  $(this).css("color","#999");
			  
			 if ($(this).val() == '') {
                $(this).val(this.defaultValue);
             }
	});
	 
	 
		
		$(".info_searchBtn01").click(function(){
			var key =$('#key').val();
			var searchType=$("#searchType").val();
			if(key == "请输入搜索关键字..."){ 
				alert("请输入关键字");
		    }
			else{
				window.location="http://news.zexy.com.cn/search/"+key;
			}
		})

	 
	 
	 
	 
   $("#index_searchData1 input:gt(0)").click(function(){
      $("#index_searchData2").hide(); 
   }) 
   $("#index_searchData1 input:eq(0)").click(function(){
      $("#index_searchData2").show(); 
   }) 
})



function $$(id) { return document.getElementById(id); }

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function addBtn() {
	if(!$$('ibanner')||!$$('ibanner_pic')||!$$('ibanner_tx')) return;
	var picList = $$('ibanner_pic').getElementsByTagName('a');
	if(picList.length==0) return;
	var btnBox = document.createElement('div');
	btnBox.setAttribute('id','ibanner_btn');
	var SpanBox ='';
	for(var i=1; i<=picList.length; i++ ) {
		var spanList = '<span class="normal">'+i+'</span>';
		SpanBox += spanList;
	}
	btnBox.innerHTML = SpanBox;
	$$('ibanner').appendChild(btnBox);
	$$('ibanner_btn').getElementsByTagName('span')[0].className = 'current';
	for (var m=0; m<picList.length; m++){
		var attributeValue = 'picLi_'+m
		picList[m].setAttribute('id',attributeValue);
	}
}

function classNormal(){
	var btnList = $$('ibanner_btn').getElementsByTagName('span');
	for (var i=0; i<btnList.length; i++){
		btnList[i].className='normal';
	}
}

function picNormal() {
	var picList = $$('ibanner_pic').getElementsByTagName('a');
	for (var i=0; i<picList.length; i++){
		picList[i].filters?(picList[i].filters[0].opacity= '0'):(picList[i].style.opacity='0');
		picList[i].style.zIndex='0';
	}
}

function txNormal() {
	var txList = $$('ibanner_tx').getElementsByTagName('li');
	for (var i=0; i<txList.length; i++){
		txList[i].className='normal';
	}
}

var timer;
function downOpacity(prevNum, nextID, delay) {
	clearInterval(timer);
	var picList = $$('ibanner_pic').getElementsByTagName('a');
	picList[nextID].filters?(picList[nextID].filters[0].opacity= '100'):(picList[nextID].style.opacity='1');
	picList[nextID].style.zIndex='1';
	picList[prevNum].filters?(picList[prevNum].filters[0].opacity= '100'):(picList[prevNum].style.opacity='1');
	picList[prevNum].style.zIndex='0';
	var elem= document.getElementById('picLi_'+prevNum);
	var o= 9;
	timer= setInterval(function(){
		elem.filters?(elem.filters[0].opacity= o* 10):(elem.style.opacity = o/10);
		o-= 1;
		if ( o< 0 ) clearInterval(timer);
	},delay);
}

function iBanner() {
	if(!$$('ibanner')||!$$('ibanner_pic')||!$$('ibanner_btn')||!$$('ibanner_tx')) return;
	var btnList = $$('ibanner_btn').getElementsByTagName('span');
	var picList = $$('ibanner_pic').getElementsByTagName('a');
	var txList = $$('ibanner_tx').getElementsByTagName('li');
	if (picList.length==1) return;
	for (var m=0; m<btnList.length; m++){
		btnList[m].onmouseover = function() {
			for(var n=0; n<btnList.length; n++) {
				if (btnList[n].className == 'current') {
					var prevNum = n;
				}
			}
			var nextNum = this.childNodes[0].nodeValue-1;
			if(nextNum!=prevNum) {
				classNormal();
				this.className='current';
				picNormal();
				downOpacity(prevNum, nextNum, 30);
				txNormal();
				txList[nextNum].className='current';
			}
		}
	}	
}

function autoBanner() {
	if(!$$('ibanner')||!$$('ibanner_pic')||!$$('ibanner_btn')||!$$('ibanner_tx')) return;
	var autoKey= false;
	$$('ibanner').onmouseover = function(){autoKey = true};
	$$('ibanner').onmouseout = function(){autoKey = false};
	var btnList = $$('ibanner_btn').getElementsByTagName('span');
	var picList = $$('ibanner_pic').getElementsByTagName('a');
	var txList = $$('ibanner_tx').getElementsByTagName('li');
	if(picList.length==1) return;
	setInterval(function(){
		if(autoKey) return;
		for(var i=0; i<btnList.length; i++) {
			if (btnList[i].className == 'current') {
				var prevNum = i;
			}
		}
		if (prevNum==(picList.length-1) ){
			classNormal();
			btnList[0].className='current';
			picNormal();
			downOpacity(prevNum, 0, 30);
			txNormal();
			txList[0].className='current';
		}else {
			classNormal();
			btnList[prevNum+1].className='current';
			picNormal();
			downOpacity(prevNum, prevNum+1, 30);
			txNormal();
			txList[prevNum+1].className='current';
		}
	},5000);
}
addLoadEvent(addBtn);
addLoadEvent(iBanner);
addLoadEvent(autoBanner);

//以下为弹窗代码

var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
var $l= function (id) {return "string" == typeof id ? document.getElementById(id) : id;};
var $lClass = {
	create: function() {
		return function() { this.initialize.apply(this, arguments); }
	}
}
var $lExtend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
}
var $lBind = function(object, fun) {
	return function() {
		return fun.apply(object, arguments);
	}
}
var $lEach = function(list, fun){
	for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
var $lContains = function(a, b){
	return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16);
}
var $lOverLay = $lClass.create();
$lOverLay.prototype = {
  initialize: function(options) {
	this.SetOptions(options);
	this.Lay = $l(this.options.Lay) || document.body.insertBefore(document.createElement("div"), document.body.childNodes[0]);
	this.Color = this.options.Color;
	this.Opacity = parseInt(this.options.Opacity);
	this.zIndex = parseInt(this.options.zIndex);
	with(this.Lay.style){ display = "none"; zIndex = this.zIndex; left = top = 0; position = "fixed"; width = height = "100%"; }
	if(isIE6){
		this.Lay.style.position = "absolute";
		//ie6设置覆盖层大小程序
		this._resize = $lBind(this, function(){
			this.Lay.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
			this.Lay.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
		});
		//遮盖select
		this.Lay.innerHTML = '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe>'
	}
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		Lay:		null,//覆盖层对象
		Color:		"#fff",//背景色
		Opacity:	50,//透明度(0-100)
		zIndex:		1000//层叠顺序
    };
    $lExtend(this.options, options || {});
  },
  //显示
  Show: function() {
	//兼容ie6
	if(isIE6){ this._resize(); window.attachEvent("onresize", this._resize); }
	//设置样式
	with(this.Lay.style){
		//设置透明度
		isIE ? filter = "alpha(opacity:" + this.Opacity + ")" : opacity = this.Opacity / 100;
		backgroundColor = this.Color; display = "block";
	}
  },
  //关闭
  Close: function() {
	this.Lay.style.display = "none";
	if(isIE6){ window.detachEvent("onresize", this._resize); }
  }
};
var LightBox = $lClass.create();
LightBox.prototype = {
  initialize: function(box, options) {
	this.Box = $l(box);//显示层
	this.$lOverLay = new $lOverLay(options);//覆盖层
	this.SetOptions(options);
	this.Fixed = !!this.options.Fixed;
	this.Over = !!this.options.Over;
	this.Center = !!this.options.Center;
	this.onShow = this.options.onShow;
	this.Box.style.zIndex = this.$lOverLay.zIndex + 1;
	this.Box.style.display = "none";
	//兼容ie6用的属性
	if(isIE6){
		this._top = this._left = 0; this._select = [];
		this._fixed = $lBind(this, function(){ this.Center ? this.SetCenter() : this.SetFixed(); });
	}
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
		Over:	true,//是否显示覆盖层
		Fixed:	false,//是否固定定位
		Center:	false,//是否居中
		onShow:	function(){}//显示时执行
	};
    $lExtend(this.options, options || {});
  },
  //兼容ie6的固定定位程序
  SetFixed: function(){
	this.Box.style.top = document.documentElement.scrollTop - this._top + this.Box.offsetTop + "px";
	this.Box.style.left = document.documentElement.scrollLeft - this._left + this.Box.offsetLeft + "px";
	
	this._top = document.documentElement.scrollTop; this._left = document.documentElement.scrollLeft;
  },
  //兼容ie6的居中定位程序
  SetCenter: function(){
	this.Box.style.marginTop = document.documentElement.scrollTop - this.Box.offsetHeight / 2 + "px";
	this.Box.style.marginLeft = document.documentElement.scrollLeft - this.Box.offsetWidth / 2 + "px";
  },
  //显示
  Show: function(options) {
	//固定定位
	this.Box.style.position = this.Fixed && !isIE6 ? "fixed" : "absolute";
	//覆盖层
	this.Over && this.$lOverLay.Show();
	this.Box.style.display = "block";
	//居中
	if(this.Center){
		this.Box.style.top = this.Box.style.left = "50%";
		//设置margin
		if(this.Fixed){
			this.Box.style.marginTop = - this.Box.offsetHeight / 2 + "px";
			this.Box.style.marginLeft = - this.Box.offsetWidth / 2 + "px";
		}else{
			this.SetCenter();
		}
	}
	
	//兼容ie6
	if(isIE6){
		if(!this.Over){
			//没有覆盖层ie6需要把不在Box上的select隐藏
			this._select.length = 0;
			$lEach(document.getElementsByTagName("select"), $lBind(this, function(o){
				if(!$lContains(this.Box, o)){ o.style.visibility = "hidden"; this._select.push(o); }
			}))
		}
		//设置显示位置
		this.Center ? this.SetCenter() : this.Fixed && this.SetFixed();
		//设置定位
		this.Fixed && window.attachEvent("onscroll", this._fixed);
	}
	
	this.onShow();
  },
  //关闭
  Close: function() {
	this.Box.style.display = "none";
	this.$lOverLay.Close();
	if(isIE6){
		window.detachEvent("onscroll", this._fixed);
		$lEach(this._select, function(o){ o.style.visibility = "visible"; });
	}
  }
};


