var busy = false;

$(function(){
	$('#rotator-up').click(function(e) {
		scrollPreview('up');
		e.stopPropagation();
	});

	$('#rotator-down').click(function(e) {
		scrollPreview('down');
		e.stopPropagation();
	});

	
	$('#allPhotos').click(function(){
		$('#posters a[rel="lightbox-Images"]').lightbox({start:true,events:false});
		return false;
	});	

	$('#bookmarks a').click(function() {
		$('#bookmarks li').removeClass('active');
		$(this).parent().addClass('active');

		var type = $(this).attr('rel');
		$('#description').hide();
		$('#video').hide();
		$('#comments').hide();
		$('#gift').hide();

		if (type == 'description')
			$('#gift').show();

		$('#' + type ).show();
		return false;
	});
	
	if (!$.browser.msie && !$.browser.opera) {
		$('#brand-info').corner("5px");
		$('#posters').corner("5px");
	}

	scrollPreview('up');
});
		
function scrollPreview(direction) {
	if (!busy) {
		busy = true;

		var elem = $('#images-preview');
		if (elem.size()) {
			var scroll = elem.scrollTop();
			var itemHeight = $('a:eq(0)', elem).outerHeight();
			var maxScroll = elem[0].scrollHeight - elem.height();
					
			if (direction == "up") {
				if (scroll != 0)
					scroll = scroll - itemHeight;
			} else {
				scroll = scroll + itemHeight;
			}
					
			if (scroll > 0) {
				$('#rotator-up').removeClass('rotator-up-disabled').addClass('rotator-up');
			} else {
				$('#rotator-up').removeClass('rotator-up').addClass('rotator-up-disabled');
			}
					
			if (maxScroll >= scroll) {
				$('#rotator-down').removeClass('rotator-down-disabled').addClass('rotator-down');
			} else {
				$('#rotator-down').removeClass('rotator-down').addClass('rotator-down-disabled');
			}
					
			elem.animate({scrollTop: scroll}, function() {
				busy = false;
			});
		}
	}
}
