var corners = '<span class="corner tl"></span><span class="corner tr"></span><span class="corner bl"></span><span class="corner br"></span>';
var featureTextBox = '<div id="featureTextBox"></div>';
var descriptionTextBox = '<div id="descriptionTextBox"></div>';



$(document).ready(function()
{
	$('.lozenge').append(corners);
	$('.hidden').hide();
	
	// Slideshow...
	$('#slides').before('<ul id=slideshowNav></ul>').cycle({
		fx:      'fade',
		pager:   '#slideshowNav',
		timeout:  6000,
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="#">'+(idx+1)+'</a></li>';
		}
	});
	
	// Nav hover...
	$('.menu ul li').hover(function(){$(this).find('ul').show()},function(){$(this).find('ul').hide()});
	
	// Run the default switch...
	set_switch('.propertyInfo');
	
	$('.show').click(function(ev){
		ev.preventDefault();
		$('.show').each(function(){$(this).parent('li').removeClass('selected')});
		$(this).parent('li').addClass('selected');	
		set_switch('.propertyInfo');
	});
										  
	$('.propertyListing .features').each(function(){
			$(this).hover(
			function() {
				 var featureText =  $(this).find('.allfeatures').html();
				 $('#featureTextBox').html(featureText);
				 $('#featureTextBox').show();
				
				 
			},
			function() {
				$('#featureTextBox').hide();			
			});
		});
	
	$('body').append(featureTextBox);
	
	$('#featureTextBox').hide();
	
	$('.propertyListing .description').each(function(){
			$(this).hover(
			function() {
				 var descriptionText =  $(this).find('.descriptionText').html();
				 $('#descriptionTextBox').html(descriptionText);
				 $('#descriptionTextBox').show();
				
				 
			},
			function() {
				$('#descriptionTextBox').hide();			
			});
		});
	
	$('body').append(descriptionTextBox);
	
	$('#descriptionTextBox').hide();
	
	$(document).bind('mousemove',function(e){
		$('#featureTextBox').css({left: (e.pageX)+'px', top: (e.pageY)+'px'});	
		$('#descriptionTextBox').css({left: (e.pageX)+'px', top: (e.pageY)+'px'});	
	});
	
});

/* SET SWITCH
--------------------------------------
- hide the .hiddens
- get the href of the clicked on link
- get an element by ID which matches that HREF
- show that element

*/

function set_switch(container)
{
	$(container+' .hidden').hide();
	var showme = $(container+' li.selected a').attr('href');
	if(showme) $(showme).show();
}
