jQuery(document).ready(function(){
	
	/**
	 * Detail tabs
	 */
	
	$('div.section_tab').bind('click', function () {
		
		/* Settings */
		var offset = $('div.section_tab').index(this);
		
		/* Remove classes */
		$('div.section_tab').removeClass('selected');
		$('div.section').removeClass('selected');
		
		/* Set new tab to be active */
		$('div.section_tab').eq(offset).addClass('selected');
		$('div.section').eq(offset).addClass('selected');
	});
	
	/* Automatic select first tab */
	$('div.section_tab').eq(0).trigger('click');
	
	/**
	 * Accessoire tab
	 */
	
	$('div.toggler span').bind('click', function () {
		
		/* Change own class */
		$(this).toggleClass('active');
		
		/* Class name */
		var clss = $(this).parent().attr('id');
		
		/* Toggle */
		$('tr.' + clss).toggle();
	});
	
	/**
	 * Images
	 */
	
	$('div.thumb a').bind('click', function () {
		
		/* Settings */
		
		/* Preview image */
		var preview = $('img.preview');
		
		/* Fade out */
		$('<img />').attr({
			'src': $(this).attr('href'),
			'alt': $('img', this).attr('alt'),
			'title': $('img', this).attr('title')
		}).addClass('preview').css({'display': 'none'}).appendTo('.preview div.image');
		
		/* Fade out */
		$(preview).fadeOut(600);
		$('img.preview').fadeIn(600);
		
		/* Delete */
		$(preview).remove();
		
		/* Stop link */
		return false;
	});
	
	/**
	 * Fancy box
	 */	
	
	$("a.image_group").fancybox(); 
	
	/* Overlay */
	$("a.overlay").fancybox({
		'frameWidth': 700,
		'frameHeight': 280,
		'hideOnContentClick': false
	});
	
	/* Trigger function for overlay */
	$('.accessoires tbody td').not('td.select').bind('click', function () {
		
		/* Trigger the overlay link */
		$(this).parent().find('td.text a.overlay').click();
	});
	
	/**
	 * Realtime price checker
	 */
	
	/* Get required values */
	var product = $('input#product').val();
	var vat = $('input#vat').val();
	
	/* Realtime price check */
	$.post('request/prices/realtime.php', {id: product}, function () {
		
		/* Load the new price */
		$.post('request/prices/detail.php', {id: product, vat: vat}, function (data) {
			
			/* Replace the loader */
			$('td.info div.loader').replaceWith(data);
		});
	});
})
