/*
  Formalize - version 1.1

  Note: This file depends on the jQuery library.
*/

// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
var FORMALIZE = (function($, window, document, undefined) {
  // Private constants.
  var PLACEHOLDER_SUPPORTED = 'placeholder' in document.createElement('input');
  var AUTOFOCUS_SUPPORTED = 'autofocus' in document.createElement('input');
  var IE6 = !!($.browser.msie && parseInt($.browser.version, 10) === 6);
  var IE7 = !!($.browser.msie && parseInt($.browser.version, 10) === 7);

  // Expose innards of FORMALIZE.
  return {
    // FORMALIZE.go
    go: function() {
      for (var i in FORMALIZE.init) {
        FORMALIZE.init[i]();
      }
    },
    // FORMALIZE.init
    init: {
      // FORMALIZE.init.ie6_skin_inputs
      ie6_skin_inputs: function() {
        // Test for Internet Explorer 6.
        if (!IE6 || !$('input, select, textarea').length) {
          // Exit if the browser is not IE6,
          // or if no form elements exist.
          return;
        }

        // For <input type="submit" />, etc.
        var button_regex = /button|submit|reset/;

        // For <input type="text" />, etc.
        var type_regex = /date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;

        $('input').each(function() {
          var el = $(this);

          // Is it a button?
          if (this.getAttribute('type').match(button_regex)) {
            el.addClass('ie6-button');

            /* Is it disabled? */
            if (this.disabled) {
              el.addClass('ie6-button-disabled');
            }
          }
          // Or is it a textual input?
          else if (this.getAttribute('type').match(type_regex)) {
            el.addClass('ie6-input');

            /* Is it disabled? */
            if (this.disabled) {
              el.addClass('ie6-input-disabled');
            }
          }
        });

        $('textarea, select').each(function() {
          /* Is it disabled? */
          if (this.disabled) {
            $(this).addClass('ie6-input-disabled');
          }
        });
      },
      // FORMALIZE.init.autofocus
      autofocus: function() {
        if (AUTOFOCUS_SUPPORTED || !$(':input[autofocus]').length) {
          return;
        }

        $(':input[autofocus]:visible:first').focus();
      },
      // FORMALIZE.init.placeholder
      placeholder: function() {
        if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) {
          // Exit if placeholder is supported natively,
          // or if page does not have any placeholder.
          return;
        }

        FORMALIZE.misc.add_placeholder();

        $(':input[placeholder]').each(function() {
          var el = $(this);
          var text = el.attr('placeholder');

          el.focus(function() {
            if (el.val() === text) {
              el.val('').removeClass('placeholder-text');
            }
          }).blur(function() {
            FORMALIZE.misc.add_placeholder();
          });

          // Prevent <form> from accidentally
          // submitting the placeholder text.
          el.closest('form').submit(function() {
            if (el.val() === text) {
              el.val('').removeClass('placeholder-text');
            }
          }).bind('reset', function() {
            setTimeout(FORMALIZE.misc.add_placeholder, 50);
          });
        });
      }
    },
    // FORMALIZE.misc
    misc: {
      // FORMALIZE.misc.add_placeholder
      add_placeholder: function() {
        if (PLACEHOLDER_SUPPORTED || !$(':input[placeholder]').length) {
          // Exit if placeholder is supported natively,
          // or if page does not have any placeholder.
          return;
        }

        $(':input[placeholder]').each(function() {
          var el = $(this);
          var text = el.attr('placeholder');

          if (!el.val() || el.val() === text) {
            el.val(text).addClass('placeholder-text');
          }
        });
      }
    }
  };
// Alias jQuery, window, document.
})(jQuery, this, this.document);

// Automatically calls all functions in FORMALIZE.init
jQuery(document).ready(function() {
  FORMALIZE.go();
});;
/**
 * @todo
 */

Drupal.omega = Drupal.omega || {};

