
// sitam faile esancios funkcijos naudojamos visuose ekranuose!

function DhtmlContent(containerClassName, selectorClassName, getHigh){
	this.containerClassName = containerClassName;
	this.selectorClassName = selectorClassName;
	this.getHigh = getHigh;
	this.containers = document.getElementsByClassName(containerClassName);
	this.selectors = document.getElementsByClassName(selectorClassName);

	this.current=0;
	
	
	
	this.showOne=function(id){
		this.current=id;
		
		for (i=0; i<this.selectors.length; i++){
			Element.removeClassName(this.selectors[i], this.getHigh);
		}		
		
		for (i=0; i<this.containers.length; i++){
			if(id!=i){
				this.containers[i].style.display="none";
			} else {
				this.containers[i].style.display="block";
				Element.addClassName(this.selectors[i], this.getHigh);
			}
		}
	}
	
	this.showOneBySelectorId=function(id){
		//alert(id);
		//this.current=id;
		for (i=0; i<this.selectors.length; i++){
			Element.removeClassName(this.selectors[i], this.getHigh);
		}		
		
		for (i=0; i<this.containers.length; i++){
			if(this.selectors[i].id!=id){
				this.containers[i].style.display="none";
			} else {
				this.current=i;
				this.containers[i].style.display="block";
				Element.addClassName(this.selectors[i], this.getHigh);
				
				
			}
		}
		
		
		//d;
		
		
	}	
	
	this.showFirst=function(){
		this.current=0;
		this.showOne(0);
	}
	this.showNext=function(){
		Element.removeClassName(this.selectors[this.current], this.getHigh);
		for (i=0; i<this.selectors.length; i++){
			Element.removeClassName(this.selectors[i], this.getHigh);
		}
		var next = this.current+1;
		if (next>=this.containers.length){
			next=0;
		}
		
		this.showOne(next);
		
	}
	this.showLast=function(){
		for (i=0; i<this.containers.length; i++){
			this.containers[i].style.display="none";
		}		
	
		i--;
		this.current=i;

		this.containers[i].style.display="block";
		Element.addClassName(this.selectors[i], this.getHigh);

	}
	
	this.shaolinTigerContainerReplace=function(e){
		for (i=0; i<this.containers.length; i++){
			this.containers[i].style.display="none";
		}
		for (i=0; i<this.selectors.length; i++){
			Element.removeClassName(this.selectors[i], this.getHigh);
			if (this.selectors[i].id==this.id){
					//this.current=i;
					//alert(i);
			}
		}		
		
		Element.addClassName(this.highlite, this.getHigh);
		this.open.style.display='block';
	}
	
	this.addObserves=function(){
		for (i=0; i<this.selectors.length; i++){
			var obj = {
				open: this.containers[i],
				containers: this.containers,
				highlite: this.selectors[i],
				selectors: this.selectors,
				getHigh: this.getHigh,
				current: i
			};
			Event.observe(this.selectors[i], 'click', this.shaolinTigerContainerReplace.bindAsEventListener(obj));			
		}
	}
	this.addObserves();
}

//------------------------------------------------------------------------------
function Menu(actives, selected){
	this.selected = selected;
	this.activate = function(){	
		for (i=0; i<this.selected.length; i++){
			Element.addClassName($('site_menu_id_'+this.selected[i]),'over');
		}
	}
	for (i=0; i<actives.length; i++){
		if ($('site_menu_id_'+actives[i][0])){
			var obj = {
				zero:$('site_menu_id_'+actives[i][0]),
				first:$('site_menu_id_'+actives[i][1]),
				all:$('theMenu'),
				selected:selected
			}
			Event.observe($('site_menu_id_'+actives[i][0]), 'mouseover', (function(){
				var all=this.all.descendants();
				for (j=0; j<all.length; j++){
					Element.removeClassName(all[j],'selected');

				}				if (this.first!=null){ 
					Element.addClassName($(this.first.id),'over');
				}
				
				if (this.zero!=null){
					Element.addClassName($(this.zero.id),'over');
				}
			}).bindAsEventListener(obj));	
			Event.observe($('site_menu_id_'+actives[i][0]), 'mouseout', (function(){
				var all=this.all.descendants();
				for (j=0; j<all.length; j++){
					Element.removeClassName(all[j],'over');
					Element.removeClassName(all[j],'over');

				}
					for (i=0; i<this.selected.length; i++){
						Element.addClassName($('site_menu_id_'+this.selected[i]),'selected');
					}
			}).bindAsEventListener(obj));			
		}
	}
	//Event.observe($('theMenu'), 'mouseout', this.activate.bindAsEventListener({selected:selected}));			
}
