var SK = {expanded:false};
$(document).ready(function(){
	
	//$('.scrollable').tinyscrollbar();
	

	function getBottomHeight(expanded){
		var procent = 0.55;
		var height = 0;
		
		if(expanded) procent = 0.80;
		var windowHeight = $(window).height(), documentHeight = $(document).height();
				
		if(documentHeight > windowHeight){
			height = Math.floor(documentHeight - windowHeight*(1-procent));
		} else{
			height = Math.floor(windowHeight * procent);
		}
		//console.info($(window).height(),$(document).height());
		//console.info(height,windowHeight*(1-procent),procent);
		return height;
	}
	
	function updateBottomHeight(){
		var h = getBottomHeight(SK.expanded);
		$('#bottom').height(h+'px');
	}
	
	jQuery.event.add(window, "resize", function(){
		updateBottomHeight();
	});
    
  
	$('.menu .item').click(function(){
    	$('.contents .item').hide();
    		updateBottomHeight();
	});
	
   	$('.menu .whoweare').click(function(){   		
		$('.contents .whoweare').fadeIn(500,function() {
	        updateBottomHeight();
	      });		
    });
    
    $('.menu .whatwedo').click(function(){
    	$('.contents .whatwedo').fadeIn(500,function() {
        	updateBottomHeight();
      	});
    });
    
    $('.menu .contactus').click(function(){
    	$('.contents .contactus').fadeIn(500,function() {
	        updateBottomHeight();
	      });
    });
    
   
    $('.menu .item').click(function(){
      if(SK.expanded) return;
      
	  $("body").css("overflow","hidden");
	  var bottomDiv = $('#bottom');
	  $(bottomDiv).animate(
		   { height: "80%"},
		   { duration: 300, 
		     queue: false,
		
		     step: function() {
		       $(bottomDiv).css("overflow","visible");
		     }, 
		
		     complete: function() {
		       $(bottomDiv).css("overflow","visible");
		     }
		});
		
		var topDiv = $('.top');
	  	$(topDiv).animate(
		   { height: "20%"},
		   { duration: 300, 
		     queue: false,
		
		     step: function() {
		       $(topDiv).css("overflow","visible"); //ie fix
		     }, 
		
		     complete: function() {
		       $(topDiv).css("overflow","visible");
		       SK.expanded = true;
		       
		       $("body").css("overflow","visible");
		       updateBottomHeight();
		     }
		});
	});
	
	$('#logo').click(function(){
		if(!SK.expanded) return;
		
		$('.contents .item').hide();
		$("body").css("overflow","hidden");
		var bottomDiv = $('#bottom');
		$(bottomDiv).animate(
		   { height: "55%"},
		   { duration: 300, 
		     queue: false,
		
		     step: function() {
		       $(bottomDiv).css("overflow","visible");
		     }, 
		
		     complete: function() {
		       $(bottomDiv).css("overflow","visible");
		     }
		});
		
		var topDiv = $('.top');
		$(topDiv).animate(
		   { height: "45%"},
		   { duration: 300, 
		     queue: false,
		
		     step: function() {
		       $(topDiv).css("overflow","visible"); //ie fix
		     }, 
		
		     complete: function() {
		       $(topDiv).css("overflow","visible");
		       
		       SK.expanded = false;
		       
		       $("body").css("overflow","visible");
		       updateBottomHeight();
		     }
		});
	});
   
});
