$(document).ready(function() {
	$('ul.bigimage li').hide(); 

	//enable browser backbutton//
	$(window).bind('hashchange', function(){
		var hash = window.location.hash.substr(1);	
		if(hash){
			if(hash=='about'){
				location.hash = 'about';
				$('ul.bigimage li').hide();
				$('.previousnext').hide();
				$('ul.smallimage li').hide();
				$('#aboutlink').hide();
				$('#return:hidden:first').show();
				$(".abouttheproject:hidden:first").show();
			}else {
				hash=Number(hash);
				if(!isNaN(hash)){
					$(".abouttheproject").hide();
					$('#return').hide();
					$('#aboutlink').show();
					$('ul.smallimage li').hide();
					$(".previousnext:hidden:first").fadeIn();
					$('ul.bigimage li').hide();
					$('ul.bigimage li').eq(hash-1).fadeIn().addClass('zoomed');
					var hash = window.location.hash.substr(1);	
					var caption = hash + ' of ' + $('ul.bigimage li').length; 
	 				$('#capt').html(caption); 

				}
			}
		}else{
				$('ul.bigimage li').hide();
				$('.previousnext').hide();
				$('ul.smallimage li').show();
				$('#aboutlink').show();
				$('#return').hide();
				$(".abouttheproject").hide();;
		}
	});
	
	$(window).trigger("hashchange");
	
	//change homepage image here!
	var backgroundIndex = Math.floor(Math.random()*7);
	switch(backgroundIndex){
				case 0:
					$('#indeximg').html("<img src='images/index/qatar_7.jpg'>");
					break;
				case 1:
					$('#indeximg').html("<img src='images/index/qatar_12.jpg'>");
					break;
				case 2:
					$('#indeximg').html("<img src='images/index/miami_1.jpg'>");
					break;
				case 3:
					$('#indeximg').html("<img src='images/index/pitts_2.jpg'>");
					break;
				case 4:
					$('#indeximg').html("<img src='images/index/pitts_6.jpg'>");
					break;
				case 5:
					$('#indeximg').html("<img src='images/index/southboston_1.jpg'>");
					break;
				case 6:
					$('#indeximg').html("<img src='images/index/yellowstone_1.jpg'>");
					break;
			}
	
	$('.smallimage span').hover(
		function () {
			$(this).fadeTo(100,0);
		}, 
		function () {
			$(this).fadeTo(100,.90);
		}
	);
	

	$('ul.smallimage li').click(function(){
		$('ul.smallimage li').fadeOut();
		$(".previousnext:hidden:first").fadeIn('fast');
		var hash = window.location.hash.substr(1);	
		hash=Number(hash)
		var caption = hash + ' of ' + $('ul.bigimage li').length; 
	 	$('#capt').html(caption); 
		var zoomIndex = $(this).index();
		$('ul.bigimage li').eq(zoomIndex).fadeIn().addClass('zoomed');	
		location.hash = zoomIndex+1;
	});
	
	$('ul.bigimage li').click(function(){
		$('ul.bigimage li.zoomed').fadeOut('fast').removeClass('zoomed');
		$(".previousnext").fadeOut('fast');
		$('ul.smallimage li').show();
	});
	
	$('#return').click(function(){
		$('.abouttheproject').fadeOut('fast');
		$('ul.smallimage li').show();
		$('#aboutlink').show();
		$('#return').hide();

	});
	
	$('a#aboutlink').click(function(){
		location.hash = 'about';
		$('ul.bigimage li').fadeOut();
		$('.previousnext').fadeOut();
		$('ul.smallimage li').fadeOut();
		$('#aboutlink').hide();
		$('#return:hidden:first').show();
		$(".abouttheproject:hidden:first").fadeIn('fast');
		return false;	
	});
	
	$('#next').click(function(){
		var hash = window.location.hash.substr(1);	
		hash = Number(hash);
		if(hash){
			if(hash >= $('ul.bigimage li').length){
			}else{
			if(hash < $('ul.bigimage li').length){
		$('ul.bigimage li.zoomed').hide().removeClass('zoomed').next().addClass('zoomed').fadeIn();
		location.hash = Number(window.location.hash.substr(1))+1;	
			}		
		}
		}
		if(hash){
			if(hash >= $('ul.bigimage li').length){
			}else{
			if(hash < $('ul.bigimage li').length){
		var caption = (hash+1) + ' of ' + $('ul.bigimage li').length; 
	 	$('#capt').html(caption); 
	 		}
		}
		}
		});

	
	$('#previous').click(function(){
		var hash = window.location.hash.substr(1);	
		hash = Number(hash);
		if(hash){
			if(hash <= 1){
			}else{
			if(hash > 1){
		$('ul.bigimage li.zoomed').hide().removeClass('zoomed').prev().addClass('zoomed').fadeIn();
		location.hash = Number(window.location.hash.substr(1))-1;	
			}
		}		
		}
		if(hash){
			if(hash <=2){
			}else{
			if (hash>1){
			var caption = (hash-1) + ' of ' + $('ul.bigimage li').length; 
	 	$('#capt').html(caption); 
			}
			}
		}
		});
	
		var backgroundIndex = Math.floor(Math.random()*10);
		switch(backgroundIndex){
				case 0:
					$('#aboutimg').html("<img src='images/about/bioimage.jpg'>");
					break;
				case 1:
					$('#aboutimg').html("<img src='images/about/bioimage_2.jpg'>");
					break;
				case 2:
					$('#aboutimg').html("<img src='images/about/bioimage_3.jpg'>");
					break;
				case 3:
					$('#aboutimg').html("<img src='images/about/bioimage_4.jpg'>");
					break;
				case 4:
					$('#aboutimg').html("<img src='images/about/bioimage_5.jpg'>");
					break;
					case 5:
					$('#aboutimg').html("<img src='images/about/bioimage_6.jpg'>");
					break;
				case 6:
					$('#aboutimg').html("<img src='images/about/bioimage_7.jpg'>");
					break;
				case 7:
					$('#aboutimg').html("<img src='images/about/bioimage_8.jpg'>");
					break;
				case 8:
					$('#aboutimg').html("<img src='images/about/bioimage_9.jpg'>");
					break;
					break;
				case 9:
					$('#aboutimg').html("<img src='images/about/bioimage_9.jpg'>");
					break;
					
				

			}
		
	
});

