$(function(){
var halfwidth = $('#conveyor_holder').width()/2;

$('.not_active').hover(
	function(){
		$(this).css("cursor","pointer").removeClass("not_active").addClass("hovered");
	},
	function(){
		$(this).css("cursor","default").removeClass("hovered").addClass("not_active");
	}
)
.click(
	function(){
		var href = ($(this).attr('id') == "contact_us") ? 'contact_us.php' : 'index.php?subject='+$(this).attr('id');
		window.location = href;
	}
);

$('#conveyor').css("left", ($('#main').width() / 2) - halfpreview);
$('#screen_inner img').click(function(){ next_image(first_pic);}).hover(function(){$(this).css('cursor', 'pointer');}, function(){$(this).css('cursor', 'default');});

$('.preview').click(function(){
	var this_src = $(this).attr('src');
	$('#screen_inner img').remove();
	$('#screen_inner').html('<img src="'+ $(this).attr("src").replace("preview_", "") + '" alt="" title="" style="display:none" />');
	$('#screen_inner img')
		.load(function(){$(this).fadeIn(200);})
		.click(function(){ next_image(this_src);})
		.hover(function(){$(this).css('cursor', 'pointer');}, function(){$(this).css('cursor', 'default');});
	$('#conveyor').animate({"left": (halfwidth - $(this).position().left - halfpreview) + 5}, 500);
})
.hover(function(){$(this).css('cursor', 'pointer');}, function(){$(this).css('cursor', 'default');});
});

function next_image(src){
	var next_prev = $('.preview[src="'+src+'"]').parent().next().children().first();
	if(!next_prev.attr('src')){next_prev = $('.preview[src="'+first_pic+'"]');}
	next_prev.click();
}
