﻿// search
function test(leq,val,sens){
	if(sens==0){
		if(leq.value==val)
			leq.value="";
	}else{
		if(leq.value.length==0)
			leq.value=val;
	}
}
function oksearch(){
	if($("#s").attr("value")=="" || $("#s").attr("value")=="Recherche") return false;
	else return true;
}



jQuery.fn.extend({
	findPos : function() {
		var obj = jQuery(this).get(0);
		var curleft = obj.offsetLeft || 0;
		var curtop = obj.offsetTop || 0;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		return {x:curleft,y:curtop};
	}
});


var clicked = false;
var scr = 0;

function doItHome(nbpost, leqscr) {

	var larg = $(window).width();
	var nbparpage = parseInt(larg/185);
	var mywidth = 6980 - $('#row0').width();
	// alert(mywidth);
	$('#rows').css("width",mywidth+"px");
	if(leqscr > 1){
		pos = $('#masterrows').findPos();
		newpos = pos.x - (nbparpage*185*(leqscr-1)) - 10;
		$('#masterrows').animate({left:newpos+"px"},1000,function(){
			if($(this).findPos().x + parseInt(nbpost/3)*185 + $("#row0").width() - larg < 0) $('#right').hide();
		});
		$('#left').show();
	}
	var timer = setInterval('flickrRotate()',5000);	

	$('a.vignette').removeAttr("title");
	$('a.vignette').find('img').removeAttr("alt");
	$('a.contenu').removeAttr("title");
	$('div.detailitem').hover(function(){
		$(this).find('a.vignette img.thumb').stop().animate({top:'-90px'},300);
		$(this).find('a.vignette img.play').stop().animate({top:'0px'},300);
	},function(){
		$(this).find('a.vignette img.thumb').stop().animate({top:'0px'},300);
		$(this).find('a.vignette img.play').stop().animate({top:'90px'},300);
	});
	// if(larg<960) {larg=960; $('body').css("overflow-x","scroll");}
	if((nbpost/3) < nbparpage) 
		$('#right').css('left',(larg-70)+'px').hide();
	else
		$('#right').css('left',(larg-70)+'px').show();
	$('#right').bind("mouseover",function(){
		$(this).stop().animate({left:(larg-80)+'px'},100);
	});
	$('#right').bind("mouseout",function(){
		$(this).stop().animate({left:(larg-70)+'px'},100);
	});
	$('#right').bind("click",function(){
		clearInterval(timer);
		if(!clicked){
			clicked = true;
			$('#left').show();
			$('#masterrows').each(function(){
				pos = $(this).findPos();
				newpos = pos.x - (nbparpage*185)-10;
				$(this).stop().animate({left:newpos+"px"},1000,function(){
					if($(this).findPos().x + parseInt(nbpost/3)*185 + $("#row0").width() - larg < 0) $('#right').hide();
					clicked = false;
				});
			});
		}
		return false;
	});
	$('#left').bind("mouseover", function(){
		$(this).stop().animate({left:'30px'},100);
	});
	$('#left').bind("mouseout", function(){
		$(this).stop().animate({left:'20px'},100);
	});
	$('#left').bind("click",function(){
		clearInterval(timer);
		if(!clicked){
			clicked = true;
			$('#right').show();
			$('#masterrows').each(function(){
				pos = $(this).findPos();
				newpos = pos.x + (nbparpage*185) - 10;
				$(this).stop().animate({left:newpos+"px"},1000,function(){
					if($(this).findPos().x > 600) $("#left").hide();
					clicked = false;
				});
			});
		}
		return false;
	});

// screening
	$("a[rel=follow]").each(function(){
		scr = parseInt(($(this).findPos().x) / (nbparpage*185))+1;
		newsrc = $(this).attr("href") + "/?scr="+scr;
		$(this).attr("href",newsrc);
	});

}


function doItSingle() {
	$('p').each(function(){
		if($(this).is(':empty')) $(this).hide();
	});
	$('.vvqbox').css({marginTop:'0px', paddingTop:'0px'});
}

function flickrRotate() {	
	var current = ($('div.flickrimages > img.show')?  $('div.flickrimages > img.show') : $('div.flickrimages > img:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.flickrimages > img:first') :current.next()) : $('div.flickrimages > img:first'));	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};