/**
 * Liens en blank
 */
$('a').click(function() {
	var rel = $(this).attr('rel');
	if(rel == 'blank' || rel == 'popup' || rel == "popbla") {
		window.open($(this).attr('href'));
		return false;
	}
});

/**
 * Lightbox
 */
$(document).ready(function(){
	var as = $("a[rel^='prettyPhoto']");
	if(as.length) {
		as.prettyPhoto({
			animationSpeed:'normal',
			theme: 'facebook',
			opacity: 0.40
		});
	}
});


$("a[rel=favoris]").click(function() {
	var atr = $(this).attr('id').split("--");
	var obj = atr[0];
	var id = atr[1];
	
	openFavorisBox(obj,id);
	return false;
});


$("a[rel=delfavoris]").click(function() {
	var atr = $(this).attr('id').split("--");
	var obj = atr[0];
	var id = atr[1];
	var visite = atr[2];
	var div = atr[3];
	
	delCarnet(obj,id,visite);
	
	if(div) {
		$('#'+div).slideUp('normal',function() {$(this).remove()});
	} else {
		$(this).parent('div').slideUp('normal',function() {$(this).remove()});
	}
	
	return false;
});

function delFromCarnet (obj,id,visite) {	
	$.ajax({url:window.location.pathname+'?delFavoris='+obj+'&delId='+id+'&delFrom='+visite});
}


$(document).ready(function() {
	$("object").click(function() {
		$('#largeur,#outfnd1').unbind('click');
		return false;
	});
});


function openFavorisBox(obj,id) {
	
	$("#favoris").dequeue();
	
	if($("#favoris").is(':visible')) {	
		$("#favoris").hide();
		$('#largeur,#outfnd1').unbind('click');
	}
	
	
	$('#favoris').css('top',window.mouseY+"px");
	if( (window.mouseX - $('#largeur').offset().left ) > 600) {
		//alert(window.mouseX - $('#largeur').offset().left );
		$('#favoris').css('right',($(document).width() - window.mouseX)+"px");
		$('#favoris').css('left',"auto");
		
	} else {
		$('#favoris').css('left',window.mouseX+"px");
		$('#favoris').css('right',"auto");
	}
	$('#favoris').fadeIn('normal',function() {$('#largeur,#outfnd1').click(function(){$('#favoris').fadeOut();
			$('#largeur,#outfnd1').unbind('click');
		});
	});	
	$('#favoris').html("<img src='/img/ajax-loader.gif' alt='' />");
	$('#favoris').load(window.location.pathname+'?addFavoris='+obj+'&addId='+id);
	
	
}



$('#largeur').mousemove(function(event) {	

  window.mouseX = event.pageX;
  window.mouseY = event.pageY;    
});

$('body').append('');

$('#favoris').hide();


/*
as = document.getElementsByTagName('a');
l = as.length;
for(p=0;p<l;p++) {
	tag = as[p];
	
	ot = tag.outerHTML;
	if(ot && ( ot.toLowerCase().indexOf('blank') > 0 || ot.toLowerCase().indexOf('popup') > 0|| ot.toLowerCase().indexOf('window.open') > 0) ) {
		tag.onclick = function(){};
		tag.rel="";
		tag.target="";
	}
	if(tag.rel == "popbla") {
		tag.onclick = function() {
			window.open(this.href);
			return false;				
		}
	}
			
}
*/
/*
		if(gid('msgs')) {
			gid('msgs').innerHTML = <?=str_replace(array("\n","\r")," ", alt($GLOBALS['MSG']))?>;
			l = gid('msgs').innerHTML;
		}
		if(l.length) {
			gid('msgs').style.display = "block";
		}
*/
