$(function(){
	// if we are on the district page, remove the district nav options when hover over the neighbourhood ones
	$('#nav_neighbourhood').hover(function(){
		$('#nav_district ul').hide();			
	}, function () {
		$('#nav_district ul').show();
	});	
	
	// if we are on the neighbourhood page, remove the neighbourhood nav options when hover over the district ones
	$('#nav_district').hover(function(){
		$('#nav_neighbourhood ul').hide();			
	}, function () {
		$('#nav_neighbourhood ul').show();
	});	
	
	//init Lighbox for the Floorplans or anything with rel="lightbox"
	$('[rel=lightbox]').lightBox();
	
	//randomize sidebar quotes
	$('#sidecol_masthead').ready(function(){
	      var $quotes = $(this).find('blockquote');
	      var n = $quotes.length;
	      var random = Math.floor( Math.random()*n );
	      $quotes.hide().eq(random).fadeIn('slow');
	});	
	
	// setting up the tabbed navigation for the Interactive Map Page
	$('ul.tabNav a').click(function() {
		var curChildIndex = $(this).parent().prevAll().length + 1;
		$(this).parent().parent().children('.current').removeClass('current');
		$(this).parent().addClass('current');
		$('ul.tabNav a').removeClass('current');	// remove the current class from all main nav items							
		$(this).addClass('current');				// add it to where we just clicked
		
		//fade in and out the content tabs
		$(this).parent().parent().next('.tabContainer').children('.current').fadeOut('fast',function() {
			$(this).removeClass('current');
			$(this).parent().children('div:nth-child('+curChildIndex+')').fadeIn('fast',function() {
				$(this).addClass('current');
			});
		});
		
		//fade in and out the multiple maps
		$('#maincol_masthead').children('.current').fadeOut('fast',function() {
			$(this).removeClass('current');
			$('#maincol_masthead').children('div:nth-child('+curChildIndex+')').fadeIn('fast',function() {
				$(this).addClass('current');
			});
		});
		return false;								
	});

	// Gallery Scripts
	$('#sidecol_gallery ul').addClass('gallery_demo'); 	// adds new class name to maintain degradability
	
	$('ul.gallery_demo').galleria({
		history   : false, 									// activates the history object for bookmarking, back-button etc.
		clickNext : false, 									// helper for making the image clickable
		insert    : '#main_image', 							// the containing selector for our main image
		onImage   : function(image,thumb) { 				// let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			// FF/Win fades large images terribly slow
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { 
								image.css('display','none').show();
							}
							
			// fade in the image & caption
			image.css('display','none').show();

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// fade out inactive thumbnail
			_li.siblings().children('img.selected').hide();

			// fade in active thumbnail
			thumb.show().addClass('selected');
		},

		onThumb : function(thumb) { // thumbnail effects goes here

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.5';

			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(500);

			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.5); } // don't fade out if the parent is active
			)
		}
	});		   
});
