function flash_player(file_flv, width, height){
document.write('<object type="application/x-shockwave-flash" data="/upload/files/flash/player_flv_maxi.swf" width="'+width+'" height="'+height+'">\n');
document.write('<param name="movie" value="/upload/files/flash/player_flv_maxi.swf" />\n');
document.write('<param name="allowFullScreen" value="true" />\n');
document.write('<param name="FlashVars" value="flv='+file_flv+'&amp;configxml=/upload/files/flash/param.xml" />\n');
document.write('<param name="wmode" value="transparent" />\n');
document.write('<param name="height" value="'+height+'" />\n');
document.write('<param name="width" value="'+width+'" />\n');
document.write('</object>\n');
}

var produit_phare_current = null;

$(document).ready(function() {	

	// tabs fiche produit
	try {
		$("#fiche-tabs ul").idTabs();
	} catch (e) {}

	// add class to inputs
	 $(":checkbox").addClass('checkbox');
	 $(":radio").addClass('radio');
	 $(":submit").addClass('submit');
	
	// clear search field on click
	$("#pass-word, #e-mail, #recherche").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

	// feature list
	$.featureList(
		$(".feature-links a"),
		$(".feature-img li"), {
			start_item : 0
		}
	);
	
	// produit phare
	$('#produits_phares').each(function() {
		$(this).find('li').mouseover(function() {
			if(produit_phare_current) {
				produit_phare_current.removeClass('selected');
			}
			produit_phare_current = $(this);
			$(this).addClass('selected');
		}).eq(0).mouseover().find('a').mouseover();
	});
	
	// check email syntax on signup
	function isValidEmailAddress(emailAddress) {
		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
		return pattern.test(emailAddress);
	}

	$("#register-form #email").blur(function(){
		var email = $(this).attr("value");
		$(this).next('.form-check-error, .form-check-valid').remove();
		if(email) {
			if(isValidEmailAddress(email)) {
				$(this).after('<img src="/upload/images/design/ui/valid.gif" alt="ok" class="form-check-valid" />'); 
			} else {
				$(this).after('<span class="form-check-error"><img src="/upload/images/design/ui/error.gif" alt="error" />Email invalide !</span>');
			}
		} else {
			$(this).after('<img src="/upload/images/design/ui/error.gif" alt="error" class="form-check-error" />');
		}
	});
	
	// check required fields on signup
	$('#register-form').each(function() {
		$(this).find('textarea, #civilite, #nom, #prenom, #adresse, #zip, #ville, #password').blur(function() {
			var v = $(this).attr("value");
			$(this).next('.form-check-error, .form-check-valid').remove();
			if(!v) {
				$(this).after('<img src="/upload/images/design/ui/error.gif" alt="error" class="form-check-error" />');
			} else {
				$(this).after('<img src="/upload/images/design/ui/valid.gif" alt="ok" class="form-check-valid" />');
			}
		});
		$(this).submit(function() {
			var ok = true;
			$(this).find('#email, textarea, #civilite, #nom, #prenom, #adresse, #zip, #ville, #password').each(function() {
				var v = $(this).attr("value");
				$(this).next('.form-check-error').remove();
				if(!v) {
					$(this).after('<img src="/upload/images/design/ui/error.gif" alt="error" class="form-check-error" />');
					ok = false;
				}
			});
			return ok;
		});
	});
	// check if fields are empty when adding secondary addresses to avoid no name&address commands
	$('table.adresse_table').each(function() {
		$(this).find('input[type=text], textarea').blur(function() {
			var v = $(this).attr("value");
			$(this).next('.form-check-error, .form-check-valid').remove();
			if(!v) {
				$(this).after('<img src="/upload/images/design/ui/error.gif" alt="error" class="form-check-error" />');
			} else {
				$(this).after('<img src="/upload/images/design/ui/valid.gif" alt="ok" class="form-check-valid" />');
			}
		});
		$(this).parents('form').submit(function() {
			var ok = true;
			$(this).find('input[type=text], input[type=password], textarea').each(function() {
				var v = $(this).attr("value");
				$(this).next('.form-check-error').remove();
				if(!v) {
					$(this).after('<img src="/upload/images/design/ui/error.gif" alt="error" class="form-check-error" />');
					ok = false;
				}
			});
			return ok;
		});
	});
	
	//Remove style attribute in Address page
	$("strong.adresse_title").nextAll("div").removeAttr("style").addClass("address-buttons");
	
	// animation for formSuccess & formError
	$('.formSuccess, .formError, .panier_chronopost').fadeOut(800).fadeIn(800);
	
	//Add class to the selected path
	$("#chemin a:last").addClass("selected-path");
	if ($("#chemin a:last:contains('Accueil')").length) {
		$("#path").hide();
	}
	
	// promo texte "au lieu de"
	try {
		$(".panier_prix_barre").prepend("au lieu de ");
	}catch(e){}

});
