$(document).ready(function(){
	lavaMenu();
	if($('#startPage').length) {
		startPage();
	}
});

//lavaMenu();
function lavaMenu() {
	//transitions  
	//for more transition, goto http://gsgd.co.uk/sandbox/jquery/easing/  
	var style = 'easeOutElastic';
	//Retrieve the selected item position and width  
	var default_left = Math.round($('#mainMenuBox li.activeMenu').offset().left - $('#mainMenuBox').offset().left);  
	var default_width = $('#mainMenuBox li.activeMenu').width();
	//Set the floating bar position and width  
	$('#lavaBox').css({left: default_left});  
	$('#lavaBox .headBox').css({width: default_width});  
	//if mouseover the menu item  
	$('#mainMenuBox li').hover(function () {  
		//Get the position and width of the menu item  
		left = Math.round($(this).offset().left - $('#mainMenuBox').offset().left);  
		width = $(this).width();   
		//Set the floating bar position, width and transition  
//		$('#lavaBox').stop(false, true).animate({left: left},{duration:1000, easing: style});     
		$('#lavaBox').stop(false, true).animate({left: left},{duration:500});     
//		$('#lavaBox .headBox').stop(false, true).animate({width:width},{duration:1000, easing: style});         
		$('#lavaBox .headBox').stop(false, true).animate({width:width},{duration:500});         
	//if user click on the menu
	}).click(function () {
		if($(this).hasClass('activeMenu')) {
			return false;
		}
		else {
			//reset the selected item  
			$('#mainMenuBox li').removeClass('activeMenu');    
			//select the current item  
			$(this).addClass('activeMenu');

			menuEngine($(this).attr('id'));
			return false;
		}
	});       
	//If the mouse leave the menu, reset the floating bar to the selected item  
	$('#mainMenuBox').mouseleave(function () {  
		//Retrieve the selected item position and width  
		default_left = Math.round($('#mainMenuBox li.activeMenu').offset().left - $('#mainMenuBox').offset().left);  
		default_width = $('#mainMenuBox li.activeMenu').width();  
		//Set the floating bar position, width and transition  
//		$('#lavaBox').stop(false, true).animate({left: default_left},{duration:1500, easing: style});     
		$('#lavaBox').stop(false, true).animate({left: default_left},{duration:1000});     
//		$('#lavaBox .headBox').stop(false, true).animate({width:default_width},{duration:1500, easing: style});
		$('#lavaBox .headBox').stop(false, true).animate({width:default_width},{duration:1000});
	});  	
}

/**
 * funkcja obsługuje wymianę danych po kliknięciu przycisku menu
 * 
 * REZYGNUJEMY Z AJAXa
 * 
 * @param menuId
 * @return
 */
/*
function menuEngine(menuId) {
	//czyścimy zawartość głównego okna
	var pageName = menuId.replace('Menu', '');
	if(menuId != 'mainsMenu') {
		//alert('STOP!');
		$('.kwicks').fadeOut(700);
		$('#mainPageText').fadeOut(700, function(){
			$('#mainBoxHandle').load('views/'+pageName+'/display.php', function(){
				$('#mainBoxHandle').fadeIn(1500);
			});
		});	
	}
	else {
		//alert(pageName);
		$('#mainBoxHandle').children().fadeOut(1700, function(){
			$('#mainBoxHandle').empty();
			$('.kwicks').fadeIn(500);
			$('#mainPageText').fadeIn(500);	
		});
	}
}
*/

