function handleLocationHash(hash){
		 $('.tour_brick').each(function(index) {
			
			   if($(this).attr('id') == 'tour_'+hash.substring(1, 100)){
				   curr_offset = index*942;
				   handleTourLinks(index);
				   $('.tour_bricks_inner').animate({
						left: '-'+curr_offset
					}, 1000, 'easeInOutSine', function(){ 
						
					});
			   }
			    
		  });
	 }
function handleTourLinks(curr){
	 $('.tour_links a').css('backgroundPosition','left top').removeClass('selected');
	 $('.tour_links a').eq(curr).css('backgroundPosition','left bottom').addClass('selected');
	 selected_a = $('.tour_links a').eq(curr);
	 if(selected_a.attr('href')){
		 window.location.hash = selected_a.attr('href').substring(selected_a.attr('href').indexOf("#")+1, 100);
	 }

}
$(document).ready(function(){
	 $('.view_courses').click(function(){
		 $(this).parent().children('.show_courses').toggle('slow');
		 return false;
	 });
	 $('.show_courses').mouseleave(function() {
		    $(this).toggle('slow');
	  });

	 
	 $("h2.help").mouseover(function() {
	    $(this).addClass('active_help');
	  }).mouseout(function(){
		  $(this).removeClass('active_help');
	  });
	 
	 $("img#close_message").click(function() {
		 $('#message_container').hide('slow');
	 });
	 $("h2.help").click(function() {
		 if($(this).parent().children('div.help').css('height') == '0px'){
			 $("div.help").each(function()
					 {
					    if($(this).css('height') != '0px'){
					    	
					    	$(this).animate({  
								 height: ['0px', 'easeOutBounce']}, 1000);
					    }else{
					    	//alert('aa');
					    }
					 });

			 
			 current_height = $(this).parent().children('div').children('p.help').height();
			 $(this).parent().children('div.help').animate({  
				 height: [(current_height+20)+'px', 'easeOutBounce']}, 1000);  
			 
		 }else{
			 $(this).parent().children('div.help').animate({  
				 height: ['0px', 'easeOutBounce']}, 1000);  
		 }
		 
	 });

	 $("div.help").css('height','0px');
	 
	 
	 
	 $('.tour_right').click(function(){
		 if(parseFloat($('.tour_bricks_inner').css('left')) > -3768){
			 curr = Math.abs(parseFloat($('.tour_bricks_inner').css('left')))/942;
				handleTourLinks(curr+1);
			$('.tour_bricks_inner').animate({
				left: '-=942'
			}, 1000, 'easeInOutSine', function(){ 
				if(parseFloat($('.tour_bricks_inner').css('left')) < -3768){
					$('.tour_bricks_inner').animate({
						left: '-3768'
					}, 1000);
				}
			});
		 }
		return false;
	 });
	 $('.tour_left').click(function(){
		 if(parseFloat($('.tour_bricks_inner').css('left')) < 0){
			 curr = Math.abs(parseFloat($('.tour_bricks_inner').css('left')))/942;
			 handleTourLinks(curr-1);
			$('.tour_bricks_inner').animate({
				left: '+=942'
			}, 1000, 'easeInOutSine', function(){ 
				if(parseFloat($('.tour_bricks_inner').css('left')) > 0){
					$('.tour_bricks_inner').animate({
						left: '0'
					}, 1000);
				}
			});
		 }
		return false;
	 });
	 $('.tour_links a').mouseenter(function() {
		 	if($(this).attr('class') != 'selected'){
		 		$(this).css('backgroundPosition','left bottom');
		 	}
		  }).mouseleave(function() {
			if($(this).attr('class') != 'selected'){
				$(this).css('backgroundPosition','left top');
			}
		  });
	
	 function handleTourLinks(curr){
		 $('.tour_links a').css('backgroundPosition','left top').removeClass('selected');
		 $('.tour_links a').eq(curr).css('backgroundPosition','left bottom').addClass('selected');
		 selected_a = $('.tour_links a').eq(curr);
		 if(selected_a.attr('href')){
			 window.location.hash = selected_a.attr('href').substring(selected_a.attr('href').indexOf("#")+1, 100);
		 }

	 }
	 function handleLocationHash(hash){
		 $('.tour_brick').each(function(index) {
			   if($(this).attr('id') == 'tour_'+hash.substring(1, 100)){
				   curr_offset = index*942;
				   handleTourLinks(index);
				   $('.tour_bricks_inner').animate({
						left: '-='+curr_offset
					}, 1000, 'easeInOutSine', function(){ 
						
					});
			   }
			    
		  });
	 }
	 if(window.location.hash) {
		 handleLocationHash(window.location.hash);
	  }

	 
});

