﻿//修改导航的切换样式
function navstyle(activeorder)
{
	var i = 0;
	$$('#nav p').each(function(element){
		if(element.parentNode==$("nav"))
		{
			i++;
			var center = document.createElement("center");
			Element.update(center,element.innerHTML);
			Element.update(element,center);
			element.className = "nav";
			if(activeorder==i)
			{
				element.getElementsByTagName("center")[0].className = "active";
			}
			else
			{
				element.getElementsByTagName("center")[0].onmouseover = function(){this.className = "mouseon"; };
				element.getElementsByTagName("center")[0].onmouseout = function(){this.className = ""; };
			}
			if(i<$("nav").getElementsByTagName("p").length)
			{
				Insertion.After(element,"<span></span>");
			}
		}
	});
}

//修改列表的样式
function liststyle(listID)
{
	if($(listID))
	{
		var ulobject = $(listID).getElementsByTagName("ul")[0];
		$$('#'+listID+' li').each(function(element){
			if(element.parentNode == ulobject)
			{
				element.className = "item";
				var divobj = element.getElementsByTagName("div");
				for(var i=1;i<=divobj.length;i++)
				{
					if(checklistdiv(divobj[i-1],ulobject))
					{
						divobj[i-1].className = "div"+i;
					}
				}
			}
		});
		updatelistclass(listID,ulobject,"h1","title");
		updatelistclass(listID,ulobject,"h2","valuelist");
		updatelistclass(listID,ulobject,"h3","dateandtime");
		updatelistclass(listID,ulobject,"h6","content");
		updatelistclass(listID,ulobject,"em","filesize");
		updatelistclass(listID,ulobject,"center","photo");
		updatelistclass(listID,ulobject,"h6","content");
	}
}

function updatelistclass(listID,ulobject,tagname,classname)
{
	$$('#'+listID+' '+tagname+'').each(function(element){
		if(element.parentNode.parentNode == ulobject)
		{
			element.className = classname;
		}
		else
		{
			if(checklistdiv(element.parentNode,ulobject))
			{
				element.className = classname;
			}
		}
	});
}

function checklistdiv(divobj,ulobject)
{
	if(divobj.tagName == "DIV")
	{
		if(divobj.parentNode.parentNode == ulobject)
		{
			return true;
		}
		else
		{
			return checklistdiv(divobj.parentNode,ulobject);
		}
	}
	else
	{
		return false;
	}
}

//修改列表标题图片
function listpic(listID,tagname,imageurl)
{
	var i=0;
	$$('#'+listID+' '+tagname+'').each(function(element){
		i++;
		element.style.backgroundImage = "url("+imageurl.replace("{0}",i)+")";
	});
}

//修改类别列表的样式
function classliststyle(listID)
{
	if($(listID))
	{
		var i=0;
		$$('#'+listID+' p').each(function(element){
			if(element.parentNode == $(listID))
			{
				i++;
				element.className = "title";
				element.id = "classtitle"+i;
			}
		});
		i=0;
		$$('#'+listID+' ul').each(function(element){
			if(element.parentNode == $(listID))
			{
				i++;
				element.className = "content";
				element.id = "classcontent"+i;
				$$('#'+element.id+' li').each(function(listelement){
					if(listelement.parentNode == element)
					{
						listelement.className = "item";
					}
				});
			}
		});
	}
}

//保持中心部分的高度一致
function divheight(side,main,total)
{
	if($(side)&&$(main)&&$(total))
	{
		if($(side).clientHeight<$(main).clientHeight)
		{    
			$(total).style.height=$(main).clientHeight+"px";    
		}
		else
		{  
			$(total).style.height=$(side).clientHeight+"px";    
		}
	}
}

//使div1与div2高度保持一致
function divheight1(div1,div2)
{
	if($(div1)&&$(div2))
	{
		if($(div1).clientHeight<$(div2).clientHeight)
		{
			$(div1).style.height=$(div2).offsetHeight+"px";
		}
		else
		{
			$(div2).style.height=$(div1).offsetHeight+"px";
		}
	}
}

