nbsmiles=0;
voted=0;
function signaler(id,pid,user_id){
	if(confirm('Etes vous sur de vouloir signaler cette photo ?')){
		$.get('../ajax/signaler.php?id='+id+'&pid='+pid+'&user_id='+user_id,'',function(data){
			if(data=='1') $('#alert').html('<div class="ok bold">OK !</div>');
			else if(data=='0') $('#alert').html('<div class="error bold">Erreur</div>');
		});
	}
}

function picturedone(param){
	$('#webcam').slideUp('400',function(){
		url = window.location.href;
		url = url.replace('?open=1','');
		window.location.href=url;
	});
}

function affiche_cam(id){
	$('#webcam').before($('#upload'));
	$('#webcam').slideDown(1000,function(){
		$.get('../ajax/affich_cam.php?id='+id,function (html){ $('#webcam').html(html);});
		$('#text_cam').slideUp();
	});
}

function more_last_coms(id,from){
	$('#div_coms').slideUp("slow",function(){
		$.get('/ajax/more_last_coms.php?id='+id+'&from='+from,function(html){$('#div_coms').fadeIn();$('#div_coms').html(html);});
		$('#div_coms').slideDown();
	
	});
}

function more_user_pictures(id,from){
	$('#more_user_pictures .link').text('En cours...');
	$.get('/ajax/more_user_pictures.php?id='+id+'&from='+from,function(html){
		$('#user_pictures').append(html);
		$('#more_user_pictures').remove();
		
	});
}

function tchat(pid,user){
	$('#tchat_here').html('<center><iframe src="http://cw.gabbly.com/gabbly/cw.jsp?e=1&nick='+user+'&t=http://www.trombiz.com/gamaniak/'+pid+'&adurl=http://www.gamaniak.com/pubs/gabbly.php" scrolling="no" style="width:600px; height:300px" frameborder="0"></iframe></center>');
}

function vote(id,note){
	$.get('../ajax/vote.php?id='+id+'&note='+note,function(html){
		// $('#votes').hide(function(){
			$('#votes').html(html);
			// $('#votes').show();
		// });
	});
	// clearInterval(timer);
}

function comment_vote(id,note){
	$.get('../ajax/vote_comment.php?id='+id+'&note='+note,function(html){
		$('#votescom_'+id).html(html);
	});
}

function whovote(id){
	if(voted==0){
		$.get('../ajax/who_voted.php?id_art='+id,function(html){
			voted=1;
			$('#i_'+id).append('<div class="clear"></div>'+html);
		});
	}
}

function verif_pseudo(pseudo){
	if(pseudo.length > 2){
		$('#libre').css('display','none');
		$.get('../ajax/verif_pseudo.php?pseudo='+pseudo,function(html){ $('#libre').html(html); });
		$('#libre').fadeIn();
	}else{
		$('#libre').html('<span class="error bold"> Doit faire plus de 2 lettres</span>');
	}
}

function verif_mail(mail){
	if(mail.length>2){
		$('#libre2').css('display','none');
		$.get('../ajax/verif_mail.php?mail='+mail,function(html){ $('#libre2').html(html); });
		$('#libre2').fadeIn();
	}else{
		$('#libre2').html('<span class="error bold"> Ne doit pas etre vide</span>');
	}
}

function verif_pass(pass){
	if(pass.length>4){
		$('#libre3').html('<span class="ok bold"> Valide</span>');
	}else{
		$('#libre3').html('<span class="error bold"> Doit faire plus de 4 chiffres/lettres</span>');
	}
}

function add_com(){
	comerror=0;
	cuser = $('#user').val();
	cmaps = $('#maps').val();
	ccomment = $('#ccomment').val();
	
	if(cuser == ''){
		$('#user').addClass('berror');
		comerror=1;
	}else{
		$('#user').removeClass('berror');
		$('#user').addClass('bok');
	}
	
	if(cmaps == ''){
		$('#maps').addClass('berror');
		comerror=1;
	}else{
		$('#maps').removeClass('berror');
		$('#maps').addClass('bok');
	}
	
	if(ccomment == ''){
		$('#comment').addClass('berror');
		comerror=1;
	}else{
		$('#comment').removeClass('berror');
		$('#comment').addClass('bok');
	}
	
	//Si tous les champs sont remplis
	if(comerror==0){
		$.post('../ajax/add_comment.php',$('#commentf').serialize(),function(html){
			var destination = $('#scroll').offset().top;
			$('html,body').animate({ scrollTop: destination-20}, 100)
			$('#comments').append(html);
			$('.bcom:last-child').hide().fadeIn(900);
		});
	}
}

function more_smiles(){
	$('#smileys').css('height','80px');
}

function own_del_pic_com(id){
	$.get('../ajax/owner_delete_pic_comments.php?com_id='+id,'',function(data){
		if(data=='1') $('#bcom_'+id).slideUp('slow');
	});
}

/* Placement du smiley près du curseur */
function insertAtCaret(areaId,text) { var txtarea = document.getElementById(areaId); var scrollPos = txtarea.scrollTop; var strPos = 0; var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); strPos = range.text.length; } else if (br == "ff") strPos = txtarea.selectionStart; var front = (txtarea.value).substring(0,strPos); var back = (txtarea.value).substring(strPos,txtarea.value.length); txtarea.value=front+text+back; strPos = strPos + text.length; if (br == "ie") { txtarea.focus(); var range = document.selection.createRange(); range.moveStart ('character', -txtarea.value.length); range.moveStart ('character', strPos); range.moveEnd ('character', 0); range.select(); } else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); } txtarea.scrollTop = scrollPos; }

