function autoWidth(){
	docWidth 		= $(window).width();
	docHeight		= $(window).height();
	sidebarWidth	= $('#sidebar').width() + 61;
	logoHeight		= $('#logo').height() +20;
	$('#container_home').width(docWidth-sidebarWidth);
	$('#sidebar').height(docHeight-logoHeight);
}

function autoIsotope(){
	$('#iso_container').show();
	$('#iso_container').isotope({
	  // options
	    itemSelector : '.iso_item',
	    layoutMode : 'masonry',
	    getSortData : {
	    	rand1 : function ( $elem ) {
	    	  return parseInt($elem.find('.rand1').text());
	    	},
	    	rand2 : function ( $elem ) {
	    	  return parseInt($elem.find('.rand2').text());
	    	},
	    	rand3 : function ( $elem ) {
	    	  return parseInt($elem.find('.rand3').text());
	    	},
	    	rand4 : function ( $elem ) {
	    	  return parseInt($elem.find('.rand4').text());
	    	}																		
	    }
	});
}

function setCookie ( name, value, expires, path, domain, secure) {
	szCookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = szCookie;
}

function getCookie (name) {
	if ( document.cookie) {
		index_cookie = document.cookie.indexOf(name);
		if ( index_cookie != -1) {
			nDeb = (document.cookie.indexOf( "=", index_cookie) + 1);
			nFin = document.cookie.indexOf( ";", index_cookie);
			if (nFin == -1) {nFin = document.cookie.length;}
			return unescape(document.cookie.substring(nDeb, nFin));
		}
	}
	return null;
}

$(document).ready(function() {
    
	/* Galerie photos */
	$('.ngg-gallery-thumbnail').each(function(index){
		if((index+1)%6 == 0){
			$(this).css("margin-right","0px");
		};
	})

	/* Fil d'ariane */
	$('.breadcrumb a').each(function(){
		if($(this).attr('title') == "Menu 1" || $(this).attr('title') == "Menu 2"){
			$(this).next().remove();
			$(this).remove();
		}
	})
	
	/* Height #container, #container_page, #container_blog*/
	docHeight		= $(window).height();
	logoHeight		= $('#logo').height() + 70;
	$('#container_blog').css("min-height",docHeight-logoHeight);	
	$('#container_page').css("min-height",docHeight-logoHeight);	
	$('#container').css("min-height",docHeight-logoHeight);

	/* Width homepage */
	if($('#container_home').get(0) != undefined){
		autoWidth();	
		$(window).resize(function() {
			autoWidth();
			autoIsotope();			
		});
	}
	
	/* Homepage */
	var rand = 1;
	setTimeout(function(){
		autoIsotope();	
	}, 500);
	
	$('#sort-by a').click(function(){
		var sortName = $(this).attr('href').slice(1);
		if(sortName == 'random'){
		     $('#iso_container').isotope({ sortBy : 'rand'+rand+'' });
		     if(rand == 4){
		     	rand = 1;
		     }else{
		     	rand++;
		     }					 
		}else{
		   $('#iso_container').isotope({ filter: '.'+sortName+'' });
		}
	});
	
	$(".iso_item").hover(
	  function () {
	    $(this).addClass("hover");
	  },
	  function () {
	    $(this).removeClass("hover");
	  }
	);
	
	$('.cbox_image').colorbox({opacity: 1});
	$('.cbox_galery').colorbox({opacity: 1});
	$('.cbox_video').colorbox({iframe:true, innerWidth:425, innerHeight:344, opacity: 1});
	$("a[rel='gallery_images']").colorbox({opacity: 1});
	$("#link_reservation").colorbox({width:"50%", height:"85%", iframe:true, opacity: 1});
	
	$('.cbox_galery_start').click(function(e){
	  galID = $(this).attr('id');
	  var $gallery = $('a[rel='+galID+']').colorbox();
	  e.preventDefault();
	  $gallery.eq(0).click();
	});
	 
	/* Colorbox avec iframe réservation */
	$("#link_reservation").colorbox({width:"50%", height:"85%", iframe:true, opacity: 1});
	
	$("#breadcrumb_blog").children("a").eq(1).remove();
	$("#breadcrumb_blog").children("span").eq(1).remove();

	/* Innerfade programme */
	$('#last_3_dates').innerfade({ speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '415px'});
	
	/* Innerfade single programme */
	$('#fade_img_date').innerfade({ speed: 'slow', timeout: 3000, type: 'sequence', containerheight: '439px'});

});	
