$(document).ready(function() {
	//wraping all boxes in oveflow=hidden div with static width (same as first element), and height (max height of all elements)
	//max height
	var max_height=0;
	var el=0;
	var width=0;
	width=$('.about').width();
	$('#left .submenu ul li').each(function(i) {
		var $link=$(this).find('a');
		var $href=$link.attr('href');

		if ($href.indexOf('#')>-1) {
			max_height=max_height>$($href).height()?max_height:$($href).height();
			el=i;
			//modyfing id otherwise it will be animation will jumping wrongly
			$($href).attr('id',$($href).attr('id')+'_box');
		}
	});
	
	$('.about').css({'display':'block','float':'left','width':width,'margin-right':'20px'});
	
	$('.text').css('height',max_height);
	$('.text').wrap('<div class="text-wrap" style="overflow: hidden"></div>'); //add overflow: hidden
	$('.text-wrap').css('width',width);
	
	$('.text').css('width',(width+20)*(el+1) +'px'); //20 is margin for each element
	$('.submenu a').click(function() {
	});
	
	var onHash=function(animation) {
		if (typeof(animation)=='undefined') {
			animation=true;
		} else {
			if (animation!==true) {
				animation=false;
			}
		}
		
		var hash=location.hash;
		if (hash.length==0) {
			//inaczej pobierac pierwszego hasha
			hash='#wthme'; //default
		}
		
		$('.submenu li').removeClass('active');
		$('a[href="'+hash+'"]').parents('li').addClass('active');
		
		if ($(hash +'_box').is('div.about')) {
			var widthbox=$('.about').width();
			var ela=undefined;
			$('.submenu ul li a').each(function(i) {
				var $link_temp=$(this);
				var $href_temp=$link_temp.attr('href');
				if (hash==$href_temp) {
					ela=i;
				} 
			});
			if (typeof(ela)!='undefined') {
				if(animation) {
					$('.text').stop().animate({marginLeft :(widthbox+20)*(ela)*-1 +'px'}, 300);
					//$('.text-wrap').stop().animate({height: $(hash+'_box').height() +'px'}, 300);
					
				} else {
					$('.text').css('margin-left',(widthbox+20)*(ela)*-1 +'px');
					//$('.text-wrap').css('height',$(hash+'_box').height() +'px');
				}
			}
		}
	}
	
	onHash(false);
	$(window).hashchange(function() {
		onHash();
	});	
});
