function update_navigation_bar(active_panel) {
	var active_class = active_panel.attr('class').split(' ').slice(0);
	$("#navigation>ul>li").removeClass('active');
	$("#navigation>ul>li a."+active_class).parent().addClass('active');
}
$(document).ready(function() {
	// Product Loading
	$("div.image-list>ul>li a").click(function() {
		// Fade out the current product navigation
		if($(this).attr('class').split(' ').slice(-1) == 'active') return false;
		//$("#product-list>ul>li a").removeClass('active');
		$("div.image-list>ul>li").removeClass('active');
		$(this).parent().addClass('active');
		// Load the selected product
		var product = $(this).attr('id');
		var product_title = $(this).attr('title');
		$('#spotlight').html('<div class="loading '+product+'">Loading<h2>'+product_title+'</h2></div>');
		$('#spotlight').load("/2009/wp-content/themes/apartment-ideas/script/load_products.php?product="+product, function(){$("ul.samples li a").fancybox();});
		// Scoll to the first panel
		var first_panel = $('#content>ul> li:first');
		$('div#content').stop().scrollTo(first_panel, 700);
		return false;
	});
	// Home link
	$("#home-link a").live("click", function(){
		$("#product-list>ul>li a").removeClass('active');
		$('#spotlight').html('<div class="loading home"><h2>Home</h2>Loading</div>');
		$('#spotlight').load("/2009/wp-content/themes/apartment-ideas/script/load_products.php?product=home", function(){$("ul.samples li a").fancybox();});
		// Scoll to the first panel
		var first_panel = $('#content>ul> li:first');
		$('div#content').stop().scrollTo(first_panel, 700);
		return false;		
	});
	// Quote Form
	$("a.request-a-quote").live("click", function(){
		$(this).fancybox({																																											 		'type': 'iframe',
		'height'		:	'100%', 
		'width'		:	700, 
		'scrolling'		:	'yes', 
		'overlayShow'	:	true
	});
		return false;
	});
	
	// Sample images
	/*$("ul.samples li a").live("click",function(){
		$(this).fancybox({ 
			'zoomSpeedIn': 300, 	
			'zoomSpeedOut': 300,
			'frameWidth' : 915,
			'frameHeight' : 550,
			'hideOnContentClick': true
			});
		return false;
	});
	*/
	// Navigation Bar
	$('#navigation>ul>li a').live("click", function(){
		$("#navigation>ul li").removeClass('active');
		$(this).parent().addClass('active');
		/// Scroll to the target
		var target_panel = $(this).attr('class');
		$("#content>ul li").removeClass('active');
		$("#content>ul li."+target_panel).addClass('active');
		$('div#content').stop().scrollTo( 'li.'+target_panel, 700 );
		return false;
	});


	// Set the product list scroll bar
	$('#product-list').removeClass('default-pane');
	$('#product-list div.scroll-pane').jScrollHorizontalPane({showArrows:true});

	// Panel Scrolling
	// Reset all scrollable panes to (0,0)
	$('div#content').scrollTo( 0 );
	// Reset the screen to (0,0)
	$.scrollTo( 0 );
	$('div#next').live("click", function(){
		// Find the class of the next panel
		var active_panel = $('#content>ul> li.active');
		var next_panel = active_panel.next();
		// If this is the last panel, then scroll over to the first
		if(!next_panel.attr('class')){
			next_panel = $('#content>ul> li:first');
		}
		active_panel.removeClass('active');
		next_panel.addClass('active');
		$('div#content').stop().scrollTo(next_panel, 900);
		update_navigation_bar(next_panel);
		return false;
	});
	$('div#previous').live("click", function(){
		// Find the class of the next panel
		var active_panel = $('#content>ul> li.active');
		var previous_panel = active_panel.prev();
		// If this is the last panel, then scroll over to the first
		if(!previous_panel.attr('class')){
			previous_panel = $('#content>ul> li:last');
		}
		active_panel.removeClass('active');
		previous_panel.addClass('active');
		$('div#content').stop().scrollTo(previous_panel, 900);
		update_navigation_bar(previous_panel);
		return false;
	});
});
