$(window).ready(function(){
	var inlet_width = 0;
	$('.carousel img').each(function(){
		inlet_width += $(this).width()+1;
	});
	$('.carousel .inlet').width(inlet_width).css({
		marginLeft: '0'
	});
	$('.carousel').css({
		overflow: 'hidden',
		width: $(window).width()+'px'
	});	
	$('<div id="prev">&nbsp;</div><div id="forward">&nbsp;</div>').prependTo('.carousel').css({
		zIndex: '10000'
	});	
	$('#prev, #forward').css({
		position: "absolute",
		height: "400px",
		width: "50px",		
		cursor: "pointer",
		zIndex: '10000'
	});
	$('body').css({
		overflow: 'hidden',
		width: $(window).width()+'px'
	})
	if(!jQuery.browser.msie) {
		$('.carousel .inlet').css({
			position: 'relative'
		});		
	}
	$(window).resize(function(){
		$('.carousel').css({
			width: $(window).width()
		});
	});
	$('#forward').css({
		right: "0px",
		backgroundPosition: "center -400px"
	}).click(function(){
		var inlet_left = ($('.carousel .inlet').css('marginLeft')).substring(0, ($('.carousel .inlet').css('marginLeft')).length-2)*1;
		var carousel_width = ($('.carousel').width())*1;
		rest = ($('.carousel .inlet').width()+inlet_left)*1;
		if((rest-(carousel_width/2)) > carousel_width) {
			var scroll = inlet_left-(carousel_width*0.5);

		} else {
			scroll = inlet_left-(rest-carousel_width);
			$(this).css({
				visibility: 'hidden'
			});
		}
		$('.carousel .inlet').animate({
			marginLeft: scroll
		},700,function(){
			$('#prev').css({
				left: 0,
				visibility: 'visible'
			});
			$('#forward').css({
				right: 0
			});
		});
	});
		
	$('#prev').click(function(){
		var inlet_left = ($('.carousel .inlet').css('marginLeft')).substring(0, ($('.carousel .inlet').css('marginLeft')).length-2)*1;
		var carousel_width = ($('.carousel').width())*1;
		var rest = ($('.carousel .inlet').width()+inlet_left)*1

		if((inlet_left)*-1 > carousel_width/2) {
			var scroll = inlet_left+(carousel_width*0.5);
		} else {
			scroll = 0;
			$(this).css({
				visibility: 'hidden'
			});
		}
		$('.carousel .inlet').animate({
			marginLeft: scroll
		},700,function(){
			$('#forward').css({
				right: 0,
				visibility: 'visible'
			});
			$('#prev').css({
				left: 0
			});
		});
		}).css({
		visibility: 'hidden'
	});
		
	if(!jQuery.browser.msie) {
		$('.carousel img').hover(function(){
			$('.carousel').before('<div style="position: absolute; top: 7px; left: '+($(this).offset()).left+'px" id="img_title">&#8968; '+$(this).attr('title')+'</div>');
		},function(){
			$('#img_title').remove();
		});
	}
});
