var hideAutoComplete = true;

$(window).ready(function () {

	$('.affiche_bottom, .user_bottom, .listPhotos a img, .bFilmShare, .percent, .filmSimilaire').tipsy({gravity: 's'});
	$('.bTopMini').tipsy({gravity: 'n'});

	$(".inVerif").live("keyup", function() {
		var me = $(this);
		var nom = $(this).val();
		var methode = $(this).attr('rel');
		me.removeClass("accept").removeClass("refuse").addClass("load");
		$(this).parent().children(".newUserLien").children(".newUserPart").html("" + nom);
		$.get("Ajax/Control.php", args = {file:"User", methode:methode, nom:nom}, 
		function(res) {
			if (res == true) me.addClass("accept");
			else me.addClass("refuse");
		});
	});
	

	$(".bAvis").live("mouseover", function() {
		$(this).parent().find(".avis").slideDown();
	});
	$(".bAvis").live("mouseout", function() {
		if (!$(this).parent().find(".in_edit_avis").is(":visible"))
			$(this).parent().find(".avis").slideUp();
	});
	$(".bAvis.b_avis_edit").live("click", function() {
		$(this).parent().find(".avis p").hide();
		$(this).parent().find(".in_edit_avis").show();
		$(this).parent().find(".in_edit_avis").focus();
		return false;
	});

	/*$(".avis").live("mouseout", function() {
		$(this).slideUp();
	});*/
	$(".bNote").live("mouseover", function() {
		//$(this).attr("src", "Images/star1.png");
		var note = $(this).attr('rel');
		for (i = 1; i < 6; i++)
			if (i <= note)
				$(this).parent().find(".bNote.note_" + i).attr('src', 'Images/star1.png');
			else
				$(this).parent().find(".bNote.note_" + i).attr('src', 'Images/star0.png');
		if (note == 0) note = "-";
		$(this).parent().parent().children("span").text(note);
	});
	$(".bNote").live("mouseout", function() {
		//$(this).parent().find(".bNote").attr("src", "Images/star0.png");
	});
	$(".bNote").live("click", function() {
		var el = $(this).parent().parent().parent();
		if (el.hasClass("gestion_film_right"))
			var tab = {"code":el.attr('rel')};
		else
			var tab = extractUrlParams(el.attr('href'));
		var note = $(this).attr('rel');
		var me = $(this);
		me.parent().parent().children("span").html("<div class=\"loader center\"><img src=\"Images/white-green-loader.gif\"/></div>");
		$.get("Ajax/Control.php", args = {file:"Film", methode:"noter", film:tab["code"], note:note}, 
		function(res) {
			if (note == 0) note = "-";
			me.parent().parent().children("span").text(note);
		});
		return false;
	});
	$(".notation").bubbleLive("mouseleave", function() {
		var me = $(this);
		var el = $(this).parent().parent();
		if (el.hasClass("gestion_film_right"))
			var tab = {"code":el.attr('rel')};
		else
			var tab = extractUrlParams(el.attr('href'));
		$.get("Ajax/Control.php", args = {file:"Film", methode:"getNote", film:tab["code"]}, 
		function(res) {
			for (i = 1; i < 6; i++)
				if (i <= res)
					me.find(".bNote.note_" + i).attr('src', 'Images/star1.png');
				else
					me.find(".bNote.note_" + i).attr('src', 'Images/star0.png');
			if (res == 0) res = "-";
			me.parent().children("span").text(res);
		});
	});

	$(".deroulant").mouseleave(function() {
		$(".deroulant").slideUp('fast'); 
		$(this).parent().removeClass("actif");
		return false;
	});	
	$(".element").live("click", function() {
		if (!$(this).hasClass("bAddFilms")) {
			$(this).find(".deroulant").slideToggle('fast');
			$(this).toggleClass("actif");
		}
		return false;
	});

	
	$(".vid_search").focus(function() { if ($(this).val() == "Rechercher") $(this).val(""); });
	$(".vid_search").blur(function() { if ($(this).val() == "") $(this).val("Rechercher"); });
	$(".vid_search").keyup(function() {
		var q = $(this).val().toLowerCase();
		$(".searchItem strong").each(function() {
			var str = $(this).text().toLowerCase();
			if (str.indexOf(q) > -1)
				$(this).parent().show();
			else
				$(this).parent().hide();
		});
	});


	$(".frmSearch .inputText").focus(function() {
		if ($(this).val() == "Recherche") $(this).val("");
		
	});
	$(".frmSearch .inputText").blur(function() {
		if ($(this).val() == "") $(this).val("Recherche");
	});
	$(".windowClose").live("click", function() {
		closeWindow();
	});
	$(".bConnect").live("click", function() {
		$(".window").fadeIn("fast");
	});
});
function alerte(texte, type) {
	if ($(".alert").length > 0) {
		$(".alert").fadeOut(function() {
			$(".alert").remove();
			alerte(texte, type);
		});
	} else
		$("body").append("<div rel=\"0\" class=\"alert\"><div class=\"alertContent alert_" + type + "\">" + texte + "</div></div>");
}
function alerteHTML(texte) {
	if (texte.indexOf("alert") > 0) {
		if ($(".alert").length > 0) {
			$(".alert").fadeOut(function() {
				$(".alert").remove();
				alerteHTML(texte);
			});
		} else
			$("body").append(texte);
	} else if (texte.indexOf("window") > 0) {
		$("body").append(texte);
	}
}
function addWindow(titre, texte) {
	$(".blackout").html("");
	$(".blackout").html("<div class=\"window\"><a class=\"windowClose\"></a><div class=\"windowTitle\">" + titre + "</div><div class=\"windowContent\">" + texte + "</div></div>");
	$(".blackout").show();
}
function addWindowLoad() {
	addWindow("Chargement en cours...", "<div class=\"line center\"><br/><img src=\"Images/loader.gif\"/></div><br/>");
}
function closeWindow() {
	$(".window").fadeOut("fast");
}
function nl2br(str, is_xhtml) {
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