(function($) {
  /**
   * @todo
   */
  var current;
  var previous;
  
  /**
   * @todo
   */
  var setCurrentLayout = function (index) {
    index = parseInt(index);
    previous = current;
    current = Drupal.settings.omega.layouts.order.hasOwnProperty(index) ? Drupal.settings.omega.layouts.order[index] : 'mobile';

    if (previous != current) {      
      $('body').removeClass('responsive-layout-' + previous).addClass('responsive-layout-' + current);      
      $.event.trigger('responsivelayout', {from: previous, to: current});
    }
  };
  
  /**
   * @todo
   */
  Drupal.omega.getCurrentLayout = function () {
    return current;
  };
  
  /**
   * @todo
   */
  Drupal.omega.getPreviousLayout = function () {
    return previous;
  };
  
  /**
   * @todo
   */
  Drupal.omega.crappyBrowser = function () {
    return $.browser.msie && parseInt($.browser.version, 10) < 9;
  };
  
  /**
   * @todo
   */
  Drupal.omega.checkLayout = function (layout) {
    if (Drupal.settings.omega.layouts.queries.hasOwnProperty(layout) && Drupal.settings.omega.layouts.queries[layout]) {
      var output = Drupal.omega.checkQuery(Drupal.settings.omega.layouts.queries[layout]);
      
      if (!output && layout == Drupal.settings.omega.layouts.primary) {
        var dummy = $('<div id="omega-check-query"></div>').prependTo('body');       

        dummy.append('<style media="all">#omega-check-query { position: relative; z-index: -1; }</style>');
        dummy.append('<!--[if (lt IE 9)&(!IEMobile)]><style media="all">#omega-check-query { z-index: 100; }</style><![endif]-->');
        
        output = parseInt(dummy.css('z-index')) == 100;

        dummy.remove();
      }
      
      return output;
    }

    return false;
  };
  
  /**
   * @todo
   */
  Drupal.omega.checkQuery = function (query) {
    var dummy = $('<div id="omega-check-query"></div>').prependTo('body');       
    
    dummy.append('<style media="all">#omega-check-query { position: relative; z-index: -1; }</style>');
    dummy.append('<style media="' + query + '">#omega-check-query { z-index: 100; }</style>');

    var output = parseInt(dummy.css('z-index')) == 100;
    
    dummy.remove();

    return output;
  };
  
  /**
   * @todo
   */
  Drupal.behaviors.omegaMediaQueries = {
    attach: function (context) {
      $('body', context).once('omega-mediaqueries', function () {
        var primary = $.inArray(Drupal.settings.omega.layouts.primary, Drupal.settings.omega.layouts.order);
        var dummy = $('<div id="omega-media-query-dummy"></div>').prependTo('body');

        dummy.append('<style media="all">#omega-media-query-dummy { position: relative; z-index: -1; }</style>');
        dummy.append('<!--[if (lt IE 9)&(!IEMobile)]><style media="all">#omega-media-query-dummy { z-index: ' + primary + '; }</style><![endif]-->');

        for (var i in Drupal.settings.omega.layouts.order) {
          dummy.append('<style media="' + Drupal.settings.omega.layouts.queries[Drupal.settings.omega.layouts.order[i]] + '">#omega-media-query-dummy { z-index: ' + i + '; }</style>');
        }

        $(window).bind('resize.omegamediaqueries', function () {
          setCurrentLayout(dummy.css('z-index'));
        }).load(function () {
          $(this).trigger('resize.omegamediaqueries');
        });
      });
    }
  };
})(jQuery);;
var isIE6=navigator.userAgent.toLowerCase().indexOf("msie 6")!=-1;jQuery.fn.megamenu=function(a){a=jQuery.extend({activate_action:"mouseover",deactivate_action:"mouseleave",show_method:"slideDown",hide_method:"slideUp",justify:"left",enable_js_shadow:true,shadow_size:3,mm_timeout:250},a);var b=this;if(a.activate_action=="click")a.mm_timeout=0;b.children("li").each(function(){jQuery(this).addClass("mm-item");jQuery(".mm-item").css({"float":a.justify});jQuery(this).find("div:first").addClass("mm-item-content");jQuery(this).find("a:first").addClass("mm-item-link");var c=jQuery(this).find(".mm-item-content");var d=jQuery(this).find(".mm-item-link");c.hide();jQuery(document).bind("click",function(){jQuery(".mm-item-content").hide();jQuery(".mm-item-link").removeClass("mm-item-link-hover")});jQuery(this).bind("click",function(a){a.stopPropagation()});c.wrapInner('<div class="mm-content-base"></div>');if(a.enable_js_shadow==true){c.append('<div class="mm-js-shadow"></div>')}var e=0;jQuery(this).bind(a.activate_action,function(f){f.stopPropagation();var g=jQuery(this).find("a.mm-item-link");var h=jQuery(this).find("div.mm-item-content");clearTimeout(e);e=setTimeout(function(){g.addClass("mm-item-link-hover");h.css({top:d.position().top+d.outerHeight()+1+"px",left:d.position().left-5+"px"});if(a.justify=="left"){var e=b.position().left+b.outerWidth();var f=d.position().left+c.outerWidth()-5;if(f>=e){h.css({left:d.position().left-(f-e)-2+"px"})}}else if(a.justify=="right"){var i=b.offset().left;var j=d.offset().left-h.outerWidth()+d.outerWidth()+5;if(j<=i){h.css({left:i+2+"px"})}else{h.css({left:j+"px"})}}if(a.enable_js_shadow==true){h.find(".mm-js-shadow").height(h.height());h.find(".mm-js-shadow").width(h.width());h.find(".mm-js-shadow").css({top:a.shadow_size+(isIE6?2:0)+"px",left:a.shadow_size+(isIE6?2:0)+"px",opacity:.5})}switch(a.show_method){case"simple":h.show();break;case"slideDown":h.height("auto");h.slideDown("fast");break;case"fadeIn":h.fadeTo("fast",1);break;default:h.each(a.show_method);break}},a.mm_timeout)});jQuery(this).bind(a.deactivate_action,function(b){b.stopPropagation();clearTimeout(e);var c=jQuery(this).find("a.mm-item-link");var d=jQuery(this).find("div.mm-item-content");switch(a.hide_method){case"simple":d.hide();c.removeClass("mm-item-link-hover");break;case"slideUp":d.slideUp("fast",function(){c.removeClass("mm-item-link-hover")});break;case"fadeOut":d.fadeOut("fast",function(){c.removeClass("mm-item-link-hover")});break;default:d.each(a.hide_method);c.removeClass("mm-item-link-hover");break}if(d.length<1)c.removeClass("mm-item-link-hover")})});this.find(">li:last").after('<li class="clear-fix"></li>');this.show()};
/*
 * 	Easy Tooltip 1.0 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
(function($) {

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {  				
			var title = $(this).attr("title");				
			$(this).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("." + options.useElement).html() : content;
				$(this).attr("title","");									  				
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'><p>"+ content +"</p></div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(e){
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);
;
/* Lance le script megamenu */
jQuery(document).ready(function() {
	
  jQuery(".megamenu").megamenu({
    'justify' : 'left',
    'enable_js_shadow' : false
  });
	
	//Gestion du bkg du sous-menu du megamenu	
	jQuery('#region-menu .megamenu .hm-item-block').find('.hm-block').parents('.hm-item-block').addClass('hm-bkg2');
	
	//Gestion des liens du Megamenu
	jQuery('#region-menu .megamenu .hm-item').find('.hm-link').bind('click', function(e) {
		if(jQuery(this).next().is('.hm-item-block')) {
			e.preventDefault();
		}
	});

  jQuery('#views-exposed .toggle-link').find('a').bind('click', function(e) {
    jQuery(this).parent().next().slideToggle();
    jQuery(this).parent().find('a').toggleClass('hide');
    e.preventDefault();
  });

  //Gestion de l'affichage de la description des campings (> minisite header description)
  jQuery('#camping-preface .camping-desc #desc-texte').find('.link-more').bind('click', function(e) {
	jQuery(this).parents('#desc-texte').find('.long-texte').fadeIn('');
	 e.preventDefault();
  });

  jQuery('#camping-preface .camping-desc .long-texte').find('.link-close').bind('click', function(e) {
	jQuery(this).parents('.long-texte').fadeOut('');
		e.preventDefault();
  });
  
  jQuery(document).delegate("a.colorbox_inline", "click", function()
  {
    var thisHref = jQuery(this).attr("href");
    jQuery.colorbox({href:thisHref, inline : true, width:"50%", current:""});
  });
  
  //Gestion des onglets (pages type hebergement)  
  jQuery('#nav-onglet-hbgt').find('a').bind('click', function(e) {
  	if(jQuery(this).is('.onglet')) {
  		var ancreOnglet = jQuery(this).attr('href');
  		jQuery(this).parents('#nav-onglet-hbgt').find('.active').removeClass('active');
  		jQuery(this).parent().addClass('active');
  		jQuery(this).parents('#region-content').find('.hbgt-block-active').removeClass('hbgt-block-active');
  		jQuery(this).parents('#region-content').find(ancreOnglet).addClass('hbgt-block-active');
  		
  		e.preventDefault();
  	}
  });
  
  /**
   * Gestion de l'état courant d'un hébergement ds la liste des hébergements d'un minisite
   */
  jQuery.fn.handleCurrentHbgt = function() {
    element = this;
    first = jQuery(element).first();
    //le premier élément est l'élément courant par défaut
    jQuery('a:first', first).addClass('current');
    //au clic, l'élement cliqué devient l'élement courant
    jQuery(element).find('a').click(function(e){
        if(jQuery(this).hasClass('current') == false) {
          jQuery('a', element).removeClass('current');
          jQuery(this).addClass('current');
        }
        e.preventDefault();
    });
  }
  
  //Gestion des tooltips
   jQuery.fn.tooltip = function() {
  	  	
  	//tooltip pour l'input date d'arrivee formulaire de recherche  	
	  jQuery('.form-type-date-popup input').easyTooltip({
			tooltipId: "tooltip-hm",
			useElement: "description:last"
		});
		
		//tooltip pour les pictos page de resultats de recherche campings		
		jQuery('.picto-camp .item-list ul li, #camping-presentation-bloc2 .item-list ul li').find('a').bind('click', function(e) {
			e.preventDefault();
		});		
		jQuery('.picto-camp .item-list ul li a').easyTooltip({
			tooltipId: "tooltip-hm"
		});
		
		jQuery('#camping-presentation-bloc2 .item-list li').find('a').easyTooltip({
			tooltipId: "tooltip-hm"
		});
		
		jQuery('#camping-equipement .picto').find('img').easyTooltip({
      tooltipId: "tooltip-hm"
    });
		
	};
	jQuery(document).tooltip();
	
	//Gestion de l'ouverture de facebook + blog dans une nouvelle fenêtre
	jQuery('#block-menu-menu-suivez-nous .menu').find('a[href^="http://"]').click(function(){
		if((jQuery(this).attr("class"))=='internal'){
      return true;
    }
    window.open(this.href);
    return false;
	});
	
  /**
   * Gestion de l'ouverture d'un lien dans une nouvelle fenêtre.
   */
  jQuery.fn.targetBlank = function() {
    element = this;
    jQuery(element).find('a[href^="http://"]').click(function(){
      if((jQuery(this).attr("class"))=='internal'){
        return true;
      }
      window.open(this.href);
      return false;
    });
  }
  
  /**
   * Ajout aux favoris
   */
    if (!jQuery.browser.mozilla && !jQuery.browser.msie && !jQuery.browser.opera){
        jQuery("li").find('a#bookmark').parent().hide();
    }//on enlève l'icône de bookmark pour le cas google chrome*
    jQuery("a#bookmark").click(function(){
      var bookmarkUrl = this.href;
      var bookmarkTitle = document.title;
      
      
      if (jQuery.browser.mozilla) // For Mozilla Firefox Bookmark
      {
        window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
      }
      else if(jQuery.browser.msie) // For IE Favorite
      {
        window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
      }
      else if(jQuery.browser.opera) // For Opera Browsers
      {
        jQuery(this).attr("href",bookmarkUrl);
        jQuery(this).attr("title",bookmarkTitle);
        jQuery(this).attr("rel","sidebar");
        jQuery(this).click();
      }
      return false;
    });
    
  
});


