//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.
//Scroller updated on 2009-11-01

MooTools.More={version:"1.2.4.2",build:"bd5a93c0913cce25917c48cbdacde568e15e02ef"};

Fx.Slide=new Class({Extends:Fx,options:{mode:"vertical",hideOverflow:true,offsetmin:0},
initialize:function(b,a){this.addEvent("complete",function(){this.open=(this.wrapper["offset"+this.layout.capitalize()]!=this.options.offsetmin);if(this.open&&Browser.Engine.webkit419){this.element.dispose().inject(this.wrapper);}},true);this.element=this.subject=document.id(b);this.parent(a);var d=this.element.retrieve("wrapper");var c=this.element.getStyles("margin","position","overflow");if(this.options.hideOverflow){c=$extend(c,{overflow:"hidden"});}this.wrapper=d||new Element("div",{styles:c}).wraps(this.element);this.element.store("wrapper",this.wrapper).setStyle("margin",0);this.now=[];this.open=true;},
vertical:function(){this.margin="margin-top";this.layout="height";this.offset=this.element.offsetHeight;},horizontal:function(){this.margin="margin-left";this.layout="width";this.offset=this.element.offsetWidth;},
set:function(a){this.element.setStyle(this.margin,a[0]);this.wrapper.setStyle(this.layout,a[1]);return this;},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},
start:function(b,e){if(!this.check(b,e)){return this;}this[e||this.options.mode]();var d=this.element.getStyle(this.margin).toInt();var c=this.wrapper.getStyle(this.layout).toInt();var a=[[d,c],[0,this.offset]];var g=[[d,c],[-this.offset+this.options.offsetmin,this.options.offsetmin]];var f;switch(b){case"in":f=a;break;case"out":f=g;break;case"toggle":f=(c==this.options.offsetmin)?a:g;}return this.parent(f[0],f[1]);},
slideIn:function(a){return this.start("in",a);},slideOut:function(a){return this.start("out",a);},hide:function(a){this[a||this.options.mode]();this.open=false;return this.set([-this.offset+this.options.offsetmin,this.options.offsetmin]);},
show:function(a){this[a||this.options.mode]();this.open=true;return this.set([0,this.offset]);},toggle:function(a){return this.start("toggle",a);}});

Element.Properties.slide={set:function(b){var a=this.retrieve("slide");if(a){a.cancel();}return this.eliminate("slide").store("slide:options",$extend({link:"cancel"},b));},get:function(a){if(a||!this.retrieve("slide")){if(a||!this.retrieve("slide:options")){this.set("slide",a);
}this.store("slide",new Fx.Slide(this,this.retrieve("slide:options")));}return this.retrieve("slide");}};

