window.onload = function(){
	correctPNG();
	navTop();
	flashHome();
	onHoverVille();
	onHoverEco();
	getVideo();
/*	if ($('.btn-search').length ) {
		$("#btn-search").mask("99999");		
		}
	$('#serchFrm').bind('click',setEventForGetMagasinByDepart);*/
		
}
function correctPNG(){ //pour les balise img=> ie6
if(window.navigator.userAgent.indexOf('MSIE 6.0') != -1){
for(var i=0; i<document.images.length; i++){
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
}
function navTop(){
	$(".items").bind("mouseenter",function(){
		   $(".sous-menu", $(this).parent()).show();
    })
	
	$(".menu > li").bind("mouseleave",function(){
		   $(".sous-menu").hide();
    });
}
function flashHome(){
	if($('#flash_home').length){
		var flashvars = false;
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			bgcolor: "#FFFFFF"
		};
		params.wmode = "transparent";
		var attributes = {
			id:"leCarre"
		};
		swfobject.embedSWF("./flash/carre.swf", "flash_home", "905", "600", "9.0.0", "./flash/expressInstall.swf", flashvars, params, attributes);
	}
	}
	
	
/*********      Chargement des magasins       ***********/

function setEventForGetMagasinByDepart(){
		if($(this).val().length == 5){
			var departement = $('#btn-search').val().substring(0,2);
			getMagasinByDepart(departement);
		}else if($(this).val().length == ""){
			getMagasinByDepart(this);
		}
	return false;
}
function getMagasinByDepart(obj, val){
	_this = obj;
	var dept = $('#btn-search').val().substring(0,2);
	$.ajax({
		type: "POST",url: "./include/magasin.php",data: "&dept=" + dept,
		success: function(data){
			if(data){
				$('#frm-search').replaceWith(data);
				$('#autreCode').click(function() {
						var serch="	<form action='' class='search' id='frm-search' onkeypress='return onKeyUpCodePostale(this,event);'><h2>LE GROUPE LE CARR&Eacute; <br/>DANS VOTRE R&Eacute;GION</h2><div id='input_codePostal'><p><label for='btn-search'>Entrez votre code postal</label></p><p><input type='text' id='btn-search' maxlength='5' onclick='return false;' /><input type='button' value='' class='submit' id='serchFrm'/></p></div></form>";
						$("#result").replaceWith(serch);
						$('#serchFrm').bind('click',setEventForGetMagasinByDepart);	 
				});					
				if (val != "")
				{
					$('#input_codePostal').val(val);
				}
			}
		}
	});
}

function onKeyUpCodePostale(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	//else return true;
	if (keycode == 13)
	   {
	   setEventForGetMagasinByDepart();
	   return false;
	   }
}
function onHoverVille(){
	var eventClick = false;
	
			$("#Map area").hover(function(){
				  //console.log(eventClick);					  
			      var id =  $(this).attr('id');
			      $('#liste-groupe li').hide();
			      $('#liste-groupe .' + id).show();
			     $("#Map area").click( function() { eventClick = true; } ); 
			    /*if($('#Map area').click()){
					
				}else{
					eventClick = false;	
				}*/	
				//console.log(eventClick);	
			 },function(){
			     var id =  $(this).attr('id');
			 	 //console.log("2");
			     if(eventClick == false){
				 	 $('#liste-groupe .' + id).hide();
					 eventClick = false;
					 //console.log(eventClick);
				  }else{
						var id =  $(this).attr('id');
						$('#liste-groupe .' + id).show();
					 	eventClick = false;
						//console.log(eventClick);		
				 }
			 });			
}

function getVideo(){
	var clipe = "<object id='player' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' name='player' width='285' height='180'><param name='movie' value='http://205.186.141.156/~lecarre/video/player.swf' /><param name='flashvars'value='file=http://205.186.141.156/~lecarre/video/glc_anime.flv&autostart=true&image=http://205.186.141.156/~lecarre/video/glc_anime.jpg' /><embed type='application/x-shockwave-flash' id='player2' name='player2' src='http://205.186.141.156/~lecarre/video/player.swf' width='285' height='180'allowfullscreen='true' flashvars='file=http://205.186.141.156/~lecarre/video/glc_anime.flv&autostart=true&image=http://205.186.141.156/~lecarre/video/glc_anime.jpg' /></object>";
			var interview = "<object id='player' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' name='player' width='285' height='180'><param name='movie' value='http://205.186.141.156/~lecarre/video/player.swf' /><param name='flashvars' value='file=http://205.186.141.156/~lecarre/video/playlist.xml&autostart=true'><embed type='application/x-shockwave-flash' id='player2' name='player2' src='http://205.186.141.156/~lecarre/video/player.swf' width='285'height='180'allowfullscreen='true'flashvars='file=http://205.186.141.156/~lecarre/video/playlist.xml&playlist=bottom&playlist=none&repeat=list&autostart=true' /></object>";
			var edf = "<object id='player' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' name='player' width='285' height='180'><param name='movie'value='http://205.186.141.156/~lecarre/video/player.swf' /><param name='flashvars' value='file=http://205.186.141.156/~lecarre/video/michel_chabert.flv&autostart=true&image=http://205.186.141.156/~lecarre/video/michel_chabert.jpg' /><embed type='application/x-shockwave-flash' id='player2' name='player2' src='http://205.186.141.156/~lecarre/video/player.swf' width='285' height='180'allowfullscreen='true'flashvars='file=http://205.186.141.156/~lecarre/video/michel_chabert.flv&autostart=true&image=http://205.186.141.156/~lecarre/video/michel_chabert.jpg' /></object>";	
	
	$('#video-clip').bind('click',function(){
		$('#content-video-items').html(clipe);
		return false;
	})		
	$('#video-edf').bind('click',function(){
		$('#content-video-items').html(edf);
		return false;
	})		
	$('#video-interview').bind('click',function(){
		$('#content-video-items').html(interview);
		return false;
	})	
}
function onHoverEco(){
	$("#nav-eco li").hover(function(){
	  var id =  $(this).attr('id');
	  $('#items-eco-energie .' + id).show();
	  $('#items-eco-energie .eco_maison').hide();
	 },function(){
	  var id =  $(this).attr('id');
	  $('#items-eco-energie .' + id).hide();
	  $('#items-eco-energie .eco_maison').show();
	 });
}



