//Define functions outside of jQuery
function top_slide() {
	jQuery('#content_slider').animate( {
		'left' : '-'+(top_spacing * top_counter) * top_items_per_click+'px'
	}, 750);
};	
function top_content_loop(top_index){
		if(top_index < $('#content_slide_nav span').size()){
			$('#content_slide_nav span').removeClass('current_pane');
			$('#content_slide_nav span:eq('+top_index+')').addClass('current_pane');
			top_counter = top_index;
			top_slide();
			top_index = top_index + 1;
			t = setTimeout('top_content_loop('+top_index+')', 5000);
			//alert('Index:'+top_index+' Slide:'+$('#content_slide_nav span').size());
		}
		else{
			
			top_counter = $('#content_slide_nav span').size();
			$('#content_slider').animate( {
				'left' : '-'+(top_spacing * top_counter) * top_items_per_click+'px'
			}, 750, 'swing',function(){
				$('#content_slide_nav span').removeClass('current_pane');
				$('#content_slide_nav span:first-child').addClass('current_pane');
				$('#content_slider').css('left','0px');
				top_index = 0;			
				t = setTimeout('top_content_loop('+top_index+')', 0);
			});
			//alert((top_spacing * top_counter)*top_items_per_click);
			
		}
}

jQuery(document).ready(function($){

// show/hide faq

$('#faq div').hide();

$('#faq h3').addClass('closed').click(function(){
	$('#faq div').not($(this).siblings()).hide();
	$('#faq h3').not($(this)).attr('class','closed');
	$(this).toggleClass('open').toggleClass('closed').siblings().toggle();
});

//Content slider - Top
//Initialized Values
	// Horizontal Spacing between start of one listing and the start of the next
	top_spacing = 775;
	//Initialize Slider Counter
	top_counter = 0;

	//Amt of Listings that Slide Per Click
	top_items_per_click = 1;

	// Under the Hood:
	// Slider Width
	// Formula: Listing Width * Listings On Screen + Listing Margins:
	top_width = 775;
		
	// Calculate total pixel length of all listings
	// Formula: Item Count * Spacing
	top_item_count = $('#content_slider div').size();
	top_list_length = top_item_count * top_spacing;

	// Pixel Length Offscreen
	// Formula: List Length - Width
	top_remainder = top_list_length - top_width;

	// Amount of slides or 'clicks' represented by the remainder
	// Formula: (Pixel Length Offscreen / Spacing) / Amt of Listings
	// Slide Per Click
	top_off_screen = (top_remainder / top_spacing) / top_items_per_click;
	
	//Amount of forward slides possible.
	top_fwd_limit = 0 - top_off_screen;


//Slider Controls
	$('#content_slide_nav span').click(function(){
		$('#content_slide_nav span').removeClass('current_pane');
		$(this).addClass('current_pane');
		top_counter = $(this).index();
		top_slide();
		clearTimeout(t);
	});
//Onload

//Set Slider width
$('#content_slider').width(top_list_length+'px');

//Copy first div to end to use in simulated loop
$('#content_slider div:first-child').clone().appendTo('#content_slider');
$('#content_slider').width($('#content_slider div').size()*top_spacing);
//start Top Content Loop
top_content_loop(0);

});


