$(document).ready(function(){
	
	$.localScroll({
		offset: {left: 0, top: -150}
	});
	
	if(location.href.indexOf('#') != -1){
		setTimeout(function(){
			$(window).scrollTop($(window).scrollTop() - 150);
		}, 10);
	}

	function setUrlHash(){
		var hashPos = location.href.indexOf('#');
		if(hashPos == -1){
			return;
		}
		var hash = location.href.substr(hashPos);
		$('a.addFragment').each(function(key, el){
			var hashPosHere = el.href.indexOf('#');
			if(hashPosHere != -1){
				el.href = el.href.substr(0, hashPosHere) + hash;
			} else {
				el.href += hash;
			}
		});
	}
	
	setUrlHash();

	$('#navCol2 a').click(function() {
		$('#navCol2 a').removeClass('selected');
		$(this).addClass('selected');
		setUrlHash();
	});
	var hashPos = location.href.indexOf('#');
	if(hashPos == -1){
		// $('#navCol2 a:first').addClass('selected');
	} else {
		var year = location.href.substr(hashPos + 5);
		$('#navCol2 a').each(function(key, el){
			if($(el).html() == year){
				$(el).addClass('selected');
			}
		});
	}
	
	// sidebar
	$('#navCol1 ul a').click(function(){
		$('.sidebar').hide();
		$('#navCol1 a').removeClass('selected');
		$(this).addClass('selected');
	});
	
	$('#showNews').click(function() {
		$('#news').show();
	});
	$('#showAbout').click(function() {
		$('#about').show();
	});
	$('#showClients').click(function(){
		$('#clients').show();
	});	
	$('#showContact').click(function(){
		$('#contact').show();
	});	
	$('#showMerOrder').click(function(){
		$('#merOrder').show();
	});	
	$('#showMerContact').click(function(){
		$('#merContact').show();
	});	
	$('#showMerInfo').click(function(){
		$('#merInfo').show();
	});	
	$('#showAudiomerOrder').click(function(){
		$('#audiomerOrder').show();
	});	
	$('#showAudiomerContact').click(function(){
		$('#audiomerContact').show();
	});	
	$('#showAudiomerInfo').click(function(){
		$('#audiomerInfo').show();
	});	
	$('.sidebar').hide();
		
	$('.noJs').hide();
	
	// slideshow
 	$('#slideshow').cycle({
		fx: 'fade',
		timeout: 0,
		prev: '#test',
		onPrevNextEvent: function(isNext, zeroBasedSlideIndex, slideElement){
			$('#total').html((zeroBasedSlideIndex + 1) + ' / ' + $('#slideshow img').length);
			if(zeroBasedSlideIndex != 0){
				$('#prev').css('visibility', '');
			} else{
				$('#prev').css('visibility', 'hidden');
			}
			if(zeroBasedSlideIndex < ($('#slideshow img').length - 1)){
				$('#next').css('visibility', 'visible');
			} else{
				$('#next').css('visibility', 'hidden');
			}
		}
	});
	$('#prev').html('<a href="">prev</a>').css('visibility', 'hidden');
	$('#next').html('<a href="">next</a>');
	$('#next').click(function(e){
		$('#slideshow').cycle('next');
		e.preventDefault();
	});
	$('#prev').click(function(e){
		$('#slideshow').cycle('prev');
		e.preventDefault();
	});
	
});
