//chargement complete
$(document).ready(function(){
	
	/* GESTION DES POLICES ALWYN */
	Cufon.replace('#header .nav .links a, .encarts-categ h2, .encarts-articles h2, .siteunder h2, #menu, .site h1, .site .h1, .infos .title, .articles-infos h1, .articles-products h2, .articles-assos h2, .institutional h1, .institutional h2, .shopping-cart .navigation, .shopping-cart h1, .shopping-cart h2, .alphabeat,#pager label, #pager strong, #pager h2, #pager h3, #pager .wizzard li', { fontFamily: 'Alwyn' });
	
   //remplace les liens <span href=""> en <a href=""> à la volée
   $('span[href]').each(function(){
   		$target = "_self";
   		if ($(this).attr("target"))
   			$target = $(this).attr("target");
   		$str_replace = "<a";
   		$str_replace += " title=\"" + $(this).attr('title') + "\" ";
   		$str_replace += " href=\"" + $(this).attr('href') + "\" ";
   		$str_replace += " target=\"" + $target + "\" ";
   		$str_replace += " rel=\"" + $(this).attr('rel') + "\" ";
   		$str_replace += " class=\"" + $(this).attr('class') + "\" ";
   		$str_replace += " style=\"" + $(this).attr('style') + "\" ";
   		$str_replace += ">" + $(this).html() + "</a>";
        $(this).replaceWith( $str_replace  );  
    });
    
    /* use lightbox */  
	$('a[rel=lightbox]').lightBox({
		overlayBgColor: '#000000',
		overlayOpacity: 0.6,
		imageLoading: '/templates/decoclico/img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/templates/decoclico/img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/templates/decoclico/img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/templates/decoclico/img/lightbox/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'de'
   });
   
   /* use facebox */
   $('a[rel*=facebox]').facebox({
   	opacity : 0.5,
   	loadingImage : '/templates/decoclico/img/lightbox/lightbox-ico-loading.gif',
	closeImage   : '/templates/decoclico/img/lightbox/lightbox-btn-close.gif'   
   });
    
   //quantité sur panier
   $('td.quantity .less').click(function(){
   	   	$o = $('input[type=text]', this.parentNode);
   		$o.val(Math.max(parseInt($o.val())-1,0));
   });
   
   $('td.quantity .more').click(function(){
   	   	$o = $('input[type=text]', this.parentNode);
   	   	$o.val(parseInt($o.val())+1);
   });
   
   //form
   $("form").jayrform();
   $("form[name=optin]").validate();
   $("form[name=contact_us]").validate();
   
   //carousel fiche produit	
	$('#slide').tabs({ fx: { opacity: 'toggle' } });
	
	//spec tech fiche produit
	$('#infos-techniques').click(function(){
		$('> div', this).toggle();
	});
	
	$('#infos-livraison').click(function(){
		$('> div', this).toggle();
	});
	    	   
});

function changesort(element){
	//alert(element.value);
	//var search=('&'+location.search.substr(1)).replace(/&(page|info|sort)=[^&]+/gi,'')+'&sort='+escape(element.value);
	//search=search.replace(/&sort=2a/i,'');
	//search=search.replace(/^&+/,'?');
	$sort = element.value;
	if ($sort.length > 0)
		location.href=window.location.host+location.pathname+'?sort='+$sort;
	else
		location.href=window.location.host+location.pathname;
}

