var current_back  = "none";
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
var functions = {
	
	/***Ajout***/
	
	init: function(divID){
		this.clickOnBox();
		this.clickOnPuce();
		this.infoBulle(divID);
	},
	
	/**********/
    
    
    
    // Lancement de l'appel AJAX si on clique sur les boites de droites
	clickOnBox: function() {
		$(".super_bloc > div.bloc").bind('click', function() {
			$(".super_bloc > div.bloc").removeAttr('alt');
			functions.appelAjax($(this));
			clearInterval(slideShowInterval);
		});
	},
	
	// Lancement de l'appel AJAX si on clique sur les puces
	clickOnPuce: function(){
		$("div.listNav > ul > li").children("a").each(function(i){
			$(this).bind('click', function(){
				$("div.listNav > ul > li").children("a").addClass("puce_nav").removeClass("puce_nav_on");
				$(this).children("a").addClass("puce_nav_on");
				
                clearInterval(slideShowInterval);
				$(".super_bloc > div.bloc").removeAttr('alt');
				functions.appelAjax( $(".super_bloc > div.bloc").eq(i));
			});
		});
	},
	
	// Effet sur les boites de droites
	hoverRightBox: function(){
		//var current_back = "none";
		$(".super_bloc > div.bloc").hover(
			function() {
				var my_id = $(this).parent().attr("id");
				if($(this).attr("alt") != "clicked") {
					$(this).attr("alt","over");
				}
				/*if ((version < 7)) {
					$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='pages/_img/ambassadors/home/fd_" + my_id + "_on.png', sizingMethod='image')");
				} else {*/
					//$(this).css("background-image","url(pages/_img/ambassadors/home/fd_" + my_id + "_on.png)");
					$(this).css("border","solid thin #8c0000");
				//}
			},
			function() {
				if($(this).attr("alt") != "clicked") {
					$(this).removeAttr("alt");
					if ((version < 7)) {
						$(this).css("filter","");
					} else {
						$(this).css("border","none");
					}
				}
			}
		);
	},
	
	// Appel AJAX
	appelAjax: function(my_bloc){
	    var my_id = my_bloc.parent().attr("id");
		var my_short_id = my_bloc.parent().attr("idn"); // Modif Fred 14.04.2009 17:34: retourne un id du nom de l'ambassadeur, pas l'index de l'id 
		my_bloc.attr("alt","clicked");
		$.ajax({
			type: 'POST',
			url: '?ajax_ambassadors',
			data: 'name=' + my_short_id + '&action=jacket',
			beforeSend: function() {
				$("div#ambassador_bloc").hide();
				//$("div#bloc_left").html('<img src="_img/general/loader_sans_gif.jpg" />');
			},
			success: function(msg) {
				var my_index = $("div#bloc_right > div").index(my_bloc.parent());
				$("div.listNav > ul > li").children("a").addClass("puce_nav").removeClass("puce_nav_on");
				$("div.listNav > ul > li").eq(my_index).children("a").addClass("puce_nav_on");
				
				$("div#ambassador_bloc").html(msg);
				$("div#ambassador_bloc").show();
				var arVersion = navigator.appVersion.split("MSIE");
				var version = parseFloat(arVersion[1]);
				/*if ((version < 7)) {
					$(".super_bloc > div.bloc[alt!=over]").css("filter","");
					$(".super_bloc > div.bloc[alt!=over]").css("background-image","none");
				} else {*/
					//$(".super_bloc > div.bloc[alt!=over]").css("background-image","none");
					$(".super_bloc > div.bloc[alt!=over]").css("border","none");
				//}
				my_bloc.attr('alt','clicked');
				/*if ((version < 7)) {
					my_bloc.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='pages/_img/ambassadors/home/fd_" + my_id + "_on.png', sizingMethod='image')");
				} else {*/
					//my_bloc.css("background-image","url(pages/_img/ambassadors/home/fd_" + my_id + "_on.png)");
					my_bloc.css("border","#8c0000 1px solid");
				//}
				//$("div#bloc_left").fadeIn();

				// transparence de l'image pour ie6
				if ((version < 7)) {
    				var photo_amb_src = document.getElementById('png_amb_picture').getAttribute('src');
                    // met l'image en transparent par le css
                    $('#photo_ambassadeur').css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + photo_amb_src + "', sizingMethod='image')");
                    // remplace l'image par un gif transparent
                    document.getElementById('png_amb_picture').src = 'pages/_img/blank.gif';
				}
			}
		});
	},
	
	
	
	/****Ajout*****/
	
	allBlocks : [], divParent: null, ibDiv : null, timeOutVar: null,
	infoBulle : function(divID){
		if ($("#ambinfo").get()==undefined) return;
		this.ibDiv = $("#ambinfo").get();
		$("#ambinfo").css('display', 'none');
		if (document.getElementById(divID)==undefined) return;
		this.divParent = document.getElementById(divID).getElementsByTagName('div');

		for (var i=0; i<this.divParent.length; i++){
			if (this.divParent[i].className=='super_bloc') {
				this.allBlocks.push(this.divParent[i]);
				this.divParent[i].saveN = (this.allBlocks.length-1);

				this.divParent[i].onmouseover = function(e){
					clearTimeout(functions.timeOutVar);
					if (!e) var e = window.event;
					e.cancelBubble = true;
					if (e.stopPropagation) e.stopPropagation();

					functions.showInfoBulle(this.saveN);
//					clearInterval(slideShowInterval);
				}
				this.divParent[i].onmouseout = function(){
					functions.timeOutVar = setTimeout('functions.hideInfoBulle()', 100);
				}
			}
		}
		$("#ambinfo").mouseover(function(e){
			clearTimeout(functions.timeOutVar);
			if (!e) var e = window.event;
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
		});
		$("#ambinfo").mouseout(function(){
			functions.timeOutVar = setTimeout('functions.hideInfoBulle()', 100);
		});
	},
	showInfoBulle: function(my_short_id){
		this.cDiv(my_short_id);

		var postop = (functions.allBlocks[my_short_id].offsetTop)+'px';
		$("#ambinfo").css("top", postop);

		/*if (functions.allBlocks[my_short_id].parentNode.className.indexOf('1')>0) { //BlockLeft1
			this.ibDiv.style.left = "163px";
		} else { //BlockLeft2
			this.ibDiv.style.left = "-40px";
		}*/
	   if((my_short_id%2)>0) {
	       $("#ambinfo").css("left", "-60px");
       } else {
            $("#ambinfo").css("left", "163px");
       }

		if ((version >= 5.5) && (version < 7)) correctPNG();
	},
	cDiv : function (n) {

		/*if (ambInf[n]!=undefined) {
			var img = this.ibDiv.getElementsByTagName('IMG');
			var bld = this.ibDiv.getElementsByTagName('STRONG');
			var psz = this.ibDiv.getElementsByTagName('p');
			var lnk = this.ibDiv.getElementsByTagName('a');

			//refix pngfix => IE6
			var span = this.ibDiv.getElementsByTagName('SPAN');
			if (span[0]!=undefined) {
				span[0].removeNode(true);
				var img = [];
				img[0] = document.createElement('IMG');
				img[0].className ='PhotoAmbassadeur';
				img[0].src = ambInf[n].portrait;
				this.ibDiv.insertBefore(img[0], this.ibDiv.firstChild)
			} else {
				img[0].src = ambInf[n].portrait;
			}

			bld[0].innerHTML = ambInf[n].title;
			psz[0].innerHTML = ambInf[n].subTitle;
			psz[1].innerHTML = ambInf[n].text;
			lnk[0].href = ambInf[n].link;
			this.ibDiv.style.display ='block';
		} else {
			this.ibDiv.style.display ='none';
		}*/
		//alert(n);
		
		content = $("#bubble"+(n+1)).html();
		//alert(content);
		$("#ambinfo").html(content);
        //this.ibDiv = $("#ambinfo").get();
        //alert(content);
		//$("#ambinfo").replaceWith("<div id='ambinfo'>"+content+"</div>");
		//this.ibDiv.innerHTML = content;
        //this.ibDiv.style.display ='block';
		$("#ambinfo").css("display", "block");
        return;
	},
	hideInfoBulle : function(){
		$("#ambinfo").css('display', 'none');
	}
};
