function carouselCallback(carousel)
{
	if ( carousel.size() < 5 )
	{
		$(".jcarousel-skin-tango .jcarousel-prev").css('visibility', 'hidden');
		$(".jcarousel-skin-tango .jcarousel-next").css('visibility', 'hidden');
	}
	
	//$('.jcarousel-control a').click(
//		function() 
//		{
//			$('.jcarousel-control a').each(
//				function()
//				{
//					$(this).css({'background': '#49555d', 'color': '#49555d'});
//				}
//			);
//			
//			carousel.scroll($.jcarousel.intval($(this).text()));
//			
//			$(this).css({'background': '#a6ce05', 'color': '#a6ce05'});
//		
//			return false;
//		}
//	);
}

function miniCarouselCallback(carousel)
{
	if ( carousel.size() < 11 )
	{
		$(".jcarousel-skin-tango-mini .jcarousel-prev").css('visibility', 'hidden');
		$(".jcarousel-skin-tango-mini .jcarousel-next").css('visibility', 'hidden');
	}
}


var g_prev_flag = false;
var g_next_flag = false;

function prevCallback(instance, control, flag)
{
	g_prev_flag = flag;
}

function nextCallback(instance, control, flag)
{
	g_next_flag = flag;
}


$(document).ready(
	function() 
	{
		var img_path = '';
		
		$(".pw").fancybox({
			autoScale	: false,			  
			onComplete  : function() 
			{
				img_path = '/media/project_img/';
				
				$("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).jcarousel({scroll: 1, initCallback: miniCarouselCallback });
				
				var file_name = $("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2) + " li:first a").attr('href');
				
				$('#full-image-' + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).attr('src', img_path + file_name);
			}
		});
		
		$(".ow").fancybox({
			autoScale	: false,			  
			onComplete  : function() 
			{
				img_path = '/media/fabric_img_home/';  //fabric_home
				
				$("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).jcarousel({scroll: 1, initCallback: miniCarouselCallback });
				
				var file_name = $("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2) + " li:first a").attr('href');
				
				$('#full-image-' + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).attr('src', img_path + file_name);
				
			}
		});
		
		$(".ohw").fancybox({
			autoScale	: false,			  
			onComplete  : function() 
			{
				img_path = '/media/fabric_img/';  //fabric_img_home
				
				$("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).jcarousel({scroll: 1, initCallback: miniCarouselCallback });
				
				var file_name = $("#jcarousel-mini-" + $(this).attr('href').substr($(this).attr('href').length - 2, 2) + " li:first a").attr('href');
				
				$('#full-image-' + $(this).attr('href').substr($(this).attr('href').length - 2, 2)).attr('src', img_path + file_name);
				
			}
		});
	
		$("#jcarousel").jcarousel({scroll: 1, initCallback: carouselCallback, buttonPrevCallback: prevCallback, buttonNextCallback: nextCallback });
		
		$('.jcarousel-prev').click(
			function()
			{
				if ( g_prev_flag ) 
				{
					var flag = false;
					
					$('.jcarousel-control a').each(
						function()
						{
							if ( !flag )
							{
								if ( $(this).css('background-color') == "rgb(166, 206, 5)" )
								{
									$(this).css({'background': '#49555d', 'color': '#49555d'});
									$(this).prev().css({'background': '#a6ce05', 'color': '#a6ce05'});
									flag = true;
								} 
							}
						}
					)
				}
			}
		);
		
		$('.jcarousel-next').click(
			function()
			{		
				if ( g_next_flag ) 
				{
					var flag = false;
					
					$('.jcarousel-control a').each(
						function()
						{
							if ( !flag )
							{
								if ( $(this).css('background-color') == "rgb(166, 206, 5)" )
								{
									$(this).css({'background': '#49555d', 'color': '#49555d'});
									$(this).next().css({'background': '#a6ce05', 'color': '#a6ce05'});
									flag = true;
								}
							}
						}
					)
				}
			}
		);
		
		$('.jcarousel-block-mini a').click(
			function()
			{
				$('#full-image-' + $(this).attr('id')).attr('src', img_path + $(this).attr('href'));
				
				return false;
			}
		);
		
		$('.jcarousel-control a').each(
			function() 
			{
				if ( $(this).text() == "1" )
				{
					$(this).css({'background': '#a6ce05', 'color': '#a6ce05'});
				}
			}
		);

		$('.jcarousel-block.captionfull').hover(
			function()
			{
				$(".cover", this).stop().animate({top: '260px'},{queue: false, duration: 160});
			}, 
			function() 
			{
				$(".cover", this).stop().animate({top: '300px'},{queue: false, duration: 160});
			}
		);
		
	    $('.gallery-block-item a').fancybox(
			{
				'titlePosition': 'over', 
				'transitionIn': 'elastic', 
				'transitionOut': 'elastic', 
				'easingIn': 'easeOutBack', 
				'easingOut': 'easeInBack'
			}
		);
		
		$(".fancy-image").fancybox();
		
		$("#jcarousel").css('visibility', 'visible');
	}
);