Element.implement({slide:function(d,e){d=d||"toggle";
var b=this.get("slide"),a;switch(d){case"hide":b.hide(e);break;case"show":b.show(e);break;case"toggle":var c=this.retrieve("slide:flag",b.open);b[c?"slideOut":"slideIn"](e);
this.store("slide:flag",!c);a=true;break;default:b.start(d,e);}if(!a){this.eliminate("slide:flag");}return this;}});


Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(b,a){this.elements=this.subject=$$(b);
this.parent(a);},compute:function(g,h,j){var c={};for(var d in g){var a=g[d],e=h[d],f=c[d]={};for(var b in a){f[b]=this.parent(a[b],e[b],j);}}return c;
},set:function(b){for(var c in b){var a=b[c];for(var d in a){this.render(this.elements[c],d,a[d],this.options.unit);}}return this;},start:function(c){if(!this.check(c)){return this;
}var h={},j={};for(var d in c){var f=c[d],a=h[d]={},g=j[d]={};for(var b in f){var e=this.prepare(this.elements[d],b,f[b]);a[b]=e.from;g[b]=e.to;}}return this.parent(h,j);
}});

Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=document.id(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);if(Browser.Engine.gecko){a=[Math.round(a[0]),Math.round(a[1])];}this.element.scrollTo(a[0],a[1]);
},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);});},start:function(c,g){if(!this.check(c,g)){return this;}var e=this.element.getScrollSize(),b=this.element.getScroll(),d={x:c,y:g};
for(var f in d){var a=e[f];if($chk(d[f])){d[f]=($type(d[f])=="number")?d[f]:a;}else{d[f]=b[f];}d[f]+=this.options.offset[f];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=document.id(b).getPosition(this.element);return this.start(a.x,a.y);},scrollIntoView:function(c,e,d){e=e?$splat(e):["x","y"];
var h={};c=document.id(c);var f=c.getPosition(this.element);var i=c.getSize();var g=this.element.getScroll();var a=this.element.getSize();var b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){if(b[j]>g[j]+a[j]){h[j]=b[j]-a[j];}if(f[j]<g[j]){h[j]=f[j];}}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];
}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);}return this;},scrollToCenter:function(c,e,d){e=e?$splat(e):["x","y"];c=$(c);var h={},f=c.getPosition(this.element),i=c.getSize(),g=this.element.getScroll(),a=this.element.getSize(),b={x:f.x+i.x,y:f.y+i.y};
["x","y"].each(function(j){if(e.contains(j)){h[j]=f[j]-(a[j]-i[j])/2;}if(h[j]==null){h[j]=g[j];}if(d&&d[j]){h[j]=h[j]+d[j];}},this);if(h.x!=g.x||h.y!=g.y){this.start(h.x,h.y);
}return this;}});

var Accordion=Fx.Accordion=new Class({Extends:Fx.Elements,options:{display:0,show:false,height:true,width:false,opacity:true,alwaysHide:false,trigger:"click",initialDisplayFx:true,returnHeightToAuto:true},
	initialize:function(){
		var c=Array.link(arguments,{container:Element.type,options:Object.type,togglers:$defined,elements:$defined});
		this.parent(c.elements,c.options);this.togglers=$$(c.togglers);this.container=document.id(c.container);this.previous=-1;this.internalChain=new Chain();
		if(this.options.alwaysHide){this.options.wait=true;}if($chk(this.options.show)){this.options.display=false;this.previous=this.options.show;}
		if(this.options.start){this.options.display=false;this.options.show=false;}
		this.effects={};
		if(this.options.opacity){this.effects.opacity="fullOpacity";}
		if(this.options.width){this.effects.width=this.options.fixedWidth?"fullWidth":"offsetWidth";}
		if(this.options.height){this.effects.height=this.options.fixedHeight?"fullHeight":"scrollHeight";}
		for(var b=0,a=this.togglers.length;b<a;b++){this.addSection(this.togglers[b],this.elements[b]);}
		this.elements.each(function(e,d){if(this.options.show===d){this.fireEvent("active",[this.togglers[d],e]);}else{for(var f in this.effects){e.setStyle(f,0);}}},this);
		if($chk(this.options.display)){this.display(this.options.display,this.options.initialDisplayFx);}
		this.addEvent("complete",this.internalChain.callChain.bind(this.internalChain));
	},
	addSection:function(e,c){
		if(c==undefined)return;if (c.firstChild == undefined) return;e=document.id(e);c=document.id(c);var f=this.togglers.contains(e);this.togglers.include(e);
		this.elements.include(c);var a=this.togglers.indexOf(e);
		var b=this.display.bind(this,a);e.store("accordion:display",b);e.addEvent(this.options.trigger,b);
		if(this.options.height){c.setStyles({"padding-top":0,"border-top":"none","padding-bottom":0,"border-bottom":"none"});}
		if(this.options.width){c.setStyles({"padding-left":0,"border-left":"none","padding-right":0,"border-right":"none"});}
		c.fullOpacity=1;if(this.options.fixedWidth){c.fullWidth=this.options.fixedWidth;}
		if(this.options.fixedHeight){c.fullHeight=this.options.fixedHeight;}
		c.setStyle("overflow","hidden");if(!f){for(var d in this.effects){c.setStyle(d,0);}}
		return this;
	},
	detach:function(){this.togglers.each(function(a){a.removeEvent(this.options.trigger,a.retrieve("accordion:display"));},this);},
	checkForOpenedSliders:function(felement) {
		var retval = false;
		if (felement) {
			var felementSlider = felement.getChildren()[1];
			if (felementSlider) {
				if (felementSlider.getStyle('height') != '0px') {
					// this element has opened sliders inside
					retval=true;
				}
			}
		}
		return retval;
	},
	display:function(a,b){
		if(!this.check(a,b)){return this;}
		b=$pick(b,true);
		if(this.options.returnHeightToAuto){
			var d=this.elements[this.previous];
			if(d&&!this.selfHidden){
				if (!this.checkForOpenedSliders(d)) {
					for(var c in this.effects){
						d.setStyle(c,d[this.effects[c]]);
					}
				}
			}
		}
		a=($type(a)=="element")?this.elements.indexOf(a):a;
		if((this.timer&&this.options.wait)||(a===this.previous&&!this.options.alwaysHide)){return this;}
		this.previous=a;
		var e={};
		this.elements.each(function(h,g){
			e[g]={};
			var f;
			if(g!=a){
				f=!this.checkForOpenedSliders(this.elements[g]);
			}else{
				if(this.options.alwaysHide&&((h.offsetHeight>0&&this.options.height)||h.offsetWidth>0&&this.options.width)){
					f=!this.checkForOpenedSliders(this.elements[g]);
					if (f) {
						this.selfHidden=true;
					}
				}
			}
			this.fireEvent(f?"background":"active",[this.togglers[g],h]);
			for(var j in this.effects){
				e[g][j]=f?0:h[this.effects[j]];
			}
		},this);
		this.internalChain.chain(function(){
			if(this.options.returnHeightToAuto&&!this.selfHidden){
				var f=this.elements[a];
				if(f){
					f.setStyle("height","auto");
				}
			}
		}.bind(this));
		return b?this.start(e):this.set(e);
	}
});

