/* ----
* VIDEO
*/
$(function() {
	$.fn.play_video = function(filename, autostart) {
		this.empty();
		this.flash({
		    src: 'flvplayer.swf',
		    width: 250,
		    height: 190,
			wmode: "opaque",
			flashvars: { 
				file: filename,
				lightcolor: "0xFFFFFF",
				backcolor: "0x0EAB8E",
				frontcolor: "0xFFFFFF",
				logo: "img/logo.video.png",
				image: filename + ".jpg",
				autostart: ( autostart ? "true" : "false" )
			}
		}, { expressInstall: true });
	};
});

/* ---
* declinaison_onmouseover
*/
function declinaison_onmouseover() {

	var src = $(this).attr("src");
	src = src.substring(src.indexOf("&src=")+5,src.indexOf("&w="));
	
	var photo_princ_src = $("#fiche #photo").attr("src");
	var query1 = photo_princ_src.substring(0,photo_princ_src.indexOf("&src=")+5);
	var query2 = photo_princ_src.substring(photo_princ_src.indexOf("&w="));

	var old_src = $("#fiche #photo").attr("src");
	var old_display = $("#fiche #photo").css("display");
	
	$("#fiche #photo").css("display", "");
	$("#fiche #photo").attr("src", query1 + src + query2 );
	$("#fiche #video").css("display", "none");
	
	$(this).mouseout(function(){  
		$("#fiche #photo").attr("src", old_src);  
		$("#fiche #photo").css("display", old_display);  
		$("#fiche #video").css("display", "");  
	});
}

/* ---
* devis_add_form_submit
*/
function devis_add_form_submit() {
	var input = $("#ajout INPUT#qte");
	var nb = parseInt(input.val());
	if(isNaN(nb)) nb = 0;
	if(nb<=0) {	
		alert("Vous devez indiquer une quantité d'article !");
		input.val("").focus();
		return false;
	}
	return true;
}

/* ---
* devis_add_form_submit
*/
function devis_delete_item(a) {
	var tr = $(a).parents("TR").eq(0);
	var key = tr.attr("id"); 
	if(!confirm("Êtes-vous certain de vouloir supprimer cette élément de votre demande de devis ?")) return false;
	$.get("./?controller=devis&action=remove&key=" + key,  function(data){
		tr.fadeOut();
	 });
}