function getElementsByClass1(node,searchClass,tag) {
    var classElements = new Array();
    var els = node.getElementsByTagName(tag); // use "*" for all elements
    var elsLen = els.length;
    var pattern = new RegExp("\b"+searchClass+"\b");
    for (i = 0, j = 0; i < elsLen; i++) { 
	
         if ( els[i].className==searchClass ) {//alert("matched");
             classElements[j] = els[i];
             j++;
         }
    }
    return classElements;
}

max_len=14;
function Init1(){
	//var lo_emnt=getElementsByClass1(document.getElementById("subnav"),"children","ul");
	//Iterate(lo_emnt2[0]);

	var lo_parent=document.getElementById("subnavbar");
	var lo_elmnt=lo_parent.getElementsByTagName("UL")[0];
	Iterate(lo_elmnt);
}


Event.domReady.add(function() {Init1();});


function Iterate(aro_emnt){

	var i;


//	document.getElementById("test").innerHTML+=lo_emnt.className+","+lo_emnt.childNodes.length+"<br/>";	
//	var lao_emnt=getElementsByClass1(lo_emnt,"children","ul");

	var lao_emnt=aro_emnt.childNodes;
	var ls_length=lao_emnt.length;
	
	if(ls_length==0){return;}

	for(i=0;i<ls_length;i++){
		if(lao_emnt[i].nodeName!="text"){	
		var lo_elmt1=lao_emnt[i];
		if(lao_emnt[i].nodeName=="UL"){
			Create_updownnav(lo_elmt1);
		}
		Iterate(lo_elmt1);
		}
	}
}
function move_Up(e){


	var ie = !!(window.attachEvent && !window.opera);
	if(!ie){
		var lo_target=e.target;
	}
	else{
		var lo_target=event.srcElement;
	}
if(lo_target.nodeName=="IMG"){
	lo_target=lo_target.parentNode;
}
var lo_con=lo_target.parentNode.parentNode;

	var lao_img1=lo_con.getElementsByTagName("IMG");
	var ln=lao_img1.length;
	lo_img1=lao_img1[ln-1];
	lo_img1.src=temp_path+"/images/down2.gif";

	var lo_emnts=GetChildNodes(lo_con);
	

	if(typeof(lo_timer)!="undefined"){
		clearTimeout(lo_timer);
	}
	lo_timer=setInterval(function(){		
	
	var from=parseInt(lo_con.getAttribute("FROM"))-1;
	var to=parseInt(lo_con.getAttribute("TO"))-1;
	if(from<0) {
		var img=lo_target.getElementsByTagName("IMG")[0];
		if(img) img.src=temp_path+"/images/up1.gif";
		return;
	}

	SCROLL(to,from,lo_emnts);
	lo_con.setAttribute("FROM",from);
	lo_con.setAttribute("TO",to);
	},100);	
}
function move_Down(e){

	var ie = !!(window.attachEvent && !window.opera);
	if(!ie){
		var lo_target=e.target;
	}
	else{
		var lo_target=event.srcElement;
	}
if(lo_target.nodeName=="IMG"){
	lo_target=lo_target.parentNode;
}	
	var lo_con=lo_target.parentNode.parentNode;
	

	var lo_emnts=GetChildNodes(lo_con);
	
	var lo_img1=lo_con.getElementsByTagName("IMG")[0];
	lo_img1.src=temp_path+"/images/up2.gif";
	//lo_img1.parentNode.parentNode.style.display="block";

	
	if(typeof(lo_timer)!="undefined"){
		clearTimeout(lo_timer);
	}
	lo_timer=setInterval(function(){
		var from=parseInt(lo_con.getAttribute("FROM"))+1;
		var to=parseInt(lo_con.getAttribute("TO"))+1;

		if(to >lo_emnts.length){ 
			var img=lo_target.getElementsByTagName("IMG")[0];
			if(img) img.src=temp_path+"/images/down1.gif";
			return;
		}	
		
		SCROLL(to,from,lo_emnts);
		lo_con.setAttribute("FROM",from);
		lo_con.setAttribute("TO",to);
	},100);	

}

function Create_updownnav(ars_con){
	
//	lao_elmts=GetChildNodes(ars_con);

	var lao_childr=ars_con.childNodes;
	var ls_length=lao_childr.length;
	var k=0;var i=0;
	var lao_elmts=new Array();
	for(i=0;i<ls_length;i++){
		if(lao_childr[i].nodeName=="LI"){
		  lao_elmts[k]=lao_childr[i];
		  k++;
		}
	}
	
	if(lao_elmts.length>max_len){
		var lo_img=document.createElement("li");
		ars_con.insertBefore(lo_img,lao_elmts[0])
		lo_img.style.width="156px";
		lo_img.style.height="16px";
		lo_img.style.cursor="pointer";
		lo_img.style.border="1px solid white";
		lo_img.style.borderBottom="none";
		lo_img.style.backgroundColor="#73BBE1";
		lo_img.innerHTML="<center><img style='width:9px;height:9px;' src='"+temp_path+"/images/up1.gif'/></center>";
		lo_img.onmouseover=function(e){move_Up(e);};
		lo_img.onmouseout=function(){if(typeof(lo_timer)!="undefined"){clearTimeout(lo_timer);}};
		
		//lo_img.style.display="none";
		
		var lo_img=document.createElement("li");
		ars_con.appendChild(lo_img);
		lo_img.style.width="156px";
		lo_img.style.height="16px";
		lo_img.style.cursor="pointer";
		lo_img.style.border="1px solid white";
		lo_img.style.backgroundColor="#73BBE1";
		lo_img.innerHTML="<center><img style='width:11px;height:11px;' src='"+temp_path+"/images/down2.gif'/></center>";
		lo_img.onmouseover=function(e){move_Down(e);};	
		lo_img.onmouseout=function(){if(typeof(lo_timer)!="undefined"){clearTimeout(lo_timer);}};
		ars_con.setAttribute("TO",max_len);
		ars_con.setAttribute("FROM",0);
		
		SCROLL(max_len,0,lao_elmts);		
	}
}

function SCROLL(ln_up,ln_bot,lo_childs){
	var i;
	var length=lo_childs.length;
	for(i=0;i<length;i++){
		if(i<ln_up && i>ln_bot){
		  lo_childs[i].style.display="block";
		}
		else{
			lo_childs[i].style.display="none";
		}
	}
}

function GetChildNodes(ars_con){
	var lao_childr=ars_con.childNodes;
	var ls_length=lao_childr.length;
	var k=0;var i=0;
	var lao_elmts=new Array();
	for(i=0;i<ls_length;i++){
		if(lao_childr[i].nodeName=="LI"){
		  lao_elmts[k]=lao_childr[i];
		  k++;
		}
	}
	lao_elmts.shift();
	lao_elmts.pop();
	return lao_elmts;
}	
