$(document).ready(function(){
	
	$(function() { // executed when $(document).ready()
  $("#jpId").jPlayer( {
    ready: function () {
      this.element.jPlayer("setFile", "http://www.sheltoncondos.com/js/music/hhpiano.mp3").jPlayer("play"); // Auto-Plays the file
    },
    volume: 0,
    swfPath: "http://www.sheltoncondos.com/js/music"
  });
$("#jpId").jPlayer("onSoundComplete", function() {
  this.element.jPlayer("play"); // Auto-Repeat
});
  
});

$('body').bind('cycle', function(event, option){cycle_change(option);});

function cycle_change(option)
{
    if (typeof cycle_change.status == 'undefined')
    {
        cycle_change.status = 'resume';
    }
    // Autoscroll should be set after the images is showed, and only once
    if (cycle_change.status != option)
    {
        var time = option == 'resume' ? 8000 : 800000;
        $('#background_images').cycle({
            speed: 1000,
            timeout: time
        });
        cycle_change.status = option;
    }    
}


$(function()
{
    //Set the default directory to find the images needed
    //by the plugin (closebtn.png, blank.gif, loading images ....)
    $.fn.fancyzoom.defaultsOptions.imgDir='js/fancyzoom/resources/';
    // Select all links in object with gallery ID using the defaults options
    $('#residences-amenities a').fancyzoom(); 
});
	
// Zoomable Hovers
$('.zoomable').live('hover', function() {
	$(this).toggleClass('hover');
});


/** Preload Images */
if (document.images) {
	var images = new Array(
		"/images/content-bg-pic.png"
	);
	
	var imageObjs = new Array();
	for (var i in images) {
		imageObjs[i] = new Image();
		imageObjs[i].src = images[i];
	}
}

/** Navigation - Level 1 */	
$('#nav > li > a').click(function()	{
    
    cycle_change('resume');
    // Start the slideshow when clicked on the main tab

    var li = $(this).parent();	
	$('#content .inner_layer').fadeOut('normal', function() { // fade out content pane if necessary, then do everything else afterwards
		// Handle nav menu
		if (li.hasClass('active')) { // clicking already active link; display submenu if hidden
			li.find('ul').show();
		} else { // clicking non-active link; switch to new submenu
			li.siblings().find('ul').hide();
			$('#nav').animate({width: '180px'}, 400);
			li.find('ul').animate({width: 'toggle'}, 400);
			
			li.siblings().removeClass('active');
			li.addClass('active');
		}
		
		// Handle content area - return items to their original state
		$('#content').hide();
		$(this).show();
		$(this).children().removeClass('active').hide();
	});
	
	$.history.load($(this).attr('href'));
	return false;
});


/** Navigation - Level 2 */
$('#nav ul a').click(function() {    
	var allContainerULs = $('#nav ul');
	var thisContainerUL = $(this).parents('#nav ul');
	var topLevelLI = $(this).parents('#nav > li');
	
	// if this event is being triggered because the page is loading from a deep link, the menu is still hidden and needs to be revealed
	$('#nav').css('width', '180px');
	allContainerULs.hide();
	thisContainerUL.show();
	
	// also need to set the top-level menu link to active
	topLevelLI.siblings().removeClass('active');
	topLevelLI.addClass('active');
	
	$('#content').fadeIn();
	
	var selectedID = $(this).attr('href');
	if (selectedID) {
		var selectedDiv = $(selectedID); // select the target div
		
		if (selectedDiv.hasClass('active')) {
            $('body').trigger('navigation_level2', [selectedID]);
			return false;
		}
		
		$(this).parent().siblings().children('a').removeClass('active');
		$(this).addClass('active');
		
		$('#content .inner_layer').fadeOut('normal', function() {
			$(this).children().removeClass('active').hide();
			selectedDiv.addClass('active').show();
			
			$(this).fadeIn();
            $('body').trigger('navigation_level2', [selectedID]);
		});
	}
	
	$.history.load($(this).attr('href'));
	return false;
});

$.history.init(pageLoad);

function pageLoad(hash) {
	$('a[href="'+hash+'"]').click();
}
	
	
});