/*
 * SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
 * By Dynamic Drive: http://www.dynamicdrive.com/style/
 * AND
 * SuckerTree Horizontal Menu (Sept 14th, 06)
 * By Dynamic Drive: http://www.dynamicdrive.com/style/
 * 
 * Recoded for mootools 1.11 by: Petar Sokarovski
 */


var SuckerTree = new Class({
	
	initialize: function(eles) {
		this.element = $(eles);
		this.uls = this.element.getElements("ul");	
		return this;
	},
	
	vertical: function() {
		for(var i=0; i<this.uls.length; i++)  {
			var ul = $(this.uls[i]);
			ul.getParent().getElement("a").addClass("subfolderstyle");
			if (ul.getParent().getParent().id == this.element.id) {
				ul.setStyle("left", ul.parentNode.offsetWidth+"px");
			} else {
				ul2 = $(this.uls[i-1]);
				ul.setStyle("left" , ul2.getElement("a").offsetWidth+"px");
			}
			
			ul.getParent().sub = ul.getParent().getElement("ul");
		    ul.getParent().onmouseover=function(){
				if ($chk(this.$tmr)) { $clear(this.$tmr) };
				this.sub.setStyle("display","block");
		    }
		    ul.getParent().onmouseout=function(){
				if ($chk(this.$tmr)) $clear(this.$tmr);
		    	this.$tmr = this.sub.setStyle.delay(100, this.sub, ["display", "none"]);
		    }			
		}
		for (var i=this.uls.length-1; i>-1; i--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
			var ul = $(this.uls[i]);
			ul.setStyles({
				"visibility" : "visible",
				"display":"none"
			});
		}		
	},
	
	horizontal: function() {
		for (var i=0; i<this.uls.length; i++) {
			var ul = $(this.uls[i]);
			if (ul.getParent().getParent().id==this.element.id) {
				ul.setStyle("top", ul.getParent().offsetHeight+"px" );
				ul.getParent().getElement("a").addClass("mainfoldericon");
			} else {
				ul2 = $(this.uls[i-1]);
				ul.setStyle("left", ul2.getElement("a").offsetWidth+"px" );
				ul.getParent().getElement("a").addClass("subfoldericon");
			}
			
			ul.getParent().sub = ul.getParent().getElement("ul");
			ul.getParent().onmouseover = function() {
				if ($chk(this.$tmr)) $clear(this.$tmr);
				this.sub.setStyle("visibility", "visible");
			}
			
			ul.getParent().onmouseout = function() {
				if ($chk(this.$tmr)) $clear(this.$tmr);
		    	//this.$tmr = this.sub.setStyle.delay(300, this.sub, ["display", "none"]);
				this.$tmp = this.sub.setStyle.delay(300, this.sub, ["visibility", "hidden"]);
			}
		}			
	}
});