Element.Events.mousestill={
	onAdd:function(a){
		this.addEvent('mouseover',function(){
			Events.mmTimer=a.delay(300, this);
		});
		this.addEvent('mouseout',function(){
			$clear(Events.mmTimer);
		});
	}
}

var mTimer = null;
window.addEvent('load', function(){
	var nav = navigator.userAgent.toLowerCase();
	var UA = nav.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/) || [null, 'unknown', 0];
	var navMode = UA[1] == 'ie' && document.documentMode;
	var navName = (UA[1] == 'version') ? UA[3] : UA[1];
	var navVersion = navMode || parseFloat((UA[1] == 'opera' && UA[4]) ? UA[4] : UA[2]);

	var container  = $$(".master_container")[0];
	var obj =  container.getElement(".header .custompage");
	var box = $$(".master_container .header .custompage .box");
	if (box[0] == undefined) return;
	var initH = box[0].getPosition().y;
	var tmpH = box[box.length - 1].getPosition().y;
	if (tmpH > initH) {
		var objClone = new Element("img", {"src":IMG_MENU_SUBSTITUTE, "class": "menu_icon"});
		objClone.inject(obj, "top");

		objClone.addEvent('mouseenter', function() {
			if (mTimer != null) {
				$clear(mTimer);
				mTimer = null;
			}
			mTimer = function() {
				var ul = $$(".master_container .header .custompage ul.sublist")[0];
				ul.fade('in');
			}.delay(100);
		});
		objClone.addEvent('mouseleave', function() {
			if (mTimer != null) {
				$clear(mTimer);
				mTimer = null;
			}
			mTimer = function() {
				var ul = $$(".master_container .header .custompage ul.sublist")[0];
				$$(".master_container .header .custompage ul.sublist")[0].fade('out')
			}.delay(100);
		});
		var p = objClone.getPosition();
		var subList = new Element("ul", {
			"class": 'sublist',
			"styles": {"opacity": 0,"top":box[0].offsetHeight,"position": 'absolute'},
			"events": {
				"mouseenter": function(){
					if (mTimer != null) {
						$clear(mTimer);
						mTimer = null;
					}
					mTimer = function() {
						var ul = $$(".master_container .header .custompage ul.sublist")[0];
						ul.fade('in');
					}.delay(100);
				},
				"mouseleave": function(){
					if (mTimer != null) {
						$clear(mTimer);
						mTimer = null;
					}
					var mTimer = function() {
						var ul = $$(".master_container .header .custompage ul.sublist")[0];
						ul.fade('out');
					}.delay(100);
				}
			}
		});

		obj.adopt(subList);
		var xImg = new Image();
		xImg.onload = function() {
			var xw = 0;
			var i = box.length - 1;
			while (tmpH > initH) {
				if (box[i] == undefined) {
					break;
				}
				if (box[i].offsetWidth > xw) xw = box[i].offsetWidth;
				box[i].getElement(".row_top .cell_left").getElement("img").src = IMG_MENU_SUBSTITUTE2;
				box[i].getElement(".row_top .cell_right").getElement("img").src = IMG_MENU_SUBSTITUTE3;
				box[i].dispose();
				tmpH = box[i - 1].getPosition().y;
				var itm = new Element("li").adopt(box[i]);
				box[i].inject(itm);
				itm.inject(subList, 'top');
				--i;
			}

			if (navName + parseInt(navVersion, 10) === 'ie7') {
				var fixBoxWidth = obj.offsetWidth;
				var m = objClone.getStyle('margin').split(' ');
				fixBoxWidth = objClone.getSize().x + (parseInt(m[1]) || 0) + (parseInt(m[3]) || 0);
				for (var i = 0; i < obj.childNodes.length; i++) {
					if (obj.childNodes[i].className == 'box') {
						var m = objClone.getStyle('margin').split(' ');
						fixBoxWidth += obj.childNodes[i].getSize().x + (parseInt(m[1]) || 0) + (parseInt(m[3]) || 0);
					}
				}
				obj.setStyle('width', fixBoxWidth);
			}

			var c = $$(".master_container .header .custompage")[0].getCoordinates();
			subList.setStyle("width", xw + "px");
			obj.setStyle('visibility', 'visible');
			subList.setStyle("left", (c.width - subList.offsetWidth) + "px");

		};
		xImg.src = IMG_MENU_SUBSTITUTE
	} else {
		obj.setStyle('visibility', 'visible');
	}
});

