

	/**
	 * Ajoute un produit dans le panier
	 * @param {Object} id
	 */
	function addCart(id){
	  var id_p = id;
	  if ( $('#produit-taille') && $('#produit-taille').val() > 0 ) id_p = $('#produit-taille').val();
		$('#commande-cart').load('_ajax.php',
				{type: 'panier-add', produit_id: id_p}
		);
		$('#panier-nb').load('_ajax.php',
				{type: 'panier-nb'}
		);
	}

	/**
	 * Supprime un produit dans le panier
	 * @param {Object} id
	 */
	function deleteCart(id){

		// Suppression de la ligne pour la page panier.php
		if ( $('#panier-produit-'+id)) {
			if ( parseInt($('#panier-produit-'+id+" .qty").html()) > 1 )
				$('#panier-produit-'+id+" .qty").html( parseInt($('#panier-produit-'+id+" .qty").html())-1 );
			else $('#panier-produit-'+id).hide();
		}
		
		$('#commande-cart').load('_ajax.php',
				{type: 'panier-del', produit_id: id},
				function() {
					$('#commande-cart-panier').load('_ajax.php',
							{type: 'panier-html'},
							function() {
								$('.sorted-table').tablesorter({ widgets: ['zebra'], textExtraction: 'complex' });
							}
					);
				}
		);
		$('#panier-nb').load('_ajax.php',
				{type: 'panier-nb'}
		);
	}

	/**
	 * Supprime tous les produits du panier
	 * @param {Object} id
	 */
	function deleteAllCart(){
		$('#commande-cart').load('_ajax.php',
				{type: 'panier-del-all'},
				function() {
					$('#commande-cart-panier').load('_ajax.php',
							{type: 'panier-html'},
							function() {
								$('.sorted-table').tablesorter({ widgets: ['zebra'], textExtraction: 'complex' });
							}
					);
				}
		);
	}

	// fonction pour le backoffice : boutons Gras, italique.....
	function getActiveText(nom_form,nom_champ,balise_deb,balise_fin) {
		var champ=eval("document."+nom_form+"."+nom_champ);
		if(document.selection) {
			vartxt = document.selection.createRange().text;
			if (vartxt!="") {
			document.selection.createRange().text = balise_deb+vartxt+balise_fin;
			}
		}
		else {
			champ.value=champ.value.substring(0,champ.selectionStart)+balise_deb+champ.value.substring(champ.selectionStart,champ.selectionEnd)+balise_fin+champ.value.substring(champ.selectionEnd,champ.value.length);
		}
		return true;
	}
	
	
	
/* jQuery.preloader - v0.95 - K Reeve aka BinaryKitten
*
* v0.95
* 	# Note - keeping below v1 as really not sure that I consider it public usable.
* 	# But it saying that it does the job it was intended to do.
* 	Added Completion of loading callback.
* 	Main Reworking With Thanks to Remy Sharp of jQuery for Designers
*/
(function ($) {
	$.preLoadImages = function(imageList,callback) {
		var pic = [], i, total, loaded = 0;
		if (typeof imageList != 'undefined') {
			if ($.isArray(imageList)) {
				total = imageList.length; // used later
					for (i=0; i < total; i++) {
						pic[i] = new Image();
						pic[i].onload = function() {
							loaded++; // should never hit a race condition due to JS's non-threaded nature
							if (loaded == total) {
								if ($.isFunction(callback)) {
									callback();
								}
							}
						};
						pic[i].src = imageList[i];
					}
			}
			else {
				pic[0] = new Image();
				pic[0].onload = function() {
					if ($.isFunction(callback)) {
						callback();
					}
				}
				pic[0].src = imageList;
			}
		}
		pic = undefined;
	};

	$.preLoadCSSImages = function(callback) {
		var pic = [], i, imageList = [], loaded = 0, total, regex = new RegExp("url\((.*)\)",'i'),spl;
		var cssSheets = document.styleSheets, path,myRules,Rule,match,txt,img,sheetIdx,ruleIdx;
		for (sheetIdx=0;sheetIdx < cssSheets.length;sheetIdx++){
			var sheet = cssSheets[sheetIdx];
			if (typeof sheet.href == 'string' && sheet.href.length > 0) {
				spl = sheet.href.split('/');spl.pop();path = spl.join('/')+'/';
			}
			else {
				path = './';
			}
			myRules = sheet.cssRules ? sheet.cssRules : sheet.rules;
			for (ruleIdx=0;ruleIdx < myRules.length;ruleIdx++) {
				Rule = myRules[ruleIdx];
				txt = Rule.cssText ? Rule.cssText : Rule.style.cssText;
				match = regex.exec(txt);
				if (match != null) {
					img = match[1].substring(1,match[1].indexOf(')',1));
					if (img.substring(0,4) == 'http') {
						imageList[imageList.length] = img;
					}
					else if ( match[1].substring(1,2) == '/') {
						var p2 = path.split('/');p2.pop();p2.pop();p2x = p2.join("/");
						imageList[imageList.length] = p2x+img;
					}
					else {
						imageList[imageList.length] = path+img;
					}
				}
			};
		};

		total = imageList.length; // used later
		for (i=0; i < total; i++) {
			pic[i] = new Image();
			pic[i].onload = function() {
				loaded++; // should never hit a race condition due to JS's non-threaded nature
				if (loaded == total) {
					if ($.isFunction(callback)) {
						callback();
					}
				}
			};
			pic[i].src = imageList[i];
		}

	};
	$.preLoadAllImages = function(imageList,callback) {
		if (typeof imageList != 'undefined') {
			if ($.isFunction(imageList)) {
				callback = imageList;
			}
			else if (!$.isArray(imageList)) {
				imageList = [imageList];
			}
		}
		$.preLoadCSSImages(function(){
			if (imageList.length > 0) {
				$.preLoadImages(imageList,function(){
					callback();
				});
			}
			else {
				callback();
			}
		});
	}
})(jQuery);
