//****************************************************************
// Affichage des sous-menus 
//****************************************************************

sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//****************************************************************
// Affichage des POPUP 
//****************************************************************

function funcPopup(varUrl, varWidth, varHeight, varResize) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar=no, menubar=no, scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
}

//****************************************************************
// Fonction d'import des animations Flash 
//****************************************************************

function RunFlash(swf, hauteur, largeur, nom) {
	document.write("<object width=\""+largeur+"\" height=\""+hauteur+"\" id=\""+nom+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n");
	document.write("<param name=\"quality\" value=\"high\">\n");
	document.write("<param name=\"wmode\" value=\"transparent\">\n");
	document.write("<param name=\"movie\" value=\""+swf+"\">\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" width=\""+largeur+"\" height=\""+hauteur+"\" name=\""+nom+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n");
	document.write("</object>\n");
}



//****************************************************************
// Gestion de la hauteur de la page 
//****************************************************************

/*function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setHeight() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('page').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'absolute';
			}
			else {
				footerElement.style.position = 'relative';
			}
		}
	}
}
window.onload = function() {
	setHeight();
}
window.onresize = function() {
	setHeight();
}*/



//****************************************************************
// Affichage des libellés de la boîte à outils 
//****************************************************************

sfHover = function() {
        if (document.getElementById('tools'))
                {
                var sfEls = document.getElementById('tools').getElementsByTagName("LI");
                for (var i=0; i<sfEls.length; i++) {
                        sfEls[i].onmouseover=function() {
                                this.className+=" sfhover";
                        }
                        sfEls[i].onmouseout=function() {
                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                        }
                }
                }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//****************************************************************
// Affichage Mask photos 
//****************************************************************
// Thumb Diaporama

(function($) {
	$.fn.thumbDiapoCreate = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/diapo-mask.png" alt="" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbDiapo').each(function(){$(this).thumbDiapoCreate();});
});


//****************************************************************
// Affichage Diaporama photos 
//****************************************************************


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 3000 );
});




//****************************************************************
// Affichage Diaporama photos Galleria
//****************************************************************

$(document).ready(function(){
	
	$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
	
	$('ul.gallery_demo').galleria({
		history   : true, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			image.css('display','none').fadeIn(1000);
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});
});



//****************************************************************
// Affichage Mask photos 
//****************************************************************
// Thumb Liens

(function($) {
	$.fn.thumbLiensCreate = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/mask-liens.gif" alt="" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbLiens').each(function(){$(this).thumbLiensCreate();});
});


// Thumb Diaporama

(function($) {
	$.fn.thumbDiaporamaCreate = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/diaporama/mask-diapo.gif" alt="" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbDiaporama').each(function(){$(this).thumbDiaporamaCreate();});
});


// Thumb Diaporama2

(function($) {
	$.fn.thumbDiaporama2Create = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/diaporama/mask-diapo.gif" alt="" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbDiaporama2').each(function(){$(this).thumbDiaporama2Create();});
});

// Thumb Slideshow

(function($) {
	$.fn.thumbSlideshowCreate = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/mask-slideshow.gif" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbSlideshow').each(function(){$(this).thumbSlideshowCreate();});
});

// Thumb News

(function($) {
	$.fn.thumbNewsCreate = function(){
		$(this).html('<div class="pic">'+$(this).html()+'</div><div class="mask"><img src="../images/mask-liens.gif" alt="" /></div>');
		return $(this);
	}
})(jQuery);

$(function(){
	$('#content div.thumbNews').each(function(){$(this).thumbNewsCreate();});
});