function resetParentHeights(elements_parent) {
	var menu_container = $('menu_container');
	while(elements_parent != menu_container) {
		var height = elements_parent.getStyle('height');
		if (height != '0px' && height != 'auto') {
			elements_parent.setStyle('height', 'auto');
		}
		elements_parent = elements_parent.getParent();
	}
}

var rAccordion = new Class({
	initialize: function(container, toggleClass, elementClass, options){
		this.container = container;
		this.tClass = toggleClass;
		this.eClass = elementClass;
		this.options = options;
		this.selector = '#' + this.container + ' > .';
		this.makeAccordion(true);
	},
	makeAccordion: function(processRecursively){
		var item2show = -1;
		var items_iterator = 0;
		var options = this.options;
		$$(this.selector+this.eClass).each(function(e){
			if (e.hasClass('opened')) {
				item2show = items_iterator;
			}
			items_iterator++;
		});
		if (item2show != -1) {
			options.show = item2show; // or .display for animation
		} else {
			options.show = false; // or .display for animation
		}
		new Accordion(
			$$(this.selector+this.tClass),
			$$(this.selector+this.eClass),
			options
		).addEvents({
			'onActive': function(toggle){
				var elements_parent = toggle.getParent();
				resetParentHeights(elements_parent);
			},
			'onComplete': function(a){
				if ($defined(a)) {
					var height = 0;
					a.getParent().getChildren().each(function(e){
						height = height + e.offsetHeight;
					});
					if(height != a.getParent().offsetHeight && a.getParent().offsetHeight != 0) a.getParent().setStyle('height','');
				}
			},
			onBackground: function(toggle, content) {
				var elements_parent = toggle.getParent();
				resetParentHeights(elements_parent);
				toggle.removeClass('open');
			}
		});
		if (processRecursively) {
			this.selector += this.eClass + ' > div > .menusubitems > .'; // div is due to a slide object
			if ($defined($$(this.selector)[0])) this.makeAccordion(true);
		}
	}
});