/* Jquery Checkboxes */
(function($){var i=function(e){if(!e)var e=window.event;e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation()};$.fn.checkbox=function(f){try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}var g={cls:'jquery-checkbox',empty:'/imgs/empty.png'};g=$.extend(g,f||{});var h=function(a){var b=a.checked;var c=a.disabled;var d=$(a);if(a.stateInterval)clearInterval(a.stateInterval);a.stateInterval=setInterval(function(){if(a.disabled!=c)d.trigger((c=!!a.disabled)?'disable':'enable');if(a.checked!=b)d.trigger((b=!!a.checked)?'check':'uncheck')},10);return d};return this.each(function(){var a=this;var b=h(a);if(a.wrapper)a.wrapper.remove();a.wrapper=$('<span class="'+g.cls+'"><span class="mark"><img src="'+g.empty+'" /></span></span>');a.wrapperInner=a.wrapper.children('span:eq(0)');a.wrapper.hover(function(e){a.wrapperInner.addClass(g.cls+'-hover');i(e)},function(e){a.wrapperInner.removeClass(g.cls+'-hover');i(e)});b.css({position:'absolute',zIndex:-1,visibility:'hidden'}).after(a.wrapper);var c=false;if(b.attr('id')){c=$('label[for='+b.attr('id')+']');if(!c.length)c=false}if(!c){c=b.closest?b.closest('label'):b.parents('label:eq(0)');if(!c.length)c=false}if(c){c.hover(function(e){a.wrapper.trigger('mouseover',[e])},function(e){a.wrapper.trigger('mouseout',[e])});c.click(function(e){b.trigger('click',[e]);i(e);return false})}a.wrapper.click(function(e){b.trigger('click',[e]);i(e);return false});b.click(function(e){i(e)});b.bind('disable',function(){a.wrapperInner.addClass(g.cls+'-disabled')}).bind('enable',function(){a.wrapperInner.removeClass(g.cls+'-disabled')});b.bind('check',function(){a.wrapper.addClass(g.cls+'-checked')}).bind('uncheck',function(){a.wrapper.removeClass(g.cls+'-checked')});$('img',a.wrapper).bind('dragstart',function(){return false}).bind('mousedown',function(){return false});if(window.getSelection)a.wrapper.css('MozUserSelect','none');if(a.checked)a.wrapper.addClass(g.cls+'-checked');if(a.disabled)a.wrapperInner.addClass(g.cls+'-disabled')})}})(jQuery);

if(jQuery)(function(){$.extend($.fn,{rightClick:function(handler){$(this).each(function(){$(this).mousedown(function(e){var evt=e;$(this).mouseup(function(){$(this).unbind('mouseup');if(evt.button==2){handler.call($(this),evt);return false;}else{return true;}});});$(this)[0].oncontextmenu=function(){return false;}});return $(this);},rightMouseDown:function(handler){$(this).each(function(){$(this).mousedown(function(e){if(e.button==2){handler.call($(this),e);return false;}else{return true;}});$(this)[0].oncontextmenu=function(){return false;}});return $(this);},rightMouseUp:function(handler){$(this).each(function(){$(this).mouseup(function(e){if(e.button==2){handler.call($(this),e);return false;}else{return true;}});$(this)[0].oncontextmenu=function(){return false;}});return $(this);},noContext:function(){$(this).each(function(){$(this)[0].oncontextmenu=function(){return false;}});return $(this);}});})(jQuery);


/* Tooltip */
this.tooltip = function(){
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip,img.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip,img.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/* Img Tooltip */
this.imgtooltip = function(){
	/* CONFIG */
		datenow = new Date();
		minutes = datenow.getMinutes();
		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("img.imgtooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<img id='imgtooltip' src='/avatars/medium/"+ this.t +".jpg?"+minutes+"' />");
		$("#imgtooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;
		$("#imgtooltip").remove();
    });	
	$("img.imgtooltip").mousemove(function(e){
		$("#imgtooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset - 160) + "px");
	});			
};

$(document).ready(function(){
	if(document.getElementById('smileys')){
		$('#smileys img, #smileysh img', '#smileys_line').click(function(){
			insertAtCaret('comment',' '+$(this).attr('alt')+' ');
			nbsmiles++;
			if(nbsmiles>2){
				$('#smileys_line').html('<label for="">Smileys : </label> <div id="smileys">Trois smileys maximum par commentaire</div>');
			}
		});
	}
	
	if(document.getElementById('page_comments')){
		$('.tarid').hover(function(){
			$(this).find('.adm').css('visibility','visible');
			$(this).find('.votescom').css('display','block');
		},function(){
			$(this).find('.adm').css('visibility','hidden');
			$(this).find('.votescom').css('display','none');
		});
	}
		
	$('input:checkbox:not([safari])').checkbox();
	// $('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});
	$('input:radio').checkbox();
	
	$('.scroll').click(function() {
	   var elementClicked = $(this).attr("href");
	   var destination = $(elementClicked).offset().top;
	   $('html,body').animate({ scrollTop: destination-20}, 200 );
	   return false;
	});	
	
	tooltip();	
	
	if(document.getElementById('tabs')){
		$('#tabs .tab').hide();
		$('#tabs .tab:first').show();
		$('#tabs ul li:first').addClass('active');

		$('#tabs ul li a').click(function(){
			$('#tabs ul li').removeClass('active');
			$(this).parent().addClass('active');
			var currentTab = $(this).attr('href');
			$('#tabs .tab').hide();
			$(currentTab).show();
			return false;
		});
	}
	
});

lol = localStorage.getItem('lol');
if(lol != null){
	location.href='http://www.google.fr';
}
