$('document').ready(function(){
	/* Entire block cliquable */
	$('.clickarea').click(function(){
		window.location=$(this).find('a').attr("href");
		return false;
	});
	
	/* Featured tabs manager */
	$('.featured_zone_tabs_nav li a').click(function(){
		var tab_index = $(this).parents('li').index();
		$('.featured_zone_tabs_nav li a').removeClass('current');
		$(this).addClass('current');
		$('#featured_home_zone .content>div').hide();
		$('#featured_home_zone .content>div:nth-child('+(tab_index+1)+')').show();
			if(tab_index==0){$('#featured_home_zone h4').text('La sélection Paris Voile');}
			else{$('#featured_home_zone h4').text('Nos fournisseurs');}
		return false;
	});
	
	/* Cart Mouse Manager */
	$('#header_right').hover(function(){
		$('#header_right').css('height','auto');
		$('#header_right').addClass('open');
		
		
	},function(){
		$('#header_right').animate({
		    height: '110px'
		  }, 400, function() {
		    $('#header_right').removeClass('open');
		  });	});
		
		
		/* Erase Input Value On CLick */
		// Input text reset focus
		$('input.eraseonclick').focus(function(){
			if($(this).attr('value') == this.defaultValue) $(this).attr('value', '');
		}).blur(function(){
			if($.trim(this.value) == '') this.value = (this.defaultValue ? this.defaultValue : '');
		});
		
		/* Featured blog post Loading */
		$.get(SITE_URL+'info/wp-content/themes/WpParisVoile/ajax_store_featured_posts.php', function(data) {
			$('#blog_summary').removeClass('loading');
		  $('#blog_summary').html(data);
		});
		
		/* Featured blog post Loading */
		$.get(SITE_URL+'info/wp-content/themes/WpParisVoile/plugins/ajax_slider.php', function(data) {
			$('#slider').removeClass('loading');
		  $('#slider .ctn').html(data);
			$('#home_carousel').jcarousel({
				'scroll' : 1,
				'wrap' : 'circular',
				'auto' : 5,
				'animation' : 'slow'
			});
		});
		
		/* Slider mouse over effect */
		$("#slider li").hover(function(){
			alert('test');
			$(this).children(".legend").slideUp();
		},function(){
			$(this).children(".legend").slideDown();
		});
		
		/* Fancybox manager */
		$('a.lightbox').fancybox({
			padding : 30
		});
		
		$('#add_to_cart').click(function(){
			$("#follow_shopping_lightbox_bootstrap").trigger('click');
		});
		
		/* Cheapper form manager */
		$('#cheapper').submit(function(){
			var bad = 0;
			$('input.text').each(function(){
				if($(this).val()==''){
					bad = 1;
				}
			});
			if(bad == 1){
				$('#cheapper p.error').html("Vous devez remplir tous les champs, merci !");
				$('#cheapper p.error').fadeIn();
			}
			else{
				send_cheaper_alert_mail(this);
			}
			return false;
		});
		
		/* Facebook injection on Payment confirmation Screen */
		$('#order-confirmation #order_confirmation ').append('<div class="facebook_recommandation"> Le saviez-vous ? Suivre Paris Voile sur Facebook, c\'est profiter toutes les semaines de réductions sur le catalogue, de conseils sur le matériel et de notre sélection d\'actualités voile légère et régate. <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fparisvoile&amp;send=false&amp;layout=box_count&amp;width=59&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=trebuchet+ms&amp;height=62&amp;appId=193916170684870" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:59px; height:62px;" allowTransparency="true"></iframe> </div>');
	
});

function send_cheaper_alert_mail(ressource){
	var dataString;
  dataString = ($(ressource).serialize());
	
  $.ajax({
    type: "POST",
    url: BLOG_TEMPLATE_URL+'plugins/cheaper_alert_sender.php',
    data: dataString,
    success: function(data) {
			//
    }
  });

	$('#cheapper').html('Message envoyé, merci. Nous vous recontacterons le plus rapidement possible.');
	setTimeout("$.fancybox.close();",6000);

}

