// promotion custom scripts

$(document).ready(function(){
		
	// Tabs
	$('#info .tabed-info:not(:first)').hide();
	$('#tabs li')
			.click(function(e) 
				{
					$('#info .tabed-info').hide(); 
					$('#tabs li.current').removeClass("current"); 
					$(this).addClass('current');
					var clicked = $(this).find('a:first').attr('href'); 
					$('#info '+clicked).fadeIn('fast'); e.preventDefault();
				})
	.eq(0).addClass('current');
	
	
	// Add to basket
	$('.add_to_basket').live('click',function() {
		$(this).closest('.button50org').addClass('button50grn');
		var num_items = $('#num_items').html();
		var str = $(this).closest('.add_form').serialize();
		$.ajax({
			type: "POST",
			url: "/includes/form-processor.php",
			data: str+'&add_to_basket=1',
			success: function(msg){
				num_items = parseInt(num_items)+1;
				$('#num_items').html(num_items);
				$('#addkitbag').slideDown();
				$('#addkitbag').delay(2000).slideUp();
			}
		});
		return false;
	});
	
	$('.coming_soon').click(function(){
		return false;
	});
	
	
	// Gallery
	
	$('#productImg .larges a,.postGallery .larges a').fancybox();
	
	$('#productImg .thumbs li a').click(function() {
		$('#productImg .larges li').fadeOut();
		var img_id = $(this).attr('rel');
		$('#'+img_id).fadeIn();
		return false;
	});
	$('.postGallery .thumbs li a').click(function() {
		$('.postGallery .larges li').fadeOut();
		var img_id = $(this).attr('rel');
		$('#'+img_id).fadeIn();
		return false;
	});
	
	// Event booking dialog
	$('#bookevent').dialog({
		autoOpen:false,
		width:'400px',
		title: 'Enquiry about this event',
		resizable: false
	});		
	$('.event_enquire').click(function() {
		$('#bookevent').dialog('open');
		return false;
	});
	$('.submit_event_booking').live('click',function() {
		// Check captcha
		var captcha = $('#captcha').val();
		if(captcha == '2') {
			var form_data = $('#booking_form').serialize();
			$.ajax({
				type: "POST",
				url: "/includes/form-processor.php",
				data: form_data,
				success: function(msg){
					$('#bookevent').html('Thank you, we will be in touch soon.<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1068989860/?label=Y7dcCNahRhCk-939Aw&amp;guid=ON&amp;script=0"/>');
				}
			});
		} else {
			$('.error').show();
		}
		return false
	});


	// Sales enquiry dialog
	$('#sales_enquiry').dialog({
		autoOpen:false,
		width:'400px',
		title: 'Enquiry about this item',
		resizable: false
	});		
	$('.sales_enquiry').click(function() {
		var product = $(this).attr('title');
		$('#product_name').val(product);
		$('#sales_enquiry').dialog('open');
		return false;
	});
	$('.submit_sales_enquiry').live('click',function() {
		// Check captcha
		var captcha = $('#telephone').val();
		if(captcha == '2') {
			var form_data = $('#sales_enquiry_form').serialize();
			$.ajax({
				type: "POST",
				url: "/includes/form-processor.php",
				data: form_data,
				success: function(msg){
					$('#sales_enquiry').html('Thank you, we will be in touch soon.<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1068989860/?label=FqeBCKjsvQIQpPvd_QM&amp;guid=ON&amp;script=0"/>');
				}
			});
		} else {
			$('.error').show();
		}
		return false
	});


	
	
	// Date picker
	
	$('.date').datepicker({ 
		dateFormat: 'dd-mm-yy',
		minDate: 0,
		onSelect: function(dateText, inst) {
			var date_from = $('#date_from').val();
			var date_to = $('#date_to').val();
			var basket_id = $('#basket_id').val();
			$.ajax({
				type: "POST",
				url: "/includes/form-processor.php",
				data: 'date_from='+date_from+'&date_to='+date_to+'&basket_id='+basket_id,
				success: function(msg){
					$('#hire_charge').html(msg);
				}
			});
		}
	});
	
	// remove sign up 
	defaulValue = 'Enter your email here';
	$("#sub_email").live('focus',function(){if(this.value==this.defaultValue)this.value='';}).live('blur',function(){ if(this.value=='')this.value=this.defaultValue;});
	
	
});

$(window).load(function() {
	$('#banner').nivoSlider();
});

