// MOSNE FUNCTIONS
$(document).ready(function(){
   
   if ($("body").hasClass("home")){
   
        var status = $.cookie("status");
        
        if (status){}else{
        $("#splash").show();
        $("#splash").click(function(){
            $("#splash").fadeOut(1200);
        });
        $.cookie("status",true);
        }
        
    
    }
    
    
    if ($("body").hasClass("category-presse")){
    
    $("a[rel^='gallery']").fancybox({
				'transitionIn': 'fade',
				'transitionOut': 'fade',
				'padding':0,
                'margin':50,
				'titleShow': true
			});
			
    
    $("a.opengallery").click(function(){
	   
	   $(this).parent().parent().find(".gallery a:eq(0)").trigger("click");
	   
	});
	
    $("a.opengallerytwo").click(function(){
	   
	   $(this).parent().parent().find(".gallery a:eq(1)").trigger("click");
	   
	});
	
	}
    
    var ea = 'easeInOutQuad';
   
    
   var pane = $('.scroll-pane');
		var jsets = {showArrows: false, 
		             autoReinitialise: true,
			         verticalDragMinHeight: 40,
			         verticalDragMaxHeight: 40
		             };
		             
   pane.jScrollPane(jsets);
  
  
  $('a.embedvideo').live("click",function(e){
    
    e.preventDefault();
       
       $(this).hide();
       url = $(this).attr("href");
       v_id = url.match("[\?&]v=([^&#]*)")[1];
       i_src = "http://www.youtube.com/embed/"+v_id+"?controls=0&showinfo=0&autoplay=1&fs=1&rel=0";
       whr = $(this).parent();
       ih = whr.find("img").height();
       iw = whr.find("img").width();
       whr.empty().append('<iframe width="'+iw+'" height="'+ih+'" src="'+i_src+'"></iframe>');
    
    
  });  
    
  $("#bd").bind("initscripts",function(e, aaa){
  
     $(aaa).find('.gallery').fadeIn().each(function(){
        
        var gal = $(this);
        var chi = $(".pics",gal);
        var bnext = $(".pics img",gal);
        var next = $(".next",gal);
        var prev = $(".prev",gal);
        var close = $(".close",gal)
        
        if ($(chi).find("img").size() <= 1){
            $(next).hide();
            $(prev).hide();
            $(chi).find(".slide").css({"cursor":"default"})
        }
       
       
        chi.cycle({
            easing: ea,
            fx: 'scrollHorz',
            timeout: 0,
            next : next,
            prev : prev,
            speed: 550,
            before: function(currSlideElement, nextSlideElement, options, forwardFlag){
            
                ttl = $(nextSlideElement).find("img").attr("alt");
                $(".dida",gal.parent()).html(ttl);
            }
        }); 
        
        bnext.click(function(){
            chi.cycle("next");
        });
        
        close.click(function(e){
            e.preventDefault();
            log("close");
            gal.parent().parent().animate({"height":0},function(){
                $(this).empty();
                $.scrollTo($(this).parent(),600,{easing: ea, offset:-5});
            });
            gal.parent().parent().parent().find(".current-menu-item").removeClass("current-menu-item");
        });
        
	
	   }); 
	
        
    }).trigger("initscripts","#bd");


/* catalogue hover fx */
    
    $(".catalogo .thumbs a").hover(function () {
        $(this).addClass("hover");
        $(this).parent().parent().parent().parent().find(".cathd a").addClass("hover");
    }, function () {
        $('.catalogo .hover').removeClass("hover");
    });
    
    $(".catalogo .cathd a").hover(function () {
       $(this).addClass("hover");
       $(this).parent().parent().parent().find(".thumbs a:eq(0)").addClass("hover");
    }, function () {
       $('.catalogo .hover').removeClass("hover");
    }); 






//category-a-propos

if($("body").hasClass("category-a-propos")){

$(".category-a-propos article h1 a").click(function(e){

    e.preventDefault();
    log("ok");
    txt = $(this).parent().parent().find(".bodytext");
    
    if ($(txt).is(":hidden")) {
        $(this).addClass("active");
        $(txt).slideDown();
    } else {
        $(txt).slideUp();
        $(this).removeClass("active");
    }

});


setTimeout(function(){
$(".category-a-propos article h1 a:eq(0)").trigger("click");
},900);
}
$("a.ajax").click(function(e){
    e.preventDefault();
      
      var who = this;
   	  
   
      if ($("body").hasClass("category-lab")){
   	  var scrlltgt = 0;
   	  }else{
   	  var scrlltgt = who;
   	  }
   	  
   	  var link = $(who).attr("href");
   	  
   	  window.location.hash = link;
   	  
   	  
   	  $.scrollTo(scrlltgt,600,{easing: ea, offset:-5, onAfter: function(){ 
   	  
   	  
   	  if ($("body").hasClass("category-lab")){
   	  var catalogo = $('#bd .labo:eq(0)');
   	  var out = $('#bd .output:eq(0)');
   	  }else{
   	  var catalogo = $(who).parent().parent().parent().parent();
   	  var out = $(catalogo).find(".output");
   	  var collection = $("body").hasClass("category");
   	  }
   	   
   	  
   	  $(catalogo).find(".current-menu-item").removeClass("current-menu-item");
   	  
        $(out).css({"display":"block"}).animate({"height":0},function(){$(this).empty()}).delay(500).animate({"height":546}).addClass("loading active");
        $(who).parent().addClass("current-menu-item");
         
        $(out).load(link+" #contents",{"ajax":true,"mm":collection}, function() {
  	  	
  	  	$(out).removeClass("loading");
  	  	 
  	  	
  	  	
  	  	$("#bd").trigger("initscripts",$(out).find("#contents"));
  	  	$(out).find(".scroll-pane").jScrollPane(jsets);
  	  	
  	  	   setTimeout(function(){    
           $(out).animate({"height":771},500);
  		},700);
  		});
 	
 	}}); //end of scroll
    
    });
    
    $(".catalogo .cathd a").click(function(e){
    
        e.preventDefault();
        $(this).parent().parent().parent().find(".thumbs a.ajax:eq(0)").trigger("click");
    });
    
    
    $('#bspacer').css({"height":$(window).height() });
    
    
   if( window.location.hash){
    var x = window.location.hash; 
    if (x.match("http")) {
    //log("link");
            page = window.location.hash.split("#")[1];
			if ($('a[href="'+page+'"]').length) {
				setTimeout(function(){
					$('a[href="'+page+'"]').eq(0).trigger("click");
				},250);
			}
    }else{
    //log("anchor");  
    $.scrollTo(0);
    $.scrollTo($(location.hash),1000,{easing: ea, offset:-5});
    
    }
  }else{
    
    $("a.current-cat:eq(0)").trigger("click");    
    $(".current-menu-item a").trigger("click");

  }
  
   $('#menu a[href^="'+$("#guesscat").html()+'"]').parent().addClass("current-menu-item");
  
  //map
  if($("body").hasClass("page-id-5")){
   
    var myhue= "#D1CCC3";
    var stylez=[{featureType:"water",elementType:"all",stylers:[{invert_lightness:true},{lightness:26},{saturation:-90},{hue:myhue}]},{featureType:"road",elementType:"all",stylers:[{hue:myhue},{visibility:"on"},{saturation:-81},{lightness:12}]},{featureType:"administrative",elementType:"all",stylers:[{lightness:28},{hue:myhue},{saturation:-73}]},{featureType:"landscape",elementType:"all",stylers:[{visibility:"on"},{saturation:-87}]},{featureType:"poi",elementType:"all",stylers:[{saturation:-77},{hue:myhue}]},{featureType:"road.highway",elementType:"all",stylers:[{visibility:"simplified"}]},{featureType:"road.local",elementType:"all",stylers:[{hue:myhue},{saturation:10},{lightness:50}]},{featureType:"transit",elementType:"labels",stylers:[{visibility:"on"},{hue:myhue},{saturation:-87},{lightness:32}]}];
    
   var mybg_color="#D1CCC3";
   var cluster_styles=[{url:'/wp-content/themes/avenel/images/m4_lt.png',height:40,width:40,opt_textSize:17,opt_anchor:[6,0],opt_textColor:'#fff'},{url:'/wp-content/themes/avenel/images/m4_lt.png',height:40,width:40,opt_textSize:17,opt_anchor:[6,0],opt_textColor:'#fff'},{url:'/wp-content/themes/avenel/images/m4_lt.png',height:40,width:40,opt_textSize:17,opt_anchor:[6,0],opt_textColor:'#fff'},{url:'/wp-content/themes/avenel/images/m4_lt.png',height:40,width:40,opt_textSize:17,opt_anchor:[6,0],opt_textColor:'#fff'}];
   var marker_icon='/wp-content/themes/avenel/images/m_ilmf.png';
   var marker_icon_poi='/wp-content/themes/avenel/images/m_ilmf.png';
   var mapstyle_id='minimal';var mapOptions={mapTypeControlOptions:{mapTypeIds:[google.maps.MapTypeId.ROADMAP,mapstyle_id]},panControl:false,zoomControl:true,zoomControlOptions:{style:google.maps.ZoomControlStyle.SMALL,position:google.maps.ControlPosition.TOP_LEFT},mapTypeControl:false,scaleControl:false,streetViewControl:false,zoom:6,disableDoubleClickZoom:true,backgroundColor:mybg_color};
   
   var s_infobox_g = {
			 content: "",
			 disableAutoPan: false,
			 maxWidth: 0,
			 pixelOffset: new google.maps.Size(-110, 5),
			 zIndex: null,
			 boxStyle: { 
			 background: "url('/wp-content/themes/avenel/images/infobox_top.png') center top no-repeat",
			 color:'#333',
			 padding: '0',
			 width: "220px"
			 },
			  closeBoxMargin: "16px 4px",
			 closeBoxURL: "/wp-content/themes/avenel/images/infobox_close.png",
		     infoBoxClearance: new google.maps.Size(1, 1),
			 isHidden: false,
			 pane: "floatPane",
			 enableEventPropagation: false
		};
		
  $("#map").mosne_map({
    mode:'address',
    elements: '#bd .location',
    infowindows: false,
    infobox: true,
    infobox_s:s_infobox_g,
    trigger: 'open_scroll',
    timeout: 100,
    clat: 48.856667,
    clng: 2.350987,
    clickedzoom: 17,
    mapstyle: stylez,
    mapstyle_name: mapstyle_id,
    map_opt: mapOptions,
    cluster_styles: {
        zoomOnClick: true,
        maxZoom: 13,
        gridSize: 30,
        styles: cluster_styles
    },
    marker_icon: marker_icon,
    after: function () {
        setTimeout(function(){
            $(".maplink").trigger("click");
        },800);
    }

}); 

    
   
  
  }
    
   
});//scope 






