// JavaScript Document

// SLIDE L'ABRI
$(function(){
	$('#slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 5000,
		pause: 2500,
		hoverPause: true,
		animationStart: function(current){
			$('.caption').animate({
				bottom:-35
			},100);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationStart on slide: ', current);
			};
		},
		animationComplete: function(current){
			$('.caption').animate({
				bottom:0
			},200);
			if (window.console && console.log) {
				// example return of current slide number
				console.log('animationComplete on slide: ', current);
			};
		},
		slidesLoaded: function() {
			$('.caption').animate({
				bottom:0
			},200);
		}
	});
});

/*
$(document).ready(function (){	
	var $active = $('#UserLoginForm');
	$active.css({opacity: 0.0})
		   .animate({opacity: 0.2}, 600);
});
$(document).ready(function (){$("#UserLoginForm").hover(function() {
		var $active = $('#UserLoginForm');
		$active.animate({opacity: 1.0}, 150);
	} , function() { //on hover out...
		var $active = $('#UserLoginForm');
		$active.animate({opacity: 0.2}, 150);
})});

$(document).ready(function (){$("input#UserMail").select(function (){ //on selected...
		var $active = $('#UserLoginForm');
		$active.animate({opacity: 1.0}, 150);
	} , function() { //on hover out...
		var $active = $('#UserLoginForm');
		$active.animate({opacity: 0.2}, 150);
})});

*/

// si aucun des trois element n'est selectionner faire le fadeout !
// ...

function effaceText(element, text){
	if(document.getElementById(element).value == text){
		document.getElementById(element).value = '';
	}
}

function ecritText(element, text){
	if(document.getElementById(element).value == ''){
		document.getElementById(element).value = text;
	}
}

$(document).ready(function() {
	//$("#UserBirthday").datepicker({ altField: '#UserBirthday', altFormat: 'dd.mm.yy', dateFormat: 'dd.mm.yy' });
	
	// sélectionne le champ email (login)
	if(window.location.href == "http://www.labri.ch/users/login"){
		document.getElementById('UserMail').focus();
	}
	
	/* anime le titre des sidebars */
	$(".sidebarContent").hover(function(){
		$(this).find(".sidebarTitre").animate({top:'3px'},{queue:false,duration:150});
	}, function(){
		$(this).find(".sidebarTitre").animate({top:'0px'},{queue:false,duration:150});
	});
	
	/*
	/* Affiche la partie masquée au click*/
	$(".showDetail").toggle(function(){
		$(this).rotate({animateTo:180});
  		$(this).parent().find(".detailContenuSidebar").slideDown(240);
	},function(){
		$(this).rotate({animateTo:0});
  		$(this).parent().find(".detailContenuSidebar").slideUp();
	});
	

	
	$("a.confirm").each(function(){
	   $(this).attr("href", "javascript:if(confirm('Etes vous sur de vouloir continuer ?')) document.location.href='"+$(this).attr("href")+"'");
    });
	
	$("a img.confirm").each(function(){
	   $(this).parent().attr("href", "javascript:if(confirm('Etes vous sur de vouloir continuer ?')) document.location.href='"+$(this).parent().attr("href")+"'");
    });
	
	$('textarea.elastic').elastic();
	
	$("ul#topnav li").hover(function() { //Hover over event on list item
		$(this).find("span").hide()
							.css({opacity: 0.75})
							.slideDown(250); //Show the subnav
	} , function() { //on hover out...
		$(this).find("span").hide(); //Hide the subnav
	});
	
	$(function(){
		// Accordion
		$("#accordion").accordion({ header: "h3" });
	
		//Autocomplete
		$("#autocomplete").autocomplete({
			source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"]
		});
	
		// Button
		$("#button").button();
		$("#radioset").buttonset();
	
		// Tabs
		$('#tabs').tabs();
	
	
		// Dialog			
		$('#dialog').dialog({
			autoOpen: false,
			width: 600,
			buttons: {
				"Ok": function() { 
					$(this).dialog("close"); 
				}, 
				"Cancel": function() { 
					$(this).dialog("close"); 
				} 
			}
		});
		
		// Dialog Link
		$('#dialog_link').click(function(){
			$('#dialog').dialog('open');
			return false;
		});
	
		// Datepicker
		$('#datepicker').datepicker({
			inline: true
		});
		
		// Slider
		$('#slider').slider({
			range: true,
			values: [17, 67]
		});
		
		// Progressbar
		$("#progressbar").progressbar({
			value: 20 
		});
		
		//hover states on the static widgets
		$('#dialog_link, ul#icons li').hover(
			function() { $(this).addClass('ui-state-hover'); }, 
			function() { $(this).removeClass('ui-state-hover'); }
		);
		
	});
});

function slideSwitch() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	var $next =  $active.next().length ? $active.next()
		: $('#slideshow IMG:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 4000 );
});

$(document).ready(function (){$('#listeActivite').wslide({
	width: 600,
	height: 640,
	pos: 1,
	horiz: true,
	duration: 800,
	effect: 'easeOutExpo',
	autolink: false
})});

$(document).ready(function (){
	var $active = $('#menuListe');
	$active.css({'display' : 'block'});
});

/*$(document).ready(function(){ 
	$('div.entreeContenuSidebar').click(function() {
		$('.detailContenuSidebar').show() 
	});
 });
*/
