$(document).ready(function() {
						   
/*	var hash = window.location.hash.substr(1);
	var href = $('#interiorsleft a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href)){
			var toLoad = hash+'.html #interiorsright';
			$('#interiorsright').load(toLoad)
		}											
	});

	$('#interiorsleft a').click(function(){
		var toLoad = $(this).attr('href')+' #interiorsright';
		
		$('#interiorsright').fadeOut('slow',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('normal');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			$('#interiorsright').load(toLoad,'',showNewContent())
		}
		function showNewContent() {
			$('#interiorsright').fadeIn('slow');
		}
		function hideLoader() {
			$('#load').fadeOut('normal');
		}
		return false;
		
	});*/


	$('map#_Phase area').click(function(e){
		
		node = $(this).attr('id');
		
		var defaultLevel = 'main';

		var unitNumber 	= $(this).attr('href').substr(1);
		var unitPhase 	= $('#'+node+' input.unitPhase').attr('value');
		var unitType 	= $('#'+node+' input.unitType').attr('value');
		var unitSize 	= $('#'+node+' input.unitSize').attr('value');
		
		if(unitNumber == 11 || unitNumber == 16 || unitNumber == 47 || unitNumber == 52){
			$('.levels .level1').hide();
			$('.levels .level3').hide();
		}
		
		$('#floorplanUnit h5').html('Townhome #'+unitNumber+' - '+unitType+' Plan');
		$('#floorplanUnit h6').html(unitSize+' sq. ft.');
		bgSwap(unitNumber,unitType,defaultLevel);
		$('#floorplanUnit a.btn-pdf').attr('href',siteURL+'/images/floorplans/pdfs/insert-'+unitType+'-'+unitPhase+'.pdf');
		
		$('#floorplanUnit .levels input.unitNumber').attr('value',unitNumber);
		$('#floorplanUnit .levels input.unitType').attr('value',unitType);
		
		targetSwap('floorplanMap','floorplanUnit');
		e.preventDefault();
	});

	$('div#floorplanUnit .levels .level').click(function(e){
		$(this).parent().find('.active').removeClass('active');
		var unitNumber = $(this).parent().find('input.unitNumber').attr('value');
		var unitType = $(this).parent().find('input.unitType').attr('value');

		targetLevel = $(this).attr('href').substr(1);
		//console.log(targetLevel);
		bgSwap(unitNumber,unitType,targetLevel);
		$(this).addClass('active');
		e.preventDefault();
	});

	$('div#floorplanUnit a.btn-backToPlan').click(function(e){
		$('.levels .level').show();
		$('.levels .active').removeClass('active');
		$('.levels .level2').addClass('active');
		targetSwap('floorplanUnit','floorplanMap');
		e.preventDefault();
	});
	
	$('#light a.btn-close').click(function(e){
		targetSwap('floorplanUnit','floorplanMap');
		e.preventDefault();
	});
	
	function targetSwap(toHide, toShow){
		$('#'+toHide).hide();
		$('#'+toShow).show();
	}
	
	function bgSwap(number,type,level){
		$('#floorplanBackground').css('background','url('+siteURL+'/images/floorplans/plan_'+number+'_'+type+'_'+level+'.gif) 0 0 no-repeat')
	}


});











