<script type="text/javascript">
	
	var global_scroll = true;
	var currentStreetNumber = -1;

	var StreetList = new Array(
		"Alojas iela",
		"Bruņinieku iela",
		"Dzirnavu iela",
		"Ganību dambis",	
		"Ģertrūdes iela",
		"Hanzas iela",
		"Jēkabpils iela",
		"Kalna iela",
		"Krišjāņa Barona iela",
		"Matīsa iela",
		"Martas iela",
		"Stabu iela",
		"Skolas iela",
		"Sporta iela",
		"Miera iela",
		"Mēness iela",
		"Rūpniecības iela",
		"Valdemāra iela"
	);
		
	
	$(document).ready(function(){
		
		$('#menu-left').height( document.body.clientHeight );

		var anchor = window.location.hash.substring(1);
		var number = getStreetNumber(anchor);
		
		if ( number == -1 ) {
			/* Init first element */
			$("#menu-left .menu-item").eq(0).addClass("menu-item-active");
			$("#toolbar-street-name").html(StreetList[0]);
		} else {
			global_scroll = false;
			$("#menu-left .menu-item").eq(number).addClass("menu-item-active");
			move_scroll_block(number);				
		}
		
	})
		
		
		
		
	function getStreetNumber(name) {
		for(var i=0; i<StreetList.length; i++) {
			if (StreetList[i] == name) return i;
		}
		return -1;
	}
	
	
	function selectStreet(number, scrollbar) {

		if ( number != -1 ) {

			currentStreetNumber = number;
			
			location.hash = StreetList[number];
			window.location="index.html" + location.hash;	
							
			$("#toolbar-street-name").html(StreetList[number]);
			
			$("#menu-left .menu-item").removeClass("menu-item-active");
			$("#menu-left .menu-item").eq(number).addClass("menu-item-active");
			

			//if ( !scrollbar ) {						
				$("#scroll .scroll-element").removeClass("scroll-element-active");
				$("#scroll .scroll-element").eq(number).addClass("scroll-element-active");	
			//}
									
		}

	}
	
	

	/******* Scroll *******/


	$(window).scroll(function () { 
		if ( global_scroll ) {
			var offset = $('div').offset();
			var number = calculateScrollElementNumber( offset.top );
			selectStreet(number, true);	
		}
	});


	function calculateScrollHeight(number) {
		
		var scroll_height = 0;
		
		for(var i=0; i<number; i++) {
			scroll_height +=  $("#scroll .scroll-element").eq(i).height();
		}
		
		return scroll_height;
	}
	

	function calculateScrollElementNumber(scroll_height) {
		
		var elements_height = 0;
		
		for(var i=0; i<StreetList.length; i++) {
			elements_height +=  $("#scroll .scroll-element").eq(i).height();  
			if ( scroll_height - 33 < elements_height  ) return i;
		}

	}		


	function move_scroll_block(number) {
		var scroll_height = calculateScrollHeight(number);
		$("html:not(:animated)" +( !$.browser.opera ? ",body:not(:animated)" : "")).animate({ scrollTop: scroll_height }, 500, function() {
			global_scroll = true;
			
		} ); 
	}
				
	
	/******* Left Menu *******/
	
	$("#menu-left .menu-item").click(function() {
		
		global_scroll = false;
		var number = $("#menu-left .menu-item").index(this);
		selectStreet( number, false);
		move_scroll_block(number);

		return false;
	});			
	
	
	
	
	/******* Dropdovn Menu *******/
	
	$(".menu-block a.switcher, .city-block a.switcher").click(function() {
		var obj = $(this).parent();
		if ( obj.is('.menu-block-open') ) obj.removeClass("menu-block-open");
		else obj.addClass("menu-block-open");
		return false;
	});	
		
	$(".menu-block nav, .city-block div.select").hover(
		function () {},
		function () {
			$(this).parent().removeClass("menu-block-open");
		}
	);	
		
	
</script>