var mover = 1;
var last;
var modulo=30;
var nbrEvents = 0;
var domain = 'http://www.lecafecentral.com';
function mainmenu(){
$("#nav ul").css({display: "none"}); // Opera Fix
$("#nav li").hover(function(){
		$(this).find('ul:first:hidden').css({visibility: "visible",display: "none"}).show();
		},function(){
		$(this).find('ul:first').css({display: "none"});
		});
};


$('document').ready(function(){
	mainmenu();
	$("a.light").lightbox();
	
	if ($('#menu').attr('rel')){
		var bg = $('#menu').attr('rel');
		//alert(bg);
		$('body').css({backgroundImage:'url('+bg+')'});	
	}
	if ($('#rightCol').find('#fame').length>0){
	$('.fameElement').each(function(){
		if($(this).prev().length>0){
			var haut = $(this).prev().position().top+$(this).prev().height();
			
			$(this).css({'top':haut+"px"});
			//alert(haut);
		}
	});
	$('#fame').css({'visibility':'visible'});
	
		setInterval('fameAnimation()',40);
		last= $('.fameElement').last();
		first=$('.fameElement').first();
		modulo=first.height();
		$('.fameElement a').hover(function(){
			mover=0;
		},function(){
			mover=1;
		});
		
	swfImplements();
	}
	//$('#headEvents').pfuit({width:450,height:300,duration:300});
	manageTopEvents();
	
	//remove_cufon('textarea');
	
});
function manageTopEvents(){
	//var classes = new Array('first','second','third');
	var toY = 0;
	$('.topEvent').each(function(){
		$(this).css({left:(450*toY)+"px"});
		toY++;
	});
	nbrEvents=toY;
	$('.topEvent').first().addClass('first');
	$('.first').next().addClass('second');
	setInterval('eventAnimation()',5000);
}
function eventAnimation(){
	var i =0;
	$('.topEvent').each(function(){
		var leftEvent = $(this).position().left-450;
		//alert(leftEvent);
		
		$(this).animate({left:leftEvent+"px"},300,'easeOutBounce',function(){
			i++;
			if (i==nbrEvents){
				deplace(i);
			}
		});
		
		
	});
	
	}
	

function deplace(i){
			//alert(i);
			var newLeft =  $('.first').position().left+(450*nbrEvents);
			//alert(newLeft);
			$('.first').css({'left':newLeft+"px"});
			$('.first').removeClass('first');
			$('.second').addClass('first');
			
			if ($('.topEvent').last().hasClass('second')){
				$('.first').removeClass('second');
				$('.topEvent').first().addClass('second');
			}else{
				$('.first').removeClass('second');
				$('.first').next().addClass('second');
			}
			
			
			
}
function fameAnimation (){
	if ($('#fame').find('#innerFame').length>0){
	$('#innerFame').css({'top':$('#innerFame').position().top-mover+"px"});
	if ($('#innerFame').position().top==-modulo){
		first.css({'top':last.position().top+last.last().height()+"px"});
		last=first;
		if (first.next().length>0){
			first=first.next();
		}else {
			first=$('.fameElement').first();
		}
		modulo+=first.height();
	}/*if ($('#innerFame').position().top==-400){
		//alert("redo");
		$('#innerFame').css({'top':"0px"});
		$('.fameElement').each(function(){
			$(this).css({'top':($(this).position().top-400)+"px"});
			//
		});
		modulo=first.height();
	}*/
	}
}
function swfImplements(){

	var flashvars ={};
	var params = {};
	 var attributes = {};
	 
	swfobject.embedSWF(domain+"/files/flash/fame1.swf", "fame",550, 386, "9.0.0", domain+"/files/flash/expressInstall.swf", flashvars, params, attributes);
	
 }
 
 
 
function remove_cufon(selector) {
    $(selector).html( cufon_text(selector) );
    return true;
}

function cufon_text(selector) {
    var g = '';
    $(selector +' cufon cufontext').each(function() {
        g = g + $(this).html();
    }); 
    return $.trim(g);
};
