// AD Web markup.js

$(document).ready(function(){

	// lavalamp
	$('#menu-main-menu').lavaLamp({target:'li', container:'li', includeMargins:true});
	
	$('.sub-menu li').hover(
		function () {
			$('#menu-main-menu li.backLava').css("visibility","hidden")
		},
		function () {
			$('#menu-main-menu li.backLava').css("visibility","visible")
		});
	/*$('#menu-main-menu li a').hover(
		function () {
			$('#menu-main-menu li.backLava').css("visibility","visible")
	});*/
	
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// tipsy
	$('.cnticon').tipsy({fade:true, gravity:'s'});
	$('.fbicon').tipsy({fade:true, gravity:'s'});
	$('.twiticon').tipsy({fade:true, gravity:'s'});
	$('.rssicon').tipsy({fade:true, gravity:'s'});
	$('.pdficon').tipsy({fade:true, gravity:'s'});
	
	$('.fbiconlarge').tipsy({fade:true, gravity:'s'});
	$('.twiticonlarge').tipsy({fade:true, gravity:'s'});
	$('.linkediconlarge').tipsy({fade:true, gravity:'s'});
	
	$('.ico').tipsy({fade:true, gravity:'w'});
	
	$('.icoserv_online').tipsy({fade:true, gravity:'s'});
	$('.icoserv_mobile').tipsy({fade:true, gravity:'s'});
	$('.icoserv_jeux').tipsy({fade:true, gravity:'s'});
	$('.icoserv_sound').tipsy({fade:true, gravity:'s'});
	$('.icoserv_photo').tipsy({fade:true, gravity:'s'});
	
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// read more
	$('.article .thumb').hover(
	  function () {
		$(this).children("div").animate({
			left: '0px'
		})	
	  },
	  function () {
		$(this).children("div").animate({
			left: '-150px'
		})
	  });
	  
	  $('.article_right .thumb').hover(
	  function () {
		$(this).children("div").animate({
			left: '0px'
		})	
	  },
	  function () {
		$(this).children("div").animate({
			left: '-150px'
		})
	  });
	  
	  $('.toparticle .thumb').hover(
	  function () {
		$(this).children("div").animate({
			left: '0px'
		})	
	  },
	  function () {
		$(this).children("div").animate({
			left: '-300px'
		})	
	  });
	  
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// form
	$('#send_btn').click( function(){
		
		
	    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
 
            var emailaddressVal = $("#emailcontact").val();
	    
	    if(!emailReg.test(emailaddressVal)) {
		
		
		 $('#dialog-notvalid').dialog({
						draggable: true,
						resizable: false,
						width: 400,
						buttons: {
						'ok': function() {
							    $(this).dialog('close');
							}
						}
					      });
		 
		 
		return;
		
	    }
	
	  	    
	    $('#ajax-loading').html('<img src="http://www.access-dev.com/wp-content/uploads/2011/04/ajax-loader.gif" />');
	   
		$.ajax({
					  url: 'http://www.access-dev.com/wp-content/themes/custom/ajax/ad-send-contact.php',
					  data: {'nom': $('#namecontact').val(), 'email':$('#emailcontact').val(),'message':$('#messagecontact').val()   },
					  type: 'post',
					  success: function (j) {
					      
					      var obj = jQuery.parseJSON(j);

				
					      $('#ajax-loading').html('');
					      
					      $('#namecontact').val('');
					      $('#emailcontact').val('');
					      $('#messagecontact').val('');
					      
					      $('#dialog-ok').dialog({
						draggable: true,
						resizable: false,
						width: 400,
						buttons: {
						'ok': function() {
							    $(this).dialog('close');
							}
						}
					      });
					      
					  }
	  
		  });
	  
	});
	
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// galleria
	$('#images').galleria({
		transition : 'fade',
		image_crop: true,
		popup_links : false,
		extend: function() {
			this.bind(Galleria.LOADFINISH, function(e) {
			$('.galleria-info-description').hide();
			$(e.imageTarget).click(this.proxy(function(e) {
				e.preventDefault(); // removes the garbage
				var obj = this.getData();
		//		alert(obj.toSource());
		//		$.colorbox({
		//			'href': obj.description,
		//			'width' : '70%',
		//			'inline' : false,
		//			'opacity' : 0.7
		//		});
			}))
			});
		}
	});
	
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// social popup
	$("#socialpoptrigger").click(function(e) {          
	e.preventDefault();
    $("#socialpopbox").toggle();
	$("#socialpoptrigger").toggleClass("menu-open");
	});
	
	
	$("#socialpopbox").mouseup(function() {
		return false
	});
	
	
	$(document).mouseup(function(e) {
		if($(e.target).parent("a#socialpoptrigger").length==0) {
			$("#socialpoptrigger").removeClass("menu-open");
			$("#socialpopbox").hide();
		}
	});
	
	// Hyphenator
	/*Hyphenator.config({
		displaytogglebox : false,
		minwordlength : 2
	});*/
	Hyphenator.run();
	
	/*--------------------------------------------------------------------------------------------------------------------------------------------------*/
	
	// Jquery popup
		$('.acc_container').hide();
		//$('.acc_trigger:first').addClass('active').next().hide(); //Add "active" class to first trigger, then show/open the immediate next container
		 
		//On Click
		$('.acc_trigger').click(function(){
			if( $(this).next().is(':hidden') ) {
				$('.acc_trigger').removeClass('active').next().slideUp();
				$(this).toggleClass('active').next().slideDown();
			}
			return false;
		});
								
		//Popups de la page Dispositif Online 
		$('.poplight').click(function() {


			var popID = $(this).attr('rel');
			var popURL = $(this).attr('href');
	
			//Pull Query & Variables from href URL
			var query= popURL.split('?');
			var dim= query[1].split('&');
			var popWidth = dim[0].split('=')[1];
	
			//Appel de la popup et du bouton, swap des z-index pour faire passer la popup et le fade au dessus de tout le monde
			$('#header').css("z-index","52");
			$('#content').css("z-index","142");			
			$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><div class="btn_closevideo" title="Fermer"></div></a>');
	
			//Definir des margins
			var popMargTop = ($('#' + popID).height() + 80) / 2;
			var popMargLeft = ($('#' + popID).width() + 80) / 2;	
	
			//Appliquer les margin à la popup
			$('#' + popID).css({ 
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});
	
			//Appel du Fade
			$('.text').append('<div id="fade"></div>'); //Ajout du Fade au bon niveau
			$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
	
			return false;
		});
		
		//Popups de la Home video
		$('a.poplightvideo[href^=#]').click(function() {
			
			
			
	
			var popID = $(this).attr('rel');
			var popURL = $(this).attr('href');
	
			//Pull Query & Variables from href URL
			var query= popURL.split('?');
			var dim= query[1].split('&');
			var popWidth = dim[0].split('=')[1];
	
			//Appel de la popup et du bouton, swap des z-index pour faire passer la popup et le fade au dessus de tout le monde
			$('#header').css("z-index","52");
			$('#content').css("z-index","142");			
			$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><div class="btn_closevideo" title="Fermer"></div></a>');
	
			//Definir des margins
			var popMargTop = ($('#' + popID).height() + 80) / 2;
			var popMargLeft = ($('#' + popID).width() + 80) / 2;	
	
			//Appliquer les margin à la popup
			$('#' + popID).css({ 
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			});
	
			//Appel du Fade
			$('#hp_container').append('<div id="fade"></div>'); //Ajout du Fade au bon niveau
			$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
	
			return false;
		});
	
		//Fermeture des popups et du Fade
		$('a.close, #fade').live('click', function() {
			$('#header').css("z-index","142");
			$('#content').css("z-index","52");
			$('#fade , .popup_block, .popup_blockvideo').fadeOut(function() {
			$('#fade, a.close').remove();  
		}); //fade them both out		
			return false;
		});
		
		
		
	
}); // document
