// Image cycling
$(document).ready(function() {
    var cycle_container = $('#feature_cycle').cycle({
		fx: 'fade', 				// choose your transition type, ex: fade, scrollUp, shuffle, etc...
		manualTrump: true,
		pauseOnPagerHover: 1,
		before: custom_transition,
		timeout: 7000,				// Time between transitions
		pause:	1,
		pauseOnPagerHover: 1

	});
	
	$('.thumb_item').click(function(){
		var thumb_click = $(this);
		cycle_container.cycle(thumb_click.index());
		cycle_container.cycle('pause');
		
		move_pointer_arrow(thumb_click.index());	// Move the arrow
		focus_thumb(thumb_click);					// Set thumbnail focus state
		update_feature_text(thumb_click);			// Update the full view text
		
		return false;
	});
	
	$('#beta_link').click(function(){
		$(document).scrollTo('900',500);
	});
	
	$('.register_button').click(function(){
		$('.register_button').fadeTo("fast",0.3);
		$('.register_form').show('blind', function(){});
	});
});

function move_pointer_arrow(img_index){
	var arrow = $('#arrow_pointer');
	var margin_left_val = 0;
	switch(img_index){
		case 0: margin_left_val = "85px";break;
		case 1: margin_left_val = "276px";break;
		case 2: margin_left_val = "476px";break;
		case 3: margin_left_val = "676px";break;
	}
	arrow.animate({'margin-left':margin_left_val},500,function(){});
}

function update_feature_text(thumb_item){
	var full_description = thumb_item.children('span.fullview_description').html();
	$('.feature_label').html(full_description);
}

function focus_thumb(thumb_click){
	thumb_click.siblings('li').removeClass('focus_shot');
	thumb_click.addClass('focus_shot');	
}

function custom_transition(currSlideElement, nextSlideElement, options, forwardFlag){
	// The arg currSlideElement == <img/> that is the current slide item
	var img_number = $(nextSlideElement).index(); // Low level JS element, not jQuery obj
	move_pointer_arrow(img_number);
	
	// Use the img's index, to get the corresponding thumbnail element
	var thumb_item = $($('.thumb_item').get(img_number));
	update_feature_text(thumb_item);
	focus_thumb(thumb_item);
}
