var errorXHR = 'Erreur, impossible d\'afficher le contenu de cette fen&ecirc;tre';
var calc = null;
$(document).ready(function(){
	$('#connect label').each(function(index,element){
		var ident = $(element).attr('for');
		var input = $('#'+ident);
		if('password' == input.attr('type')) {
			input.after('<input type="text" id="' + ident + '2" value="' + $(element).text() +'" />');
			input.hide();
			$('#' + ident + '2').focus(function(){
				$(this).hide();
				$('#' + ident).show().focus();
			});
		}
		else {
			input.val($(element).text());
		}
	});
	$('input[name=password]').blur(function(){
		if('' == $(this).val()) {
			$(this).hide();
			$('#' + $(this).attr('id') + '2').show();
		}
	});
	var login = $('input[name=login]');
	login.blur(function(){
		var defVal = $('label[for=' + $(this).attr('id') + ']').text();
		if('' == $(this).val()) {
			$(this).val(defVal);
		}
	});
	login.focus(function(){
		var defVal = $('label[for=' + $(this).attr('id') + ']').text();
		if ($(this).val() == defVal) {
			$(this).val('');
		}
	});
	$('input#mail').focus(function(event){
		if('Votre courriel ici' == $(this).val()) {
			$(this).val('');
		}
	});
	$('a.popup').click(function(event){
		event.stopImmediatePropagation();
		var width = 560;
		var height = 550;
		var heightframe = 99;
		var obj = $(this);
		if(obj.hasClass('little')) {
			height = 410;
		}
		if(obj.hasClass('mini')) {
			height = 200;
			heightframe = 98;
		}
		$('body').append('<div id="modal-dialog"><iframe src="' + obj.attr('href') + '?iframe=1" frameborder="0" border="0" width="100%" height="' + heightframe + '%" style="border:0;width:100%;height:' + heightframe + '%;padding:0;margin:0"></iframe></div>');
		var popup = $('#modal-dialog');
		popup.dialog({
			modal: true,
			resizable: false,
			width: width,
			height: height,
			close: function(event, ui) {
				$(this).dialog('destroy');
				popup.remove();
			}
		});
		return false;
	});
	$('#calc1').before('<div class="second" id="calc2"></div>');
	$('#calc2').hide();
	calc = $('#calc2');
	setTimeout('animation()',3000);
});
function animation(){
	calc.css({left:'-950px'});
	var i = calc.attr('id').substr(4);
	$('#p' + i).css({right:'-' + (i=='2'?'890':'920') + 'px'}).show();
	var end = false;
	calc = $('#calc' + (i=='1'?'2':'1'));
	$('.second').animate({opacity:'toggle',left:'+=950'},1000,'swing');
	$('.phrase').animate({right:'+=950'},2000,'swing',function(){
		if(!end){
			setTimeout('animation()',6000);
			end=true;
		}
	});
}