/**
 * Gestion de l'onglet hbgt minisite
 */
function handleOngletHbgt(){  

	   // Gestion des onglets (minisite page hebergement)
	  jQuery('#tab-onglet-heb ul li a').live('click', function(e) {
			var blocLien = jQuery(this).attr('class');
			
			if(jQuery(this).is('.selected') == false) {
		  	jQuery(this).parents('#tab-onglet-heb').find('.selected').removeClass('selected');
		  	jQuery(this).addClass('selected');
		  	jQuery(this).parents('#hebergement-bloc3').find('.blocActive').removeClass('blocActive');
		  	jQuery(this).parents('#hebergement-bloc3').find('#'+blocLien).addClass('blocActive');
	  	}
	  	e.preventDefault();
	  });
}

/* Gestion du carousel du minisite (header)
 * ------------------------------------
 */

function imageViewer() {
		
	jQuery('#carouselThumb').carouselsimple({ 
	  manual: true,
	  speed: 2000,
	  itemVisibles: 5
	});
	
	jQuery('#viewer').find('li:nth-child(1)').addClass('current').show();
		
	jQuery('#carouselThumb .masque li, #visio-camping .pager-camping-btn-video, #visio-camping .pager-camping-btn-360, #visio-camping .pager-camping-btn-plan3d, #visio-camping .pager-camping-btn-plan2d').delegate('a', 'click', function(e) {
		var linkItem = jQuery(this).attr('href');
		var classItem = jQuery(this).parent().attr('class');
		var viewer = jQuery('#viewer');
		var titleImg = jQuery(this).find('img').attr('alt');
		
		if(jQuery(this).parent().is('.actif') == false) {
			jQuery(this).parents('#carouselThumb').find('.actif').removeClass('actif');
			jQuery('#carouselThumb .'+classItem).addClass('actif');
			if(viewer.find('li.'+classItem+' a').children().is('.replace')) {
				var currentImg = viewer.find('li.'+classItem+' a');
				currentImg.find('.replace').remove().end()
									.prepend('<img src="' + linkItem + '" alt="'+titleImg+'" width="388" height="239" />');
			}
			viewer.find('.current').addClass('hide').removeClass('current').end()
				 		.find('.'+classItem).addClass('current').fadeIn('', function() {
							viewer.find('.hide').removeClass('hide').hide();
			});
		}
		e.preventDefault();
	});
	
	var $tab_photo = new Array();
	
	if(Drupal.settings.homair_hbgt) {
    $tab_photo = Drupal.settings.homair_hbgt.photo_hbgt;
	}
	else if(Drupal.settings.homair_minisite) {
    $tab_photo = Drupal.settings.homair_minisite.photo_visio1;
	}
	
  //Colorbox
 	jQuery("#viewer a").each(function() {
   var $link = jQuery(this);
   var $img = $link.find("img");
   var $title = $img.attr("alt");
   $link.attr("title", $title);
   $img.attr("title", "");
   $link.colorbox({rel : "groupe", current:""});
  });	
}

