// JavaScript Document
$(function() {
	$('#mycarousel').jcarousel({
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });	   
	
	$("#commlist").scrollable({ 
        vertical:true,  
        size: 3, 
		next: '#less', 
    	prev: '#more' 
    });
	
	$("#v_logo_scroller").scrollable({ 
        vertical:true,  
        size: 6, 
		next: '#btdn', 
    	prev: '#btup' 
    });
	
	$("#contactlink").tooltip({ 
		position: "bottom center", 
		opacity: 0.9,
		effect: 'slide',
		tip: '#tipcontact'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });	
	
	$("#worklink").tooltip({ 
		position: "bottom center", 
		opacity: 0.9,
		effect: 'slide',
		tip: '#tipwork'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	$("#aboutlink").tooltip({ 
		position: "bottom center", 
		opacity: 0.9,
		effect: 'slide',
		tip: '#tipabout'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	$("#homelink").tooltip({ 
		position: "bottom center", 
		opacity: 0.9,
		effect: 'slide',
		tip: '#tiphome'
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	setInterval( "slideSwitch()", 6000 );
	
	$("a[rel=group]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'inside'
	});
	
	$("a.smenu").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'fade',
		'titlePosition' 	: 'inside'
	}).click(function() {
		$("#ves-items").slideUp();
	});;
	
	$("#ves_inner").click(function() {
		$("#ves-items").slideToggle();							   
	});
	
	
	/*
	$("a.shot").tooltip({ 
		position: "bottom center", 
		opacity: 0.9,
		effect: 'fade',
		tipClass: 'tooltip2'
	});
	*/
	
	$("#submitlogin").click(function() {						 
		$("#loginform, #msgcontainer").hide();
		$("#progress").slideDown();
		setTimeout(function() {			
			$("#progress").hide();
			$("#loginform").slideDown("normal", function() {
				$("#msgcontainer").fadeIn("normal");												 
			});
		}, 2000);								 
	});	
	
	$("#submitpassforgot").click(function() {
		$("#msgcontainer-success").show("normal");										  
	});
	
	$(".editlink").click(function() {
		var self = $(this).parent().parent();
		var adresse = self.children(".contenu-addr").children("p").children("span.adresse").text();
		var email = self.children(".contenu-addr").children("p").children("a").children("span.email").text();
		self.children(".contenu-addr").html('<textarea class="editadresstextarea">' + adresse + '</textarea>' + 
											'<input type="text" class="emailinput" value="' + email + '" />');
		$(this).hide();
		self.children(".actioncont").children(".oklink").show();
		return false;
	});
	
	/*
	$("a.shot").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'titlePosition' : 'over'		
	});
	*/
	
});

function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function slideSwitch() {
    var $active = $('#slideshow div.active');

    if ( $active.length == 0 ) $active = $('#slideshow div:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow div:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 800, function() {
            $active.removeClass('active last-active');
        });
}

