//////////////////////////////////////////////
/////   Opens Jquery
jQuery(document).ready(function() { 
//////////////////////////////////////////////


	//////////////////////////////////////////////
    /////   adds a subtitle to each rootItem of the menu
    //////////////////////////////////////////////
    var menutabsubtitle = ['Top d&eacute;part', '&nbsp;D&eacute;couverte', "Besoin d'aide ?", 'T&eacute;l&eacute;chargements', 'News & Events', 'Config', 'Config'];
    var menutabcount = 0;
	var elemMenu = jQuery('.RadMenu_dnnfr .rmHorizontal > .rmItem > .rmLink');
    elemMenu.each(function() {
		var elem = jQuery(this);
        var pagelabel = elem.text();
        var mysubtitle = menutabsubtitle[menutabcount];
        elem.html('<span class="rmText">' + pagelabel + '</span><span class="mainNavBottom">' + mysubtitle + '</span>');
        menutabcount = menutabcount + 1;
    }); 
	jQuery('div.RadMenu_dnnfr').show(); //Evite un jump du menu sur les pages à chargement long type Forum
								
	//////////////////////////////////////////////
    /////   Style-Switcher code
    //////////////////////////////////////////////
    jQuery('#styleChanger ul li a').click(function() {
        jQuery('#styleChanger li a.selected').css({
            backgroundPosition: 'left 0px'
        });
        switchStylestyle(this.getAttribute("rel"));
        createCookie('id', this.id, 365);
        jQuery(this).css({
            backgroundPosition: 'left -16px'
        });
        jQuery('#styleChanger ul li a').removeClass('selected');
        jQuery(this).addClass('selected');
        return false;
    });
    var style = readCookie('style');
    var id = readCookie('id');
    if (style) switchStylestyle(style);
    if (id) {
        jQuery('#styleChanger li a.selected').removeClass('selected');
        jQuery('#' + id).addClass('selected');
    }
    jQuery('#styleChanger li a.selected').css({
        backgroundPosition: 'left -16px'
    }); 
	
	
	//////////////////////////////////////////////
    /////   Place the translation info inside the right container
    //////////////////////////////////////////////
	if (jQuery("#LastTranslationInfo").length > 0) {
		if (jQuery("#LastTranslationInfo").length > 0) {
		
		var elem = jQuery("#LastTranslationInfo");
		var elem2 = jQuery("#LastTranslationPlaceHolder");
        elem2.html(elem);
		elem.show('slow');
		}
		
    }
	if (jQuery("#PreviousTranslationInfo").length > 0) {
		if (jQuery("#PreviousTranslationInfo").length > 0) {
		
		var elem = jQuery("#PreviousTranslationInfo");
		var elem2 = jQuery("#PreviousTranslationPlaceHolder");
        elem2.html(elem);
		elem.show('slow');
		}
		
    }
	
	
	//////////////////////////////////////////////
    /////   The sliding connection container at the top of the page
    //////////////////////////////////////////////
    jQuery('div#slideContainer').addClass('contactBG');
    if (jQuery('#dnn_ctr378_ctl01_lblMessage').length > 0) {
        jQuery('div#slideContainer').slideDown(800,
        function() {
            jQuery('#slideContact').html('Refermer');
        });
    };
    if (jQuery('#dnn_ctr378_ctl00_lblMessage').length > 0) {
        jQuery('div#slideContainer').slideDown(800,
        function() {
            jQuery('#slideContact').html('Refermer');
        });
    };
    jQuery('a#slideContact').toggle(function() {
        jQuery('div#slideContainer').slideDown(800,
        function() {
            jQuery('#slideContact').html('Refermer');
        }); return false;
    },
    function() {
        jQuery('div#slideContainer').slideUp(800,
        function() {
            jQuery('#slideContact').html('Connexion Inscription');
        });
        return false;
    }); 
	
	//////////////////////////////////////////////
    /////   adds a class of odd (.odd) to every other list item in the News Block (.newsBlock)
    //////////////////////////////////////////////
    jQuery('.rightSideBarBlock li').filter(':odd').addClass('odd'); 
	
	//////////////////////////////////////////////
    /////   adds a class of odd (.odd) to every other table row in the mortgage table (#mortgageTable)
    /////   adds the class tableHover (.tableHover) to a table row with the class of sub (.sub) when hovered
    //////////////////////////////////////////////
    jQuery('#businessTable tr').filter(':odd').addClass('odd');
    jQuery('#downloadTable tr').filter(':odd').addClass('odd');
	jQuery('.businessTable tr').filter(':odd').addClass('odd');
    jQuery('.downloadTable tr').filter(':odd').addClass('odd');
    jQuery('tr.sub').hover(function() {
        jQuery(this).addClass('tableHover');
    },
    function() {
        jQuery(this).removeClass('tableHover');
    });
	jQuery('.businessTableItem').hover(function() {
        jQuery(this).addClass('tableHover');
    },
    function() {
        jQuery(this).removeClass('tableHover');
    });
	
	//////////////////////////////////////////////
    /////   Login panel slide
    //////////////////////////////////////////////
    jQuery('a.openlogin').toggle(function() {
        jQuery('div#slideContainer').slideDown(800);
        jQuery('#slideContact').html('Refermer');
        return false;
    },
    function() {
        jQuery('div#slideContainer').slideUp(800);
        jQuery('#slideContact').html('Connexion Inscription');
        return false;
    }); 
	
	//////////////////////////////////////////////
    /////   Initialize newsSlider
    //////////////////////////////////////////////
	if (jQuery('#newsSlider').length > 0) {
    	jQuery('#newsSlider').newsSlider(); 
	}; 
	
	//////////////////////////////////////////////
    /////    Build an automatic list of anchor when the div#giveMeAList is present
    //////////////////////////////////////////////
    if (jQuery('#giveMeAList').length > 0) {
        var intanchorcount = 0;
        jQuery('.homePageContent h3').each(function() {
            var anchortext = jQuery(this).text();
            jQuery(this).html('<a name="anchor_' + intanchorcount + '"></a>' + anchortext);
            jQuery("#giveMeAList").html(jQuery("#giveMeAList").html() + '<a href="#anchor_' + intanchorcount + '">' + anchortext + '</a><br />');
            intanchorcount = intanchorcount + 1;
        });
    }; 
	
	//////////////////////////////////////////////
    /////   Highlight the key elements
    //////////////////////////////////////////////
    jQuery("div#dnn_headerRight").oneTime(30000,
    function(i) {
        jQuery(this).fadeOut("fast");
        jQuery(this).fadeIn("fast");
        jQuery(this).fadeOut("fast");
        jQuery(this).fadeIn("fast");
    });
	jQuery(".evidence .evidence_wrap h1").oneTime(4000,
    function(i) {
        jQuery(this).fadeOut("fast");
        jQuery(this).fadeIn("fast");
        jQuery(this).fadeOut("fast");
        jQuery(this).fadeIn("fast");
    });
	
	//////////////////////////////////////////////
    /////   Auto expantion of the article comment's textarea
    //////////////////////////////////////////////
    if (jQuery('textarea[id*=_txtComment]').length > 0) {
        jQuery('textarea[id*=_txtComment]').elastique();
    };
	
	//////////////////////////////////////////////
    /////   Format the code in any article containing a PRE
    //////////////////////////////////////////////
    if (jQuery('pre').length > 0) {
        jQuery.beautyOfCode.init({
              config: {stripBrs: true}
			, brushes: ['Vb', 'JScript', 'CSharp', 'Sql', 'Css', 'Xml']
        });
    }; 
	
	//////////////////////////////////////////////
    /////   Send to a friend
    //////////////////////////////////////////////
		if(jQuery(".infos_details #sendtofriend a").length > 0)
	{
		var eauatabid = '72'; // TabID of the page containing the module OSO.SendToAFriend
		var urlcourante = document.location.href;
		var titrecourant =  jQuery('.infos_general h1').text();   // This can be changed ... document.title;
		
		
		jQuery(".infos_details #sendtofriend a").attr("href", document.location.href.replace("tabid", "") + "Default.aspx?tabid=" + eauatabid + "&EAUAURL=" + urlcourante + "&EAUATITLE=" + titrecourant);
	}
	
	
	
	//////////////////////////////////////////////
    /////   Send to a friend - In field label & elastic
    //////////////////////////////////////////////
	
	if(jQuery("label#custombodylabel").length > 0)
	{
		jQuery(function(){ 
			jQuery("label#custombodylabel").inFieldLabels(); 
			jQuery("textarea[id$='_txt_BodyCustom']").elastic(); 
			}
		);	
	}
	
	if(jQuery("label#emailLabel").length > 0)
	{
		jQuery(function(){ 
			jQuery("label#emailLabel").inFieldLabels(); 
			 
			}
		);	
	}

	//////////////////////////////////////////////
    /////   Removes the Dnn Help buttons
    //////////////////////////////////////////////
    if (jQuery("a[id$='_cmdHelp']").length > 0) {
        jQuery("a[id$='_cmdHelp']").parent().remove();
    }; 




	//////////////////////////////////////////////
    /////   Sommaire dynamique
	//////////////////////////////////////////////
	if(jQuery(".twoColRight #Sommaire_dynamique ul").length > 0)
	 {
	
		if(jQuery(".twoColLeft h2").length > 0)
		 {
			 jQuery('.twoColLeft h2, .twoColLeft h3').each(function(){
				 var thisText = jQuery(this).text();
				 var anchorText = thisText.replace(/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/g, "-");
				 var anchorLink = '<a name="' + anchorText + '"></a>';
				 var refText = '';
				 if (jQuery(this).is('h2')){
					 thisText = '<b>' + thisText + '</b>';
					 refText = '<li><a href="#' + anchorText + '">' + thisText + '</a></li>';
				  }else{
	
					 refText = '<li>' + '&nbsp;'  + '<a href="#' + anchorText + '">' + thisText + '</a></li>';
				  }
				  
				 jQuery(this).before(anchorLink);
				 jQuery(refText).appendTo('#Sommaire_dynamique ul');
			 });
		 };
	};
	
	if(jQuery(".twoColLeft #Sommaire_dynamique ul").length > 0)
	 {
	
		if(jQuery(".twoColRight h2, .twoColRight h3").length > 0)
		 {
			 jQuery('.twoColRight h2, .twoColRight h3').each(function(){
				 var thisText = jQuery(this).text();
				 var anchorText = thisText.replace(/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/g, "-");
				 var anchorLink = '<a name="' + anchorText + '"></a>';
				 var refText = '';
				 if (jQuery(this).is('h2')){
					 thisText = '<b>' + thisText + '</b>';
					 refText = '<li><a href="#' + anchorText + '">' + thisText + '</a></li>';
				  }else{
	
					 refText = '<li>' + '&nbsp;'  + '<a href="#' + anchorText + '">' + thisText + '</a></li>';
				  }
				  
				 jQuery(this).before(anchorLink);
				 jQuery(refText).appendTo('#Sommaire_dynamique ul');
			 });
		 };
	};
	
	if(jQuery(".article_detail #Sommaire_dynamique ul").length > 0)
	 {
	
		if(jQuery(".article_detail h3").length > 0)
		 {
			 jQuery('.article_detail h3').each(function(){
				 var thisText = jQuery(this).text();
				 var anchorText = thisText.replace(/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/g, "-");
				 var anchorLink = '<a name="' + anchorText + '"></a>';
				 var refText = '';
				 thisText = '<b>' + thisText + '</b>';
				  refText = '<li><a href="#' + anchorText + '">' + thisText + '</a></li>';
				  
				 jQuery(this).before(anchorLink);
				 jQuery(refText).appendTo('.article_detail #Sommaire_dynamique ul');
			 });
		 };
	};
	
	
	
	
	
	
	
	

	//////////////////////////////////////////////
    /////   Page des sponsors
	//////////////////////////////////////////////
	if(jQuery(".sponsorFlip").length > 0)
	 {
		jQuery('.sponsorFlip').bind("click",function(){
			var elem = jQuery(this);
			if(elem.data('flipped'))
			{
				elem.revertFlip();
				elem.data('flipped',false)
			}
			else
			{
				elem.flip({
					direction:'lr',
					speed: 350,
					onBefore: function(){
						elem.html(elem.siblings('.sponsorData').html());
					}
				});
				elem.data('flipped',true);
			}
		});
	}

	//////////////////////////////////////////////
    /////   Image de chargement
	//////////////////////////////////////////////
	if(jQuery("a.createaccount").length > 0)
		 {
			var elem = jQuery("a.createaccount");
			elem.click(function(){
				//elem.removeClass('createaccount');
				elem.html("<img class='localding_image_registration' src='http://www.dotnetnuke-fr.org/Portals/_default/Skins/dnnfr/images/loading_bar.gif' />");
			});

    }

    //////////////////////////////////////////////
    /////   Délaye le chargement des images dans le corps de l'article
    //////////////////////////////////////////////
    if (jQuery(".article_detail img").length > 0) {
        var elem = jQuery(".article_detail img");
        elem.lazyload({
            placeholder: "http://www.dotnetnuke-fr.org/Portals/_default/Skins/dnnfr/images/grey.gif",
            effect: "fadeIn"
        });
    }
    


    //////////////////////////////////////////////
    /////   Popup proposant l'inscription
    //////////////////////////////////////////////
	
	if (jQuery("li.bulletFooter a[href*=Logoff.aspx]").length == 0) {
	
	
   	 if (jQuery("a.popup").length > 0) {
			var elem = jQuery("a.popup");
		 
			 elem.click(function(){
				centerPopup();
				loadPopup();
			});
						
			//CLOSING POPUP
			jQuery("#PupopClose").click(function(){
				disablePopup();
			});
			jQuery("#PupopBackground").click(function(){
				disablePopup();
			});
			//Press Escape event!
			jQuery(document).keypress(function(e){
				if(e.keyCode==27 && popupStatus==1){
					disablePopup();
				}
			});
		}
	 }
	
	
	//////////////////////////////////////////////
    /////   Zoom sur les images enormes
	//////////////////////////////////////////////
	if(jQuery(".zoomin").length > 0)
		 {
			//var elem = jQuery("a.createaccount");
			jQuery(".zoomin").jqzoom();

    }
	
	
	

//////////////////////////////////////////////
/////   Closes Jquery
}); 
//////////////////////////////////////////////

