$(function(){
	//$('#javascript_error').hide(); 
	//$('.container_12').pause(1000).fadeIn('slow');
	$('#maps_link').click(function(){
		$(this).fadeOut('fast');
		$.get('maps.ajax.html', function(data){
			$('#maps_placeholder').html(data);
		});
		return false;
		
	});

	
	$('.outside-pics').colorbox();
	//this function simply calls the initSpaces setup function for each "room"
    initSpacesLoop();

	//hide all the room divs
	$('.room').hide();
	$('#roompics_bed4, #space_bed4').show();
	$('#roompics_bed4').cycle({
		delay: 2000,
		speed: 500
	});
	
	//initialize the navigation full page scroll
	//just requires a link to an anchor, and a named anchor where the scroll goes to
	$('ul#nav li, .scroll').localScroll({
							hash: true,
							reset: true
	});
	
	//hide all the exterior images,
	$('.ext a img').hide();
	//but then fade in first one
	$('.ext a:first-child img').fadeIn();
	
	
	//this lets the exterior images swap when the appropriate links are clicked.
	// <a rel="#example" href="#"> will fade in <img id="example" />
	$('.dots a').click(function(){
		//read the rel property
		var which = $(this).attr('rel');
		//hide all the images
		$('.ext img').hide();
		//show the one clicked
		$(which).fadeIn();
		//don't send the # link to the browser
		return false;
	});
	
});

//this code gets run for each of the "spaces", i.e. bedrooms kitchens and common
function initSpace(a)
{			

	$('.roompics').hide();
	
	//this handles the image roll over
	$('#' + a).hover(function(){
		if ($(this).attr('rel') != 'on'){
			var src = $(this).attr('src');
			var src_on = src.replace('.gif', '_f2.gif');
			$(this).attr('rel', 'on');
			//alert('hover on ' + src  + ' '+ src_on);
			$(this).attr('src', src_on);
		}
	},function(){
		if ($(this).attr('rel') != 'off'){
			var src_on = $(this).attr('src');
			var src = src_on.replace('_f2.gif','.gif');
			$(this).attr('rel', 'off');
			//alert('hover off ' + src  + ' '+ src_on);
			$(this).attr('src', src);
		}
	}).click(function(){
		//alert($(this).attr('id'));
		$('#roompics_' + a).cycle({
			speed: 500
		});
		$('.room, .roompics').hide();
		$('#space_' + a).fadeIn();
		$('#roompics_' + a).fadeIn();
		
		//var img_html = "";
		$('img', '#roompics_' + a).each(function(i){
			//$(this).attr('id', ''
			img_html = img_html + '<a href="javascript:;">[Image ' + (i+1) + ']</a>';
		});
		$('#img-nav').html('<p>' + img_html + '</p>');
	

	});			
}


//this calls the initSpaces function for each room in the array
function initSpacesLoop()
{
	var spaces = new Array('bed1',
	 			 	'bed2',
				 	'bed3',
					'bed4',
					'bed5',
					'bed6',
					'bed7',
					'bed8',
					'bed9',
					'bed10',
					'bed11',
					'bed12',
					'kitchen1',
					'kitchen2',
					'cmnbasement',
					'cmn1',
					'cmn2',
					'cmnattic');

	
	
	
  for(var i=0;i<spaces.length;i++)
  {
   initSpace(spaces[i]);
  }
  
}
