<!--

var switchTab = function(id, tag, ev, className)
{
	this.id = id;
	this.tag = tag;
	this.triggerEvent = ev;
	this.className = className

	this.init();
};

switchTab.prototype = {
	id : null,
	tag : null,
	triggerEvent : 'mouseover',
	className : null,
	current : null,
	delay : 5000,
	stop : false,

	init : function() {
		var el = this.getEl(this.id);
		var childs = el.getElementsByTagName(this.tag);
		var len = childs.length;
		for(i=0; i<len; i++)
		{
			var child = childs[i];
			var othis = this;
			(function(el, o){
				o.addEvent(el, o.triggerEvent, function(){
					o.stop = true;
					o.change(el, o);
				}, false);
			})(child, othis);

			(function(el, o){
				o.addEvent(el, 'mouseout', function(){
					o.stop = false;
				}, false);
			})(child, othis);
		};

		this.change(childs[0], this);
		this.auto(this);
	},

	auto : function(othis) {

		var getNext = function(n) {
			if (!n) { return null; }
			var node = n.nextSibling;
			if (!node) { return null; }
			if (node.nodeType == 1 /* Node.ELEMENT_NODE */) {
				return node;
			} else {
				return getNext(node);
			}
		};
		othis.timer = setInterval(function(){

			if (othis.stop) { clearInterval(othis.timer); return; }

			var next = getNext(othis.current);
			if (!next)
			{
				var el = othis.getEl(othis.id);
				next = getNext(el.childNodes[0]);
			}
			othis.change(next, othis);
		}, othis.delay);
	},
	
	change : function(child, othis) {
		if (!othis.current)
		{
			if (typeof othis.changeContent == 'function')
			{
				othis.changeContent(child, othis);
			}

			othis.addClass(child, othis.className, othis);
			othis.current = child;
		}
		else
		{
			if (othis.current.innerHTML == child.innerHTML)
			{
				return;
			}
			else
			{
				if (typeof othis.changeContent == 'function')
				{
					othis.changeContent(child, othis);
				}

				othis.removeClass(othis.current, othis.className, othis);
				othis.addClass(child, othis.className, othis);
				othis.current = child;
			}
		}
	},

	hasClass : function(ele,cls,othis) {
		return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	},

	addClass : function(ele,cls,othis) {
		if (!othis.hasClass(ele,cls)) ele.className += " "+cls;
	},

	removeClass : function(ele,cls,othis) {
		if (othis.hasClass(ele,cls)) {
			var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			ele.className=ele.className.replace(reg,' ');
		}
	},

	//element.addEvent(window, 'load', init, false);
	addEvent: function(elm, evType, fn, useCapture){
		if (elm.addEventListener) 
		{
			elm.addEventListener(evType, fn, useCapture);
			return true;
		} else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		} else {
			elm['on' + evType] = fn;
		}
	},
	
	getEl : function(name) {
		return document.getElementById(name) || null;
	}
};

function DrawImage(ImgD,FitWidth,FitHeight){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		if(image.width/image.height>= FitWidth/FitHeight){
			if(image.width>FitWidth){
				ImgD.width=FitWidth;
				ImgD.height=(image.height*FitWidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		} else{
			if(image.height>FitHeight){
				ImgD.height=FitHeight;
				ImgD.width=(image.width*FitHeight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
	}
};

window.onload = function () {

	var maxWidth = 400;

	var pageImages = document.getElementsByTagName('img');
	var len = pageImages.length;

	for(var i=0; i<len; i++)
	{
		if (pageImages[i].width > maxWidth)
		{
			pageImages[i].width = maxWidth;
		}
	}

	var yituImage = new switchTab('yituNewPost', 'li', 'mouseover', 'current');
}

//-->