/**
 * Redimensionnement de l'iframe dont l'id est passé, si meme domaine.
 */
function adjustIframe(idIframe){
	try{
		//jQuery("#"+idIframe).height(jQuery("#"+idIframe).contents().find("html").height() + 20 );
		jQuery("#"+idIframe).height(jQuery("#"+idIframe).contents().height() + 20 );
	}catch(e){
	}
}

//Gestion de l'affichage des photos du carousel minisite (onglet hebergement) (carousel + colorbox)
jQuery(function($) {
	
	function boxMinisite() {
		jQuery("#image-visio-hebergement .lienBig").each(function() {
			var $link = jQuery(this);
			var $img = $link.find("img");
			var $title = $img.attr("alt");
			$link.attr("title", $title);
			$img.attr("title", "");
			$link.colorbox({rel : "groupe-minisite", current:""});
		});
	}

	jQuery.fn.constructItem = function() {	
		boxMinisite();
		
		jQuery('#image-visio-hebergement .bloc a, #pager-visio-hebergement .btn-visio a').bind('click', function() {
			boxMinisite();
	  	jQuery('#image-visio-hebergement .replace').each( function() {	  		
	  		var link = jQuery(this).attr('href');	  		
	  		jQuery(this).removeClass('replace').prepend('<img src="'+link+'" width="304" height="239" alt="" />')
	  	});
	  });
	  
	  jQuery('#pager-visio-hebergement .btn-visio a').bind('click', function(e) {
			var lienBlock = jQuery(this).attr('class');
			jQuery('#image-visio-hebergement').find('.selected').removeClass('selected').end()
																				.find('#'+lienBlock).addClass('selected');
	  	e.preventDefault();
	  });
	  
	}
});


;

