jQuery.preloadImages = function() 
{
  for(var i = 0; i<arguments.length; i++) 
  {
  jQuery("<img>").attr("src", arguments[i]);
  }
}

$.preloadImages("");

//sidenav on and off states
function sidenav(a)
{
	$('#nav-list>li>a').removeClass('active');
	$(a).addClass('active');
}
//hide other sections and show active one
function show_tier(tier)
{
	$('#tier-plans>div').css({'display' : 'none'});
	$(tier).css({'display' : 'block'});
}
//change header image
function change_hdr(file)
{
	$('#container #right #content h1').css({ 'background-image':'url(/images/floorplans/headers/' + file + ')'});
}
// (div to show, header file to change to, tag to add active class to, tier plan to show)
function show_section(div,a,tier)
{
	$('#fp-left>div').css({'display' : 'none'});;
	$(div).css({'display' : 'block'});
	//makes 'a' and 'tier' optional parameters
	if (typeof a != 'undefined')
	{
		sidenav(a);
	}
	if (typeof tier != 'undefined')
	{
		show_tier(tier);
	}
	
}


$(document).ready( function() 
{  
	if (window.location.search.match(/id=/)) 
	{
		show_section($('#large'));
	}		 
    
	$('A[rel="external"]').click( function() 
	{
        window.open( $(this).attr('href') );
        return false;
    }); 

	//search by floor

	// 2nd floor
	$('#floor_2').click( function() 
	{
		show_section($('div#two'), $(this), $('#tier-2'));
		change_hdr('floor_2.gif');
		return false;
	}); 
	// 4th floor
	$('#floor_4').click( function() 
	{
		show_section($('div#four'), $(this), $('#tier-4'));
		change_hdr('floor_4.gif');
		return false;
	}); 
	// 6th floor
	$('#floor_6').click( function() 
	{
		show_section($('div#six'), $(this), $('#tier-6'));
		change_hdr('floor_6.gif');
		return false;
	});
	// 6th floor
	$('#floor_7').click( function() 
	{
		show_section($('div#seven'), $(this), $('#tier-7'));
		change_hdr('floor_7.gif');
		return false;
	});

	//search by unit

	// 1 br
	$('#nav-one').click( function() 
	{
		show_section($('div#one-br'), $(this));
		change_hdr('one-br.gif');
		return false;
	}); 
	// 1 br den
	$('#nav-one-den').click( function() 
	{
		show_section($('div#one-br-den'), $(this));
		change_hdr('one-br-den.gif');
		return false;
	}); 
	// 2 br
	$('#nav-two').click( function() 
	{
		show_section($('div#two-br'), $(this));
		change_hdr('two-br.gif');
		return false;
	});
	// 2 br den
	$('#nav-two-den').click( function() 
	{
		show_section($('div#two-br-den'), $(this));
		change_hdr('two-br-den.gif');
		return false;
	});
	// 3 br
	$('#nav-three').click( function() 
	{
		show_section($('div#three-br'), $(this));
		change_hdr('three-br.gif');
		return false;
	});
	

	
//make background images disappear on hover

	$('#nav>ul>li').bind('overState',function()
	{	
		var li = $(this);
		var li2 = li.next('li');
		li.addClass('on');
		li2.find('a').css({'background' : 'none'});
	}
		
	).bind('outState',function()
		{
			$(this).removeClass('on').next().find('a').css({'background' : 'url(/images/nav_divider.gif) bottom left no-repeat'});		
		}
	).hover(function()
		{
			$(this).trigger('overState');
		},
		function()
		{
			if(!$(this).is('.active'))
			{
				$(this).trigger('outState');
			}
		}		
	);
	
	//TOP NAV
	var a = document.URL.split("//"); // split at protocol
	a = (a[1] ? a[1] : a[0]).split("/");
	subd = a[1];
	// use last element of a; split at /
	// host is a[0]; path is a[1..(n-1)]; a[n] is page
	
	//hover states for nav	
	
	if (subd !="") 
	{
		$('#nav ul li.'+subd).trigger('overState').addClass('active');
	}
	
	//lightbox
	$('#gallery a').lightBox();
	
	
});

// END DOC READY
	



