//滚动
function marquee(i, direction)
{
	var obj = document.getElementById("marquee" + i);
	var obj1 = document.getElementById("marquee" + i + "_1");
	var obj2 = document.getElementById("marquee" + i + "_2");

	if (direction == "up")
	{
		if (obj2.offsetTop - obj.scrollTop <= 0)
		{
			obj.scrollTop -= (obj1.offsetHeight + 20);
		}
		else
		{
			var tmp = obj.scrollTop;
			obj.scrollTop++;
			if (obj.scrollTop == tmp)
			{
				obj.scrollTop = 1;
			}
		}
	}
	else
	{
		if (obj2.offsetWidth - obj.scrollLeft <= 0)
		{
			obj.scrollLeft -= obj1.offsetWidth;
		}
		else
		{
			obj.scrollLeft++;
		}
	}
}

function marqueeStart(i, direction)
{
	var obj = document.getElementById("marquee" + i);
	var obj1 = document.getElementById("marquee" + i + "_1");
	var obj2 = document.getElementById("marquee" + i + "_2");

	obj2.innerHTML = obj1.innerHTML;
	var marqueeVar = window.setInterval("marquee("+ i +", '"+ direction +"')", 20);
	obj.onmouseover = function(){window.clearInterval(marqueeVar);}
	obj.onmouseout = function(){marqueeVar = window.setInterval("marquee("+ i +", '"+ direction +"')", 20);}
}

//屏蔽鼠标右键
function disabledRightButton()
{
	document.oncontextmenu = function(e){return false;}
	document.onselectstart = function(e){return false;}
	if (navigator.userAgent.indexOf("Firefox") > -1)
	{
		document.writeln("<style>body {-moz-user-select: none;}</style>");
	}
}

//设为首页
function setHomePage()
{
	if(document.all)
	{
		var obj = document.links(0);
		if (obj)
		{
			obj.style.behavior = 'url(#default#homepage)';
			obj.setHomePage(window.location.href);
		}
  	}
	else
	{
		if(window.netscape)
		{
			try
			{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch (e)
			{
				window.alert("此操作被浏览器拒绝，请通过浏览器菜单完成此操作！");
			}
		}
   	}
}

//加入收藏
function addFavorite()
{
	var url		= document.location.href;
	var title	= document.title;
	if (document.all)
	{
		window.external.addFavorite(url,title);
	}
	else if (window.sidebar)
	{
		window.sidebar.addPanel(title, url,"");
	}
}

//强制等高 
function $(obj)
{
	return document.getElementById(obj);
}

String.prototype.camelCase = function()
{
	return this.replace(/-\D/g,function(match)
	{
		return match.charAt(1).toUpperCase();
	});
}

String.prototype.hyphenate = function()
{
	return this.replace(/[A-Z]/g,function(match)
	{
		return ('-' + match.charAt(0).toLowerCase());
	});
}

var _getComputedStyle = function(property)
{
	if(this.currentStyle) return this.currentStyle[property.camelCase()];
	var computed = document.defaultView.getComputedStyle(this,null);
	return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
}



function EqualHeight(obj,clear){
	function $(obj)
	{
		return document.getElementById(obj);
	}

	function $each(iterable,fn,fn_sub)
	{
		for(i = 0;i < iterable.length;i++)
		{
			fn.apply(null,[iterable,i]);
		}
	}

	function _nodeFix(obj)
	{
		var arr = new Array();
		var cl = new RegExp("\\b"+clear+"\\b\\s*","");
		for(i = 0;i < obj.childNodes.length;i++)
		{
			if(obj.childNodes[i] && obj.childNodes[i].nodeType == 1 && !(cl.test(obj.childNodes[i].className)))
			{
				arr.push(obj.childNodes[i]);
					
			}
		}
		return arr;
	}	

	function calc(h,obj)
	{
			
		try
		{
			 var _t = parseInt(_getComputedStyle.call(obj,"paddingTop"));
		}
		catch(e)
		{
			throw new Error("获取padding值时出现错误!!");
			alert(e);
		}

		var _b = parseInt(_getComputedStyle.call(obj,"paddingBottom"));
		return (h - (_t + _b))	;
	}
	//window.alert("断点-改变前");		
	var arr = _nodeFix($(obj)),_H = 0;

	$each(arr,function(arr,i)
	{	
		var _h = arr[i].offsetHeight;
		_H = (_h > _H ? _h : _H);
	});
	$each(arr,function(arr,j)
	{
		arr[j].style.height = calc(_H,arr[i]) + 'px';
	});
	
};

//window.onload = function(){document.getElementById("me").firstChild.firstChild.style.height = "100%";}