function pagealign()
{
	divheight("side","main","total");
	//divheight1("side","main");
}

document.observe('dom:loaded', function() {
	setInterval ("pagealign()",200);
});
//某个层的最小高度
function minheight(divid,height)
{
	if($(divid))
	{
		if($(divid).clientHeight<height)$(divid).style.height=height+"px";
	}
}

//图片自动居中
function photocenter(photoID,paddingWidth,paddingHeight)
{
    var photoobj = $(photoID).getElementsByTagName("img")[0];
    var photoParent = $(photoID).parentNode;
    photoobj.style.display = "none";
	photoParent.style.padding = paddingHeight+"px "+paddingWidth+"px";
    photoParent.style.overflow = "hidden";
    photoobj.onload = function()
    {
	    this.style.display = "";
	    if(this.width/this.height>(photoParent.clientWidth-paddingWidth*2)/(photoParent.clientHeight-paddingHeight*2))
	    {
		    if(this.width>=(photoParent.clientWidth-paddingWidth*2))
		    {
			    this.width = photoParent.clientWidth-paddingWidth*2;
			    this.style.marginTop = (photoParent.clientHeight-paddingHeight*2-this.height)/2+"px";
		    }
		    else
		    {
			    this.style.margin = "auto";
			    this.style.marginTop = (photoParent.clientHeight-paddingHeight*2-this.height)/2+"px";
		    }
	    }
	    else
	    {
		    if(this.height>=photoParent.clientHeight-paddingHeight*2)
		    {
			    this.height = photoParent.clientHeight-paddingHeight*2;
			    this.style.marginLeft = (photoParent.clientWidth-paddingWidth*2-this.width)/2+"px";
		    }
		    else
		    {
			    this.style.margin = "auto";
			    this.style.marginTop = (photoParent.clientHeight-paddingHeight*2-this.height)/2+"px";
		    }
	    }
    }
    photoobj.src = photoobj.src+"?1";
}


//加载整个页面input的动态样式
function inputstyle(normalbordercolor,normalbackgroundcolor,focusbordercolor,focusbackgroundcolor,buttonstyle)
{
	document.observe('dom:loaded', function(){
		$$('input[type="text"]','input[type="password"]').each(function(element){
			element.style.borderWidth = "1px";
			element.style.borderStyle = "solid";
			element.style.borderColor = normalbordercolor;
			element.onmouseover = function(){this.style.borderColor = focusbordercolor;this.style.backgroundColor = focusbackgroundcolor;};
			element.onmouseout = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;};
			element.onfocus = function(){this.style.borderColor = focusbordercolor;this.style.backgroundColor = focusbackgroundcolor;this.onmouseout=""};
			if(element.onblur==null)
			{
				element.onblur = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;this.onmouseout = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;};};
			}
			element.autocomplete= "off";
		});
		$$('input[type="button"]','input[type="submit"]','input[type="reset"]').each(function(element){element.className = buttonstyle;});
		$$('textarea').each(function(element){
			element.style.borderWidth = "1px";
			element.style.borderStyle = "solid";
			element.style.borderColor = normalbordercolor;
			element.onmouseover = function(){this.style.borderColor = focusbordercolor;this.style.backgroundColor = focusbackgroundcolor;};
			element.onmouseout = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;};
			element.onfocus = function(){this.style.borderColor = focusbordercolor;this.style.backgroundColor = focusbackgroundcolor;this.onmouseout=""};
			if(element.onblur==null)
			{
				element.onblur = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;this.onmouseout = function(){this.style.borderColor = normalbordercolor;this.style.backgroundColor = normalbackgroundcolor;};};
			}
		});
	});
}

//ajax载入
function loadAjaxData(u,p,s,f){
	if(arguments.length < 3){
		return ;
	}
	p = $H(p).toQueryString();
	new Ajax.Request(u,{method: 'get', parameters: p, onComplete:s});
}