var rAccordionObj;
function initMenuSubElements(elm) {
	var div_sep = elm.getChildren('div.sep')[0];
	if ($defined(div_sep)) {
		div_sep.setStyle('cursor', 'pointer');
		if (div_sep.getStyle("display") == "none") div_sep.setStyle("display","");

		var itemsDiv = elm.getChildren('div.menusubitems')[0];

		var myFx = new Fx.Slide(itemsDiv);
		if (!elm.hasClass('opened')) {
			myFx.hide();
		} else {
			for (cssIterator=1; cssIterator<=10; cssIterator++) {
				var classNameDown_ = "lv" + cssIterator;
				var classNameUp_   = "lv" + cssIterator + "_1";
				if (div_sep.hasClass(classNameDown_)) {
					div_sep.removeClass(classNameDown_);
					div_sep.addClass(classNameUp_);
					break;
				}
			}
		}
		div_sep.addEvent('click', function(e) {
			var elements_parent = this.getParent();
			resetParentHeights(elements_parent);
			var itemsdDiv = elements_parent.getElement('div.menusubitems');
			var notloadedDiv = itemsdDiv.getChildren('div.menu_not_loaded')[0];
			for (cssIterator=1; cssIterator<=10; cssIterator++) {
				var classNameDown_ = "lv" + cssIterator;
				var classNameUp_   = "lv" + cssIterator + "_1";
				if ($(this).hasClass(classNameDown_)) {
					$(this).removeClass(classNameDown_);
					$(this).addClass(classNameUp_);
					if ($defined(notloadedDiv)) {
						if (notloadedDiv.getStyle("display") == "none") notloadedDiv.setStyle("display","");
						var divnotloadedid = notloadedDiv.get('id');
						var idstructure = divnotloadedid.split('_');
						idstructure[1] = parseInt(idstructure[1], 10);
						idstructure[2] = parseInt(idstructure[2], 10);
						myFx.toggle().chain(function() {
							var req = new Request.HTML({
								method: 'get',
								url: 'ajax_menu_subitems_load.php?nc=1',
								data: { 'categoryid': idstructure[1], 'level': idstructure[2] },
								onRequest: function() {},
								update: itemsdDiv,
								onComplete: function(response) {
									myFx.hide();
									var new_items = itemsdDiv.getElements('.element');
									if ($defined(new_items)) {
										new_items.each(function(elm) {
											initMenuSubElements(elm);
										});
										rAccordionObj.selector = '#' + rAccordionObj.container + ' > .';
										for (lvlIterator=0; lvlIterator<idstructure[2]; lvlIterator++) {
											rAccordionObj.selector += rAccordionObj.eClass + ' > div > .menusubitems > .'; // div is due to a slide object
										}
										if ($defined($$(rAccordionObj.selector)[0])) {
											rAccordionObj.makeAccordion(false);
										}
									}
									myFx.toggle();
								}
							}).send();
						});
					} else {
						myFx.toggle();
					}
					break;
				}
				if ($(this).hasClass(classNameUp_)) {
					$(this).removeClass(classNameUp_);
					$(this).addClass(classNameDown_);
					myFx.hide();
					break;
				}
			}
		});
	}
}

