$(document).ready(function(){
	// Fonctions des listes de travaux----------------
	$("a.switch_thumb").toggle(function(){
		$(this).addClass("swap");
		$("ul.display").fadeOut("fast", function() {
			$(this).fadeIn("fast").addClass("thumb_view");
		});
	}, function () {
		$(this).removeClass("swap");
		$("ul.display").fadeOut("fast", function() {
			$(this).fadeIn("fast").removeClass("thumb_view");
		});
	});
	
	//Fiche de contact
	/*
	 * contactable 1.2.1 - jQuery Ajax contact form
	 *
	 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
	 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
	 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
	 *
	 * Revision: $Id: jquery.contactable.js 2010-01-18 $
	 *
	 */
	 
	//extend the plugin
	//define the new for the plugin ans how to call it	
	$.fn.contactable = function(options) {
		//set default options  
		var defaults = {
			name: 'Name',
			email: 'Email',
			message : 'Message',
			subject : 'Message du site uhcronikart',
			recievedMsg : 'Merci pour votre message',
			notRecievedMsg : 'Désolé, mais votre message n a pu être envoyé, essayez plus tard. ',
			disclaimer: 'Merci de me laisser un message, je vous répondrai très rapidement',
			hideOnSubmit: true
		};
		//call in the default otions
		var options = $.extend(defaults, options);
		//act upon the element that is passed into the design    
		return this.each(function(options) {
			//construct the form
			$(this).html('<div id="contactable"></div><form id="contactForm" method="" action=""><div id="loading"></div><div id="callback"></div><div class="holder"><p><label for="name">Nom <span class="red"> * </span></label><br /><input id="name" class="contact" name="name" /></p><p><label for="email">E-Mail <span class="red"> * </span></label><br /><input id="email" class="contact" name="email" /></p><p><label for="comment">Votre message <span class="red"> * </span></label><br /><textarea id="comment" name="comment" class="comment" rows="4" cols="30" ></textarea></p><p><input class="submit" type="submit" value="Envoyer"/></p><p class="disclaimer">'+defaults.disclaimer+'</p></div></form>');
			//show / hide function
			$('div#contactable').toggle(function() {
				$('#overlay').css({display: 'block'});
				$(this).animate({"marginLeft": "-=10px"}, "fast"); 
				$('#contactForm').animate({"marginLeft": "-=0px"}, "fast");
				$(this).animate({"marginTop": "+=0px"}, "slow"); 
				$('#contactForm').animate({"marginBottom": "+=512px"}, "slow"); 
			}, 
			function() {
				$('#contactForm').animate({"marginBottom": "-=512px"}, "slow");
				$(this).animate({"marginTop": "-=0px"}, "slow").animate({"marginLeft": "+=10px"}, "fast"); 
				$('#overlay').css({display: 'none'});
			});
			
			//validate the form 
			$("#contactForm").validate({
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					email: {
						required: true,
						email: true
					},
					comment: {
						required: true
					}
				},
				//set messages to appear inline
					messages: {
						name: "",
						email: "",
						comment: ""
					},			

				submitHandler: function() {
					$('.holder').hide();
					$('#loading').show();
					$.post('mail.php',{subject:defaults.subject, name:$('#name').val(), email:$('#email').val(), comment:$('#comment').val()},
					function(data){
						$('#loading').css({display:'none'}); 
						if( data == 'success') {
							$('#callback').show().append(defaults.recievedMsg);
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#contactForm').animate({dummy:1}, 2000).animate({"marginBottom": "-=460px"}, "slow");
								$('div#contactable').animate({dummy:1}, 2000).animate({"marginBottom": "-=460px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
								$('#overlay').css({display: 'none'});	
							}
						} else {
							$('#callback').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
	//suite fiche contact
	$('#contact').contactable({
		subject: 'Message envoyé à partir du site UchronikArt.fr'
	});
	// Menu Navigation -------------------------------------------------------------------------------------
	/**
	* for each menu element, on mouseenter, 
	* we enlarge the image, and show both sdt_active span and 
	* sdt_wrap span. If the element has a sub menu (sdt_box),
	* then we slide it - if the element is the last one in the menu
	* we slide it to the left, otherwise to the right
	*/
	$('#navigation-top > li').bind('mouseenter',function(){
		var $elem = $(this);
		$elem.find('img')
			 .stop(true)
			 .animate({
				'width':'170px',
				'height':'170px',
				'left':'0px'
			 },400,'easeOutBack')
			 .andSelf()
			 .find('.sdt_wrap')
			 .stop(true)
			 .animate({'top':'90px'},500,'easeOutBack') // position texte dans sous menu
			 .andSelf()
			 .find('.sdt_active')
			 .stop(true)
			 .animate({'height':'130px'},300,function(){ // hauteur sous-menu
			var $sub_menu = $elem.find('.sdt_box');
			if($sub_menu.length){
				var left = '170px';
				if($elem.parent().children().length == $elem.index()+1)
					left = '-170px';
				$sub_menu.show().animate({'left':left},200);
			}	
		});
	}).bind('mouseleave',function(){
		var $elem = $(this);
		var $sub_menu = $elem.find('.sdt_box');
		if($sub_menu.length)
			$sub_menu.hide().css('left','0px');
		
		$elem.find('.sdt_active')
			 .stop(true)
			 .animate({'height':'0px'},300)
			 .andSelf().find('img')
			 .stop(true)
			 .animate({
				'width':'0px',
				'height':'0px',
				'left':'85px'},400)
			 .andSelf()
			 .find('.sdt_wrap')
			 .stop(true)
			 .animate({'top':'10px'},500);
	});
	// Toolbar -------------------------------------------------------------------------------------
		//hide toolbar and make visible the 'show' button
		$("span.downarr a").click(function() {
			$("#toolbar").slideToggle("fast");
			$("#toolbarbut").fadeIn("slow");
		});
		
		//show toolbar and hide the 'show' button
		$("span.showbar a").click(function() {
			$("#toolbar").slideToggle("fast");
			$("#toolbarbut").fadeOut();
		});
		
		//show tooltip when the mouse is moved over a list element 
		$("ul#social li").hover(function() {
			$(this).find("div").fadeIn("fast").show(); //add 'show()'' for IE
			$(this).mouseleave(function () { //hide tooltip when the mouse moves off of the element
				$(this).find("div").hide();
			});
		});
		
		//don't jump to #id link anchor 
		$(".facebook, .twitter, .delicious, .digg, .rss, .stumble, .menutit, span.downarr a, span.showbar a").click(function() {
			return false;
		});
		
		//show quick menu on click 
		$("span.menu_title a").click(function() {
			if($(".quickmenu").is(':hidden')){ //if quick menu isn't visible 
				$(".quickmenu").fadeIn("fast"); //show menu on click
			}
			else if ($(".quickmenu").is(':visible')) { //if quick menu is visible 
				$(".quickmenu").fadeOut("fast"); //hide menu on click
			}
		});
		
		//hide menu on casual click on the page
		$(document).click(function() {
			$(".quickmenu").fadeOut("fast");
			$(".quickmenu").css({'vivibility': 'hidden'});
		});
		$('.quickmenu').click(function(event) { 
			event.stopPropagation(); //use .stopPropagation() method to avoid the closing of quick menu panel clicking on its elements 
		});
	
	
	
});

