$(document).ready(function() {

	// SHADOWBOX
	Shadowbox.init({players: ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']});
	
	$('.pbi-thumb-item img').click(function () {

		var id = $(this).attr('id');

		$(this).parents('.page-block-images').find('.pbi-large').css('display', 'none');

		id = id.replace ('thumb', 'large');

		$('#' + id).css('display', 'block');

	});
	
	// PRODUCT TABS
	$('#spec_1').css('backgroundPosition', '0px -29px');
	$('a.tab_spec').click(function () {

		var id = $(this).attr('id');

		$('.info_spec').css('display', 'none');
		$('#info_' + id).css('display', 'block');
		
		$('.tab_spec').css('backgroundPosition', '0px 0px');
		$('#' + id).css('backgroundPosition', '0px -29px');

	});
	
	// LOADER IMAGE
	var loader = '';
	var items = $('#loader_img ul#images li');
	
	$("ul#blocks li").click(function(){
		
		if ($(this).attr('class') != 'active') {
		
			var title = $(this).attr('id').replace('block_', '');
 			
			active_img = $('#loader_img ul#images li.active');
			active_block = $('ul#blocks li.active');
				
			slide_img = $('#loader_img ul#images li#' + title);
							
			// Remove active
			active_img.removeClass('active');
			active_block.removeClass('active');
			
			slide_img.addClass('active');
			$(this).addClass('active');
	
			$(active_img).fadeOut(1500);
			$(slide_img).fadeIn (1500);
			
			clearInterval(loader);
			
			loader = setInterval (function () {
				
				// Remove active
				active_img = $('#loader_img ul#images li.active');
				active_block = $('ul#blocks li#block_' + $(active_img).attr('id') + '.active');
				
				// Calculate next
				next = items.index(active_img) + 1;
				
				// Check for offset
				if (next == items.length) {
					next = 0;
				}		
								
				// Fetch next
				slide_img = items.get(next);
				slide_block = $('ul#blocks li#block_' + $(slide_img).attr('id'));
				
				// Remove active
				$(active_img).removeClass('active');
				$(active_block).removeClass('active');
				
				$(slide_img).addClass('active');
				$(slide_block).addClass('active');
						
				$(active_img).fadeOut(1500);
				$(slide_img).fadeIn (1500);
							
			}, 7500);
		
		}
					
	});
		
	if (items.length > 1) {
	
		$('#loader_img ul#images li').css ("display", "none");
		$('#loader_img ul#images li.active').css ("display", "block");
		
		loader = setInterval (function () {
			
			// Remove active
			active_img = $('#loader_img ul#images li.active');
			active_block = $('ul#blocks li#block_' + $(active_img).attr('id') + '.active');
			
			// Calculate next
			next = items.index(active_img) + 1;
			
			// Check for offset
			if (next == items.length) {
				next = 0;
				
			}
						
			// Fetch next
			slide_img = items.get(next);
			slide_block = $('ul#blocks li#block_' + $(slide_img).attr('id'));
			
			// Remove active
			$(active_img).removeClass('active');
			$(active_block).removeClass('active');
			
			$(slide_img).addClass('active');
			$(slide_block).addClass('active');
					
			$(active_img).fadeOut(1500);
			$(slide_img).fadeIn (1500);
						
		}, 7500);
	
	}
	
	// INFO BUTTON ON THE RIGHT	
	$('#bg_selector').mouseenter (function () {

		$('img', this).css('display', 'none');
		
		$(this).stop().animate ({'width': '344px'}, 1000, 'easeOutQuad', function () {
			
			$('img', this).css('display', 'block');
		});
		
		$(this).children('#bg_selector_out').css('display', 'block');
		$(this).children('#bg_selector_in').css('display', 'none');

	}). mouseleave (function () {

		$('img', this).css('display', 'none');
		
		$(this).stop().animate ({'width': '48px'}, 1000, 'easeOutQuad', function () {
			$(this).children('#bg_selector_out').css('display', 'none');
			$(this).children('#bg_selector_in').css('display', 'block');
		});

	});
				
	
	// LOADER IMAGE
	var loader_bg = '';
	var items_bg = $('#header ul li');
		
	if (items_bg.length > 1) {
	
		$('#header ul li').css ("display", "none");
		$('#header ul li.active').css ("display", "block");
		
		loader_bg = setInterval (function () {
			
			// Remove active
			active_img_bg = $('#header ul li.active');
			
			// Calculate next
			next_bg = items_bg.index(active_img_bg) + 1;
			
			// Check for offset
			if (next_bg == items_bg.length) {
				next_bg = 0;
				
			}
						
			// Fetch next
			slide_img_bg = items_bg.get(next_bg);
			
			// Remove active
			$(active_img_bg).removeClass('active');
			$(slide_img_bg).addClass('active');
					
			$(active_img_bg).fadeOut(1500);
			$(slide_img_bg).fadeIn (1500);
						
		}, 12500);
	
	}
	
	/*// CAROUSEL
	$(".carousel").jCarouselLite({
		btnNext: ".next",
 		btnPrev: ".prev",
 		auto: 9000,
        speed: 1500,
        visible: 1
 	});*/
		
});
