$(document).ready(function () {
	
	// Initilize compare
	$('#compare #compare_type div:first').click();
	
	// Initilize set apart
	init_set_apart();
	
});

function compare_type(el){
						
	//reset
	$(el).siblings().removeClass('selected');
	$('#compare table tr.data').hide();
	
	// select
	$(el).addClass('selected');
	$('#compare table tr.' + $(el).text()).show();
	
}

// Set the number of sections
var set_apart_sections = 5;
var set_apart_current_position;

function init_set_apart(){
	
	// Setup onclick handler
	$('#set_apart #thumbs .thumb').click(
	function(){
		set_apart_current_position = $(this).attr('target');
		jump_to(set_apart_current_position);
	});
	
	// Setup hover
	$('#set_apart #thumbs .thumb').hover(
		function(){$(this).find('img').css('border', '1px solid black');},
		function(){$(this).find('img').css('border', '1px solid #a1a1a1');}
	);
	
	$('#set_apart .button_previous').hover(
		function(){$(this).find('img').attr('src',path + 'images/design/set_apart/previous_active.gif');},
		function(){$(this).find('img').attr('src',path + 'images/design/set_apart/previous_inactive.gif');}
	).click(previous);
	
	$('#set_apart .button_next').hover(
		function(){$(this).find('img').attr('src',path + 'images/design/set_apart/next_active.gif');},
		function(){$(this).find('img').attr('src',path + 'images/design/set_apart/next_inactive.gif');}
	).click(next);
	
	// Initilize
	set_apart_current_position = 0;
	jump_to(set_apart_current_position);
}

// Jump to passed section
function jump_to(target){
	
	el_section = $("#set_apart .section[target='" + target + "']");
	el_thumb = $("#set_apart #thumbs .thumb[target='" + target + "']")
	el_link = el_thumb.find('div');	
	
	$('#set_apart #container').html(el_section.html());
	
	// Reset thumb styles
	$('#set_apart #thumbs .thumb').css('backgroundImage', 'none');
	$('#set_apart #thumbs .thumb').find('div').css('color', 'blue');
	$('#set_apart #thumbs .thumb').find('div').css('textDecoration', 'underline');
	
	// Set selected thumb styles
	el_thumb.css('backgroundImage', 'url(' + path + 'images/design/set_apart/thumb_highlight.gif)');
	el_link.css('color', 'black');
	el_link.css('textDecoration', 'none');
	
}

// Iterate forward
function next(){
	if(set_apart_current_position == set_apart_sections - 1) set_apart_current_position = 0;
	else set_apart_current_position++;
	jump_to(set_apart_current_position);
}

// Interate backward
function previous(){
	if(set_apart_current_position == 0) set_apart_current_position = set_apart_sections - 1;
	else set_apart_current_position--;
	jump_to(set_apart_current_position);
}

function next_quote(){
	step_size = 308;
	
	// Get the current position
	str_current_position = $('#quote_content').css('left');
	if(str_current_position == 'auto'){
		current_position = 0;
	}else{
		number_end = str_current_position.indexOf('px');
		current_position = parseInt(str_current_position.substr(0, number_end));
	}
	
	// Get content width
	str_width = $('#quote_content').css('width');
	number_end = str_width.indexOf('px');
	width = parseInt(str_width.substr(0, number_end));
	
	// Determine new position
	new_position = current_position - step_size;
	
	// Check to see if we need to go back
	if(Math.abs(new_position) + step_size > width) new_position = 0;
	
	// Animate to new position
	$('#quote_content').animate({left:new_position + 'px'}, {duration:500, queue:true, easing:'easeOutQuad'});
	
}