/**
 * A MODIFIER 
 */
var cheminImage = 'http://intra.interface.oceamanager/v3/commun/image/';

$(document).ready(function(){
	
	//Préchargement des images
	jQuery.preloadImages = function(){
		for(var i = 0; i<arguments.length; i++){
			jQuery("<img>").attr("src", arguments[i]);
		}
	};
	
	$.preloadImages(cheminImage+'handle.gif');
	
	//Lightbox prettyPhoto
	$("a.lightbox").attr("rel","prettyPhoto[gallery]");
	
	$("a.lightbox_iframe").attr("rel","prettyPhoto[iframes]");
	
	
	

	if($("a#video_accueil").size()>0) {
		
		$("a#video_accueil").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.40, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			modal: false, /* If set to true, only the close button will close the window */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){} /* Called when prettyPhoto is closed */
		});
	
	}
	
	if($("a#lien_accueil").size()>0) {
		$("a#lien_accueil").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.40, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			modal: false, /* If set to true, only the close button will close the window */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){} /* Called when prettyPhoto is closed */
		});
	
	}
	
	

	
	
});
/**
 * Affiche le loader 
 * 
 * @param 	id
 * @return	void
 */
function loader(id){
	$('#'+id).append('<div style="text-align: center; margin-top: 5px; font-weight: bolder;"><img src="'+cheminImage+'handle.gif" alt="loader" />&nbsp; Chargement en cours...</div>');
}

/**
 * Modifie le titre de la boite de dialogue avec image
 * 
 * @param 	conteneur
 * @param 	image
 * @param 	text
 * @return 	void
 */
function titreDialog(conteneur, image, text){
	$(conteneur).empty().prepend('<img src="'+cheminImage+image+'" style="vertical-align: -3px;" />&nbsp;'+text);
}

/**
 * Affiche la valeur de retour d'une requete AJAX 
 * avec un effet dans une box
 * 
 * @param 	conteneur
 * @param 	text
 * @param 	erreur
 * @return	void
 */
function messageRetour(conteneur, text, erreur){
	
	if( erreur == true ){
		$(conteneur).addClass('ui-state-error');
	}else{
		$(conteneur).addClass('ui-state-success');
	}
	$(conteneur).animate({opacity: '1.0'}, 2000);
	$(conteneur).html(text);
	$(conteneur).animate({ opacity: '0' }, 3000);
}

/**
 * Equivalent au strpos PHP
 * 
 * @param 	haystack
 * @param 	needle
 * @param 	offset
 * @return	integer
 */
function strpos(haystack, needle, offset){
    var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}

/**
 * Nombre de checkbox selectionnÃ© dans la page
 * 
 * @param 	void
 * @return	integer
 */
function nbSelection(){
	
	var i = 0;
	jQuery('input:checkbox').each(function(){
		
		checkbox = jQuery(this);
		if( checkbox.attr('checked') == true ){
			i++;
		}
	});
	return i;
}