/* licuit interactive S.L. */
/* globalscripts.js */
/* Created Jan, 2010 */
/* Modified Jan, 2010
--------------------------------------- */

var appCore = new licuitCore.appCore();
window.addEvent("domready", function(){
	appCore.replaceFonts();
	resizeMenuToWindow();
	
	$("btnNoticias").addEvent("click",function(){newsTab.toggle(); });
	$$(".leermas").addEvent("click",function(){newsTab.open(this.get("new")); });

});
window.addEvent("load", function(){
	appCore.replaceFonts();			
	resizeMenuToWindow();
});


licuitCore.newsTab = new Class({
        Extends: licuitCore.licuit,
		
		fx : null,
		fx2 : null,

		tabElem:null,
		opened:false,
		posicion: null,
		
		initialize: function(){},
		
		setup: function(){
			var tClass = this;
			
			this.tabElem = $("newsTab");
			this.fx = new Fx.Tween(this.tabElem, {duration: 1000, transition: Fx.Transitions.Quad.easeInOut}).addEvent('onComplete', function(){
								
					if(slider == undefined){
						makeScrollbar( $('cajaNoticias'), $('scrollbar'), $('handle') );
						
					}
						
					if (tClass.posicion != null)
						slider.set(tClass.posicion)
					
					$("handle").setStyle('visibility', 'visible');
				

			})
			this.fx2 = new Fx.Tween(this.tabElem, {duration: 1000, transition: Fx.Transitions.Quad.easeInOut});
		},
		
		toggle: function(){
			if(this.opened == false)
				this.open();
			else
				this.close();
		},
		
		open: function(id){
		
			if(this.opened != true){
				this.fx.cancel();
				this.fx.start("width",this.tabElem.offsetWidth + "px","600px");
			}
			if(id != null){
				
				this.posicion = $(id).offsetTop-$("cajaNoticias").offsetTop - 25;
				
				if (this.posicion != null)
						slider.set(this.posicion)
			}
	
			this.opened = true;
	
		},
		
		close: function(){
			$("handle").setStyle('visibility', 'hidden');

			document.location.hash = "";

			this.fx2.cancel();
			this.fx2.start("width",this.tabElem.offsetWidth + "px","0px");
			this.opened = false;
		}
});

var resizeMenuToWindow = function(){
	var alto = document.documentElement.clientHeight;
	var altocontenido = $('contents').getStyle('height').split('px')[0];
	
	
	if ( altocontenido >= alto ) 
		alto = altocontenido;
	
	$("newsTab").setStyle("height",alto + "px");
	$("mainTab").setStyle("min-height",alto + "px");
	$("contents").setStyle("min-height",alto + "px");
}


var slider;
		
var makeScrollbar = function(content,scrollbar,handle){
	
	var steps = parseInt(content.getSize().y) - parseInt(scrollbar.getSize().y);
	slider = new Slider(scrollbar, handle, {
		 duration: 1000,
    transition: Fx.Transitions.Pow.easeOut,

		steps: steps,
		mode: 'vertical',
		onChange: function(step){
			content.setStyle('margin-top',-step);
		}
	}).set(0);
	
}
			


var newsTab = new licuitCore.newsTab();
window.addEvent("load", function(){	newsTab.setup();if (document.location.hash == "#news") newsTab.open();
												  
});

window.addEvent("resize", function(){	resizeMenuToWindow(); });



/* FIx height imagenes with shadow*/

/*
window.addEvent("domready",function(){	
	var content = $$('.imgSombra');
	
	var height;
	for(var a = 0; a < content.length; a++){
		height = content[a].getStyle('height');
		content[a].getParent().setStyle('height', height);
	}
});
*/

