
arr_images_phototeque_affichees = new Array() ;

$(document).ready(function() {

	/* effets page phototeque */
	if($("#phototeque").size() > 0) {
		
		prechargerImages(new Array(
				'./img/phototeque/polaroid-hover.jpg'
		)) ;
		
		$("#phototeque map area").bind("mouseover",function() {
			$("#hover-"+$(this).attr('id')).css('display','block') ;
		}) ;
		$("#phototeque map area").bind("mouseout",function(event) {
			$("#hover-"+$(this).attr('id')).css('display','none') ;
		}) ;
		$(".hover-lieu-phototeque").bind("mouseover",function() {
			$("#"+$(this).attr('id')).css('display','block') ;
		}) ;
		$(".hover-lieu-phototeque").bind("mouseout",function() {
			$("#"+$(this).attr('id')).css('display','none') ;
		}) ;
		$(".hover-lieu-phototeque").bind("click",function() {
			window.location.replace($('#'+$(this).attr('id').substr(6,$(this).attr('id').length)).attr('href')) ;
		}) ;
			
	}
	
	
	$(".item-vignette-phototeque").each(function() {
		var image = new Image() ;
		image.src = $(this).find('a').attr('href') ;
		
		var id_photo = $(this).find('img').attr('id') ;
		
		if(!image.complete && !arr_images_phototeque_affichees[id_photo]) {
			$(this).css('display','none') ;
		}
	});
	
	if($("#googlemap").size() > 0) {
		$("#googlemap").css('display','block') ;
	}
	
	/* effets page recherche */
	if($("#conteneur-carte-fc").size() > 0) {
		/* precharger les images */
		prechargerImages(new Array(
			'./img/recherche/carte-bleue.jpg',
			'./img/recherche/carte-besac.jpg',
			'./img/recherche/carte-bresse-revermont.jpg',
			'./img/recherche/carte-massif-jura.jpg',
			'./img/recherche/carte-montbe-belfort.jpg',
			'./img/recherche/carte-region-lacs.jpg',
			'./img/recherche/carte-saone-ognon.jpg',
			'./img/recherche/carte-vallee-doubs.jpg'
		)) ;
		
		/* effets */
		$("#conteneur-carte-fc map area").bind("mouseover",function() {
			$("#carte-fc img").attr('src','./img/recherche/carte-'+$(this).attr('id')+'.jpg') ;
			majLocalisationCarte($(this)) ;
		}) ;
		$("#conteneur-carte-fc map area").bind("mouseout",function() {
			$("#carte-fc img").attr('src','./img/recherche/carte-bleue.jpg') ;
			$("#texte-localisation").html('') ;
		}) ;
	}
	
	/* effets images */
	if($("#vignettes-images").size() > 0) {
		
		$("#vignettes-images img").bind('mouseover',function() {
			
			$("#image-principale img").css('display','none') ;
			
			var img_vignette = $(this) ;
			
			$("#image-principale img").each(function(){
				if($(this).attr('src') == img_vignette.attr('src')) {
					
					var width ;
					
					if(navigateurIE()) {
						width = parseInt($(this).css('width').substr(0,$(this).css('width').length - 2)) + 8 ;
					}else {
						width = parseInt($(this).attr('width')) + 8 ;
					}
					
					
					$("#bas-image-principale").css('width',width+'px') ;
					$(this).css('display','block');		
				}
			}) ;
			
		}) ;
	}

	var cpt_photo_vue  = 0 ;
	var cpt_photo_vue_general = 0 ; 
	
	
	if($("a[rel^='prettyPhoto']").size() > 0) {
		$("a[rel^='prettyPhoto']").prettyPhoto({
				theme : 'facebook'
		});
	}

	/* effet formulaire page de resultats */
	if($("#select-rubrique").size() > 0) {
		
		$("#select-rubrique").bind('change',function() {
			$("#form-recherche-result input").each(function() {
				if($(this).attr('name').substr(0,1) == 'r' && $(this).attr('type') == 'hidden') {
					$(this).remove() ;
				}
			}) ;
			$("#form-recherche-result").submit() ;
		}) ;
		
		$("#select-photo").bind('change',function() {
			$("#form-recherche-result").submit() ;
		}) ;
		
	}
	
	/* contact */
	if($("#zone-textarea-contact-erreur").size() > 0) {
		
		$("#zone-textarea-contact-erreur").bind("focus",function() {
			$("#zone-textarea-contact-erreur").attr('id','zone-textarea-contact') ;
			
			$(".zone-texte-contact").each(function() {
				if(!$(this).val())
					$(this).attr('class','zone-texte-contact-erreur') ;
			}) ;
		});

		$(".zone-texte-contact-erreur").bind("focus",function() {
			$(".zone-texte-contact").each(function() {
				if(!$(this).val())
					$(this).attr('class','zone-texte-contact-erreur') ;
			}) ;
			
			$(this).attr('class','zone-texte zone-texte-contact') ;
			
			if(!$("#zone-textarea-contact").val())
				$("#zone-textarea-contact").attr('id','zone-textarea-contact-erreur') ;
			
		});
		
	}
	
}); 

function afficheVignettePhototeque(id) {
	
	$('#'+id).parent().parent().fadeIn() ;
	arr_images_phototeque_affichees[id] = true ;
	
}

function majLocalisationCarte(objArea,langue) {
	
	var marge_texte_normal = '44px' ;
	var marge_texte_grand = '38px' ;
	var marge ;
	var txt ;
	var area = objArea ;
	var id_area = objArea.attr('id') ;
	
	
	if(id_area == 'vallee-doubs') {
		if($("#langue").html() == 'en') {
			txt = 'The Doubs, the Loue<br />and the Dessoubre Valleys' ;
		}else {
			txt = 'Vallée du Doubs, de la Loue<br />et du Dessoubre' ;
		}
		marge = marge_texte_grand ;
	}else if(id_area == 'montbe-belfort') {
		if($("#langue").html() == 'en') {
			txt = 'Pays de Montbéliard<br />and Belfort Territory' ;
		}else {
			txt = 'Pays de Montbéliard<br />et Territoire de Belfort' ;
		}
		marge = marge_texte_grand ;
	}else {
		txt = objArea.attr('alt') ;
		marge = marge_texte_normal ;
	}
	
	$("#texte-localisation").css('top',marge) ;
	$("#texte-localisation").html(txt) ;
}

function afficheLocalisationCarte(bool) {
	
	var id = '#localisation-carte-fc' ;
	var vitesse = 'fast' ;
	
	if(bool) {
		$(id).fadeIn(vitesse) ;
	}else {
		$(id).fadeOut(vitesse) ;
	}
}

function prechargerImages(arr_chemins_images) {
	
	var i ;
	var src_img_tmp ;
	arr_images = new Array() ;
	
	for(i=0 ; i<arr_chemins_images.length ; i++) {
		arr_images[i] = new Image() ;
		arr_images[i].src = arr_chemins_images[i];
	}
	
}


function navigateurIE() {
	
	if(navigator.appName == "Microsoft Internet Explorer") {
		return true ;
	}else {
		return false ;
	}
}



