/** zoomer do menu */
var $j = jQuery.noConflict();
$j(window).load(
function () {
	
	var animDelay = 200;
	
	var ct = jQuery('#icons')[0];
	var links = jQuery('#icons img');
	var shrinkBy = 0.714;
	
	function deactivateTopMenu () {
		var menus = {
				current_page_ancestor: function() {return $j('#menu-nav > li.current_page_ancestor');}, 
				current_page_parent: function() {return $j('#menu-nav > li.current_page_parent');}, 
				current_page_item: function() {return $j('#menu-nav > li.current_page_item');} 
		};
		
		var m;
		for(var cls in menus) {
			m = menus[cls]();
			if (m) {
				m.removeClass(cls);
			}
		};
	};
	
	function killHomeMovie() {
		if(Monad.globals.homeMovie) {
			Monad.globals.homeMovie.destroy();
		}
		
	}
	
	links.each(function(idx, elem) {
		var je = jQuery(elem);
		elem.__bigHeight = je.height();
		elem.__bigWidth = je.width();
		elem.__smallHeight = elem.__bigHeight * shrinkBy; 
		elem.__smallWidth = elem.__bigWidth * shrinkBy;
		elem.__panX = (elem.__bigWidth - elem.__smallWidth) / 2;
		elem.__panY = 10;
		
		je.height(elem.__smallHeight);
		je.width(elem.__smallWidth);
		elem.__pos = je.position();
		
	});
	
	
	links.each(function(idx, elem) {
		var p = elem.__pos;
		
		elem.style.position = 'absolute';
		elem.style.left = p.left + 'px';
		elem.style.top = p.top + 'px';
		
		elem.zoomIn = function(delay) {
			if(!this.__grew) {
				this.__grew = true;
				jQuery(this).animate({
					left: '-=' + this.__panX + 'px',  
					top: '-=' + this.__panY + 'px', 
					width: this.__bigWidth + 'px', 
					height: this.__bigHeight + 'px'
				}, delay);
			}
		}
		
		elem.zoomOut = function(delay) {
			if(this.__grew) {
				this.__grew = false;
				jQuery(this).animate({
					left: '+=' + this.__panX + 'px',  
					top: '+=' + this.__panY + 'px',
					width: this.__smallWidth + 'px', 
					height: this.__smallHeight + 'px'
				}, delay);
			}
		}
		
	});
		
	links.mouseenter(function() {
		this.zoomIn(animDelay);
	});
	
	links.mouseleave(function() {
		if(!this.__active) this.zoomOut(animDelay);
	});
	
	
	links.click(function() {
		if (!this.__active) {
			killHomeMovie()
			deactivateTopMenu();
			links.each(function(idx, elem){
				if(elem.__active) {
					elem.__active = false;
					elem.zoomOut(animDelay);
					return false;
				}
			});
			this.__active = true;
		}
		
		//Monad.globals.hashManager.setParam('i', this.getAttribute('tabindex'));		
	});
	
	ct.style.visibility = 'visible';
	
	/*
	Monad.globals.hashManager.on('load', function(params) {
		if('i' in params) {
			var act = jQuery('#icons img[tabindex="'+ params.i +'"]').get(0);
			if(act) {
				act.zoomIn(0);
				act.__active = true;
			}
		}
	}, this);
	*/	
});

