// JavaScript Document

$(document).ready(function(){
	var $pages = $('.page').css({'display' : 'none', 'padding' : 0});	
	var $idOpenPage = 0;
	var $uc = $('#uc-block .block-height');
	var $line = $('#menu .line');
	var $ul = $('#menu ul');
	var $ap = 48;
	var $menu_a = $('#menu a');
	
	$pages.eq($idOpenPage).show();
	
	$menu_a.each(function(index){
		var $id = index;
		
		$(this).click(function(event){
				if($(window).height() < 650) {
					if($id == 0) {
						$uc.animate({'opacity' : 1});	
					}
					else {
						$uc.animate({'opacity' : 0.5});	
					}
				}

				var $id_page = $idOpenPage;	
				$idOpenPage = $id;
				$('#' + $menu_a.eq($id_page).attr('id') + '-page').fadeOut(function(){																									 
					$('#' + $menu_a.eq($id).attr('id') + '-page').fadeIn();
				});	
			
				event.preventDefault();
		});
	});
	
	/* --- BEGIN effect hover --- */	
	var $idHover = $idOpenPage;
	var $timeOut = 60;
	var $idTimer = 0;
	
	function moveCancelTimer(){
  	if($idTimer){
      window.clearTimeout($idTimer);
      $idTimer = null;
		}
  }
	
	function moveLineOut() {
		moveLine($menu_a.eq($idOpenPage));	
	}
	
	function moveLineTimer(){			    
		$idTimer = window.setTimeout(moveLineOut, $timeOut);
  }
	
	function moveLine($jobj) {	
		moveCancelTimer();    
		$line.animate({'left' : ($jobj.parent().offset().left - $ul.offset().left)});
	}
	
	$('#menu a').bind('mouseover', function(){		
		moveLine($(this));		
	});
	
	$('#menu a').bind('mouseout', function(){		
		moveLineTimer();
	});
	/* --- END effect hover --- */
});