// Switch CSS styles
function switchStylestyle(styleName) {
    jQuery('link[rel*=style][title]').each(function(i) {
        this.disabled = true;
        if (this.getAttribute('title') == styleName) this.disabled = false;
    });
    createCookie('style', styleName, 365);
} 

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}function eraseCookie(name) {
    createCookie(name, "", -1);
}

// Popup
//0 means disabled; 1 means enabled;
var popupStatus = 0;
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		jQuery("#PupopBackground").css({
			"opacity": "0.7"
		});
		jQuery("#PupopBackground").fadeIn("slow");
		jQuery("#Pupop").fadeIn("slow");
		popupStatus = 1;
	}
}
//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#PupopBackground").fadeOut("slow");
		jQuery("#Pupop").fadeOut("slow");
		popupStatus = 0;
	}
}
//centering popup
function centerPopup(){
	//Get the window height and width  
	var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset;
    var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset;

    var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth;
    var screenHeight = document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;

	var popupHeight = jQuery("#Pupop").height();
	var popupWidth = jQuery("#Pupop").width();

    var left = scrolledX + (screenWidth - popupWidth)/2;
    var top = scrolledY + 100 + (popupHeight)/2;
	
	
	//centering
	jQuery("#Pupop").css({
		"position": "absolute",
		"top": top,
		"left": left
	});
	//only need force for IE6
	
	jQuery("#PupopBackground").css({
		"height": screenHeight
	});
	
}