window.addEvent('domready', function(){
	/* create slide areas */
	if ($defined($$('.element')[0])) {
		$$('.element').each(function(elm) {
			initMenuSubElements(elm);
		});
	}

	rAccordionObj = new rAccordion('menu_container', 'toggle', 'element', {
		opacity: false,
		display: false,
		alwaysHide:true,
		trigger: 'mousestill',
		onActive: function(toggle){},
		onBackground: function(toggle){}
	});

	$$('img').each(function(el) {
		if (el.getProperty('title') == null) {
			if (el.getProperty('alt') != null) {
				el.setProperty('title', el.getProperty('alt'));
			}
		}
	});

	if ($$(".airleft")) {
		$$(".airleft").setStyle("width", "50%");
		$$(".airright").setStyle("width", "50%");
	}
});

var Debug = {
	add:function() {
		var D = $("x_debug__x");
		if (!D) {
			var D = new Element("div",{id:"x_debug__x"}).setStyles({"width":"400px","padding":"2px","border":"1px solid #999999","background-color":"#000000","position":"absolute","z-index":"999999","top":"0px","right":"0px"});
			D.adopt(new Element("input",{type:"button",value:"close"}).addEvent("click",Debug.close));
			D.adopt(new Element("input",{type:"button",value:"empty"}).addEvent("click",Debug.empty));
			D.adopt(new Element("div"));
			document.body.adopt(D);
		} else if  (D.getStyle("display") == "none") {
			D.setStyle("display","block");
		}
		txt = '';
		for(var i=0; i<arguments.length; i++) {
			txt += arguments[i] + " | ";
		}
		txt = txt.substr(0, txt.length - 3);
		var tmp = new Element("div").setStyles({"padding":"2px","border-bottom":"1px solid #999999","color":"#ffffff"}).set("text", txt);
		D.getChildren("div").adopt(tmp);
	},
	empty:function(){
		var D = $("x_debug__x");
		if (!D) return;
		D.getChildren("div")[0].empty();
	},
	close:function() {
		var D = $("x_debug__x");
		if (!D) return;
		Debug.empty();
		D.setStyle("display","none");
	}
}

function renderizeBox(objs) {
	for (var i = 0, n = objs.length; i < n; i++) {
		objs[i].style.height = objs[i].parentNode.offsetHeight + "px";
	}
}


var Asset={javascript:function(f,d){d=$extend({onload:$empty,document:document,check:$lambda(true)},d);
if(d.onLoad){d.onload=d.onLoad;}var b=new Element("script",{src:f,type:"text/javascript"});var e=d.onload.bind(b),a=d.check,g=d.document;delete d.onload;
delete d.check;delete d.document;b.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e();}}}).set(d);if(Browser.Engine.webkit419){var c=(function(){if(!$try(a)){return;
}$clear(c);e();}).periodical(50);}return b.inject(g.head);},css:function(b,a){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:b},a)).inject(document.head);
},image:function(c,b){b=$merge({onload:$empty,onabort:$empty,onerror:$empty},b);var d=new Image();var a=document.id(d)||new Element("img");["load","abort","error"].each(function(e){var g="on"+e;
var f=e.capitalize();if(b["on"+f]){b[g]=b["on"+f];}var h=b[g];delete b[g];d[g]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;
}d=d.onload=d.onabort=d.onerror=null;h.delay(1,a,a);a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(d,c){c=$merge({onComplete:$empty,onProgress:$empty,onError:$empty,properties:{}},c);
d=$splat(d);var a=[];var b=0;return new Elements(d.map(function(e){return Asset.image(e,$extend(c.properties,{onload:function(){c.onProgress.call(this,b,d.indexOf(e));
b++;if(b==d.length){c.onComplete();}},onerror:function(){c.onError.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();}}}));}));}};
