/******************************************************************************************************************/
//  FUNCTIONS
/******************************************************************************************************************/

function handleCarousel(){
	$('.carousel .prev').css({ opacity: 0.2, cursor: 'default' });
	
	num = $('.carousel LI').size();
	myid = $('.carousel').attr('id');
	
	current = 0;
	
	if (myid == 'prod') {
		// products carousel init
		mystep = $('.carousel LI').width() + 32;
		myw = mystep * num;
		myview = 5;
	}
	else {
		// gallery carousel init
		mystep = $('.carousel LI').width() + 52;
		myw = mystep * num;		
		myview = 3;		
	}
	
	$('.carousel UL').width(myw);
	max = num - myview;
	
	// next click
	$('.carousel .next').click(function(){
		current++;
		
		if (current <= max) {
			$('.carousel .prev').css({ opacity: 1, cursor: 'pointer' });
						
			m = '-'+ (mystep * current) +'px';
			$('.carousel UL').animate({ marginLeft: m }, 500);
		}
		else {
			$('.carousel .next').css({ opacity: 0.2, cursor: 'default' });		
			current = max;
		}
	});
	
	// prev click
	$('.carousel .prev').click(function(){
		current--;
		
		if (current >= 0) {
			$('.carousel .next').css({ opacity: 1, cursor: 'pointer' });
			
			m = '-'+ (mystep * current) +'px';
			$('.carousel UL').animate({ marginLeft: m }, 500);
		}
		else {
			$('.carousel .prev').css({ opacity: 0.2, cursor: 'default' });		
			current = 0;
		}
	});
}


/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	// submenu link hack
	$('#menu LI A').click(function(){ if ($(this).parent('LI').find('UL').size()) return false;	});
	
	// handle carousel
	handleCarousel();
	
	// fancy box
	$('.fancybox').fancybox({
		'zoomOpacity'			: true,
		'zoomSpeedIn'			: 300,
		'zoomSpeedOut'			: 300,
		'frameWidth'			: 750,
		'frameHeight'			: 500
	});	
});