//	$Id: ks.js 77 2010-05-24 17:47:44Z Yannick $

var api_client = null;
var in_ajax = false;
var cphoto;
var fixed_dialogs = true;
var banner_timer = null;

if (($.browser.msie) && ($.browser.version.substr(0,1)=="6"))
{
	fixed_dialogs = false;
}

$(document).ready(function(){
	$.ajaxSetup({
		url: (sid_param!="")?"/ajax.php?"+sid_param:"/ajax.php",
		global: true,
		type: "POST",
		dataType: "json"
	});
	$(document).bind("ajaxStart",function(){
		in_ajax = true;
		$("#progress").fadeIn(500);
	});
	$(document).bind("ajaxStop",function(){
		$("#progress").fadeOut(500);
		in_ajax = false;
	});
	$(document).bind("ajaxError",function(){
		in_ajax = false;
		alert("Une erreur s'est produite !");
	});
	$("input[type=text],input[type=password],textarea").focus(function(){
		if ($(this).val()==$(this).attr("title"))
		{
			$(this).removeClass("blurred").val("");
		}
		$(this).select();
	}).blur(function(){
		if ($(this).val()=="")
		{
			$(this).addClass("blurred").val($(this).attr("title"));
		}
	}).each(function(){
		if ((!this.value) || (this.value==this.title))
		{
			$(this).addClass("blurred");
			this.value = this.title;
		}
	});
	$("a.photo").click(function(){
		var photo_big = $("#photo-big");
		var r = new RegExp(/^(.*?)#([0-9]+)_([0-9]+)$/);
		var m = r.exec(this.href);
		var w = Number(m[2])+20;
		var h = Number(m[3])+20;
		var t,pos;
		cphoto = $(this);
		photo_big.html("<img src=\""+m[1]+"\" width=\""+m[2]+"\" height=\""+m[3]+"\" alt=\"\" />");
		if (fixed_dialogs)
		{
			pos = "fixed";
			t = ($(window).height()-h)/2;
		}
		else
		{
			pos = "absolute";
			t = $(document).scrollTop()+($(window).height()-h)/2;
		}
		photo_big.css({
			left: ($(document).width()-w)/2,
			top: t,
			position: pos
		});
		photo_big.fadeIn(250);
		$("body").click(function(e){
			$("body").unbind("click");
			var clicked = $(e.target);
			if ((clicked.is("#photo-big")) || (clicked.closest("#photo-big").length==1))
			{
				var nphoto = cphoto.next("a.photo");
				if (nphoto.length==1) nphoto.click();
				else photo_big.fadeOut(500);
			}
			else
			{
				photo_big.fadeOut(500);
			}
			return false;
		});
		return false;
	});

	banner_timer = window.setTimeout("change_image()",10000);
});

function change_image()
{
	$(".banner_trans").fadeIn(1000,function(){
		var trans = $(".banner_trans").get(0);
		var img2 = img;
		var i = 0;

		$(".banner").get(0).src = trans.src;
		$(".banner_trans").hide();
		while ((img2==img) || (img2==pimg))
		{
			img2 = Math.floor(Math.random()*nimg);
			if (++i==10) break;
		}
		pimg = img;
		img = img2;
		trans.src = banners[img];
		banner_timer = window.setTimeout("change_image()",10000);
	});
}

function htmlspecialchars(str)
{
	if (str==null) return "";
	str = str.split('&').join('&amp;');
	str = str.split('"').join('&quot;');
	str = str.split('\'').join('&#039;');
	str = str.split('<').join('&lt;');
	str = str.split('>').join('&gt;');
	return str;
}
