/* ------------------------------------------------------------------- */
/* Preload images
*/
function preload (obj) {
	if (obj.size() > 0) {
		$("<img>").attr("src", obj.css('background-image').replace(/^url|[\(\)]/g, '').replace(/_off\./, '_on.'));
	}
}

/* ------------------------------------------------------------------- */
/* Fonction utilise pour les rollover sur les images / input images 
Utilisation:
Mettre la classe rollover sur l'lment devant changer
Le nom des images doit finir -off.xxx pour l'image par dfaut et -on.xxx pour l'image de survol
*/

rolloverTool = {};
rolloverTool.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".rollover").hover(
         function () { $(this).attr( 'src', rolloverTool.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', rolloverTool.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.rollover').each( function( key, elm ) { $('<img>').attr( 'src', rolloverTool.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.replace(/_off\./, '_on.');
   },

   oldimage: function( src )
   {
      return src.replace(/_on\./, '_off.');
   }
};

/* ------------------------------------------------------------------- */
/* Fonction regroupant tous les correctifs pour IE6 uniquement */
function ie6Fixes () {
	/* Active le bouton affichant les rseaux sociaux */
	$('#btFiliales').hover(function () {$(this).addClass('liHover');}, function () {$(this).removeClass('liHover');});
}

/* ------------------------------------------------------------------- */
/* Ouvre le lien dans une nouvelle fentre */
function ouvrirDansNouvelleFenetre () {
	window.open(this);
	return false;
}

/* ----------------------------------------- Ouverture de popup  ----------------------------------------------- */
// Si x et y ne sont pas mentionnés, la popup est automatiquement centrée

function openPopup(url,nomPopup,myScroll,l,h,x,y,myResizable){
	var win;
	if (x == null) {
		x = screen.width/2 - l/2;
	}
	if (y == null){
		y = screen.height/2 - h/2;
	}
	if (myScroll != 'no'){
		myScroll = 'yes';
	}
	if (myResizable != 'yes'){
		myResizable = 'no';
	}
	win=open(url,nomPopup,'width=' + l + ',height=' + h + ',status=no,toolbar=no,menubar=no,location=no,resizable=' + myResizable + ',titlebar=no,scrollbars=' + myScroll + ',fullscreen=no,left=' + x + ',top=' + y);
	win.focus();
}

function ouvrirContact() {
	openPopup(frontFolder + 'popup-contact.php','contact','no',500,300,null,null,'no');
	return false;
}

function fermerPopup() {
	window.close();
	return false;
}

/* ------------------------------------------------------------------- */
/* Initialisation de la page */

$(document).ready(function () {
   rolloverTool.rollover.init();
   
   $('a.triggerNouvelleFenetre').bind("click", ouvrirDansNouvelleFenetre);
   $('a.triggerPopupContact').bind("click", ouvrirContact);
   $('a.triggerFermerPopup').bind("click", fermerPopup);
   
   preload ($('#btAccueil'));
   preload ($('#btFiliales'));
   preload ($('#btBeYoupi'));
   preload ($('#btBigJack'));
   preload ($('#btDigitalKartel'));
   preload ($('#btReference'));
   
   /* Correctifs pour IE6 */
	if (jQuery.browser.msie && parseInt(jQuery.browser.version.substr(0,1)) <= 6) {
		ie6Fixes ();
	}
});