var Slide = function(obj, selector)
{
	var self = this;
	obj = $(obj);
	var slider = $(selector);

	this.calculate = function()
	{
  		return {"height": obj.outerHeight(), "width": obj.outerWidth(), 
  				"left": self.getAbsX(obj) - self.getAbsX($("#yellow")), 
  				"top": self.getAbsY(obj) - self.getAbsY($("#yellow"))};
	}
	this.slide = function(step)
	{
  		if(slide_timeout)
			clearTimeout(slide_timeout);
			
		slider.stop().animate(this.calculate(), 800, "easeOutBack");
  		$(".floating_navigation .white_link").stop().removeClass("white_link").animate({color: "#333"}, 300);
  		if(step == 1)
  		{
  			if(!obj.hasClass("active"))
  				obj.children().addClass("white_link");
  				
			slide_timeout = setTimeout(function() {
				$(".floating_navigation .white_link").stop().animate({color: "#FFF"}, 300);
			}, 300);
		}
	}
	this.move = function()
	{
  		slider.css(this.calculate());
	}
	this.show = function()
	{
		this.move();
		slider.fadeIn("fast");
		obj.children().addClass("white_link").animate({color: "#FFF"}, 300);
	}
	this.clear = function()
	{
  		slider.fadeOut("fast");
  		slide_timeout = setTimeout(function(){
			$(".floating_navigation .white_link").removeClass("white_link").animate({color: "#333"}, 300);
    	}, 200);
	}
	this.getAbsY = function( oElement )
	{
  		var iReturnValue = 0;
		if(oElement != null)
  		{
			iReturnValue += oElement.offset().top;
    		oElement = oElement.parent();
    	}
  		return iReturnValue;
	}
	this.getAbsX = function( oElement )
	{
  		var iReturnValue = 0;
  		if(oElement != null)
  		{
			iReturnValue += oElement.offset().left;
    		oElement = oElement.parent();
    	}
  		return iReturnValue;
	}
	return this;
};

var slide_timeout;

$(document).ready(function()
{
	if(_controller == 'index')
	{
		var src = _baseUrl + "/images/menu/menu.png";
		pictures[src] 		= new Image;
    	pictures[src].src 	= src;
    }
	
	var sl;
	var active = $("#menu li.active");
	var counter = 0;
	
	if(!$(".floating_navigation li").hasClass("active")) {
		active = false;
	}
	
	if(active != false) {
		sl = new Slide(active, ".univers").move();
		$(".univers").show();
		
		sl = new Slide(active, ".hilite").move();
		$(".hilite").show();
	}
	
	$(".floating_navigation .menu").mouseover(function() {		
		if(active || counter == 2){
			sl = new Slide(this, ".hilite").slide(1);
		} else if(counter == 1) {
			sl = new Slide(this, ".hilite").slide(1);
			counter++;
		} else if(counter == 0) {
			sl = new Slide(this, ".hilite").show();
			counter = 1;
		}
	});
	
	$(".floating_navigation .menu").mouseout(function() {
		if(slide_timeout)
			clearTimeout(slide_timeout);
		$(this).children().stop().animate({color: "#FFF"}, 300);	
		slide_timeout = setTimeout(function() {
			if(active){
				sl = new Slide(active, ".hilite").slide(0);
			} else {
				sl = new Slide(active, ".hilite").clear();
				counter = 0;
			}	
		}, 2000);
	});
});