var $j = jQuery.noConflict();

$j(function(){

	// .sub-menu for IE6
	if (jQuery.browser.msie && jQuery.browser.version < 7 ) {
		$j('#menu-topmenu li, #menu-bar li').hover(function(){
			$j(this).find('.sub-menu').show();
		}, function(){
			$j(this).find('.sub-menu').hide();
		});
	};
	
	// target _blank with jquery 
	$j('.entry-content a[href*=http://]').each(function(){
		//alert(location.hostname);
		if(this.hostname !== location.hostname){
			$j(this).addClass('external-link').attr('target', '_blank');
		}
	});

	// remove target _blank for internal links
	$j('a[href*=apprendreetsorienter]').removeAttr('target');
	
	// PDF LINK
	if(!$j('body').hasClass('page-id-7')){
		$j('.entry-content a[href*=.pdf]').addClass('pdf-link').removeClass('external-link');
	}
		$j('li > a[href*=.pdf]').parent().addClass('li-pdf-link'); //gets all links ending in “pdf” that are children of any list item that has another list item as its previous sibling
	
	// fancybox all wordpress images
	$j("#content a[href$=.jpg], #content a[href$=.jpeg],#content a[href$=.png],#content a[href$=.gif]").fancybox({'overlayColor'	: '#FFF', 'overlayOpacity'	: .8});

	// Connexion adhérent
	$j(".popup-adherent").hide();

    $j(".btn-adherent").toggle(function(){
    		$j(".popup-adherent").slideDown(500);
    		$j(this).addClass("adherent-active");
	    }, function(){
    		$j(".popup-adherent").slideUp("slow");
    		$j(this).removeClass("adherent-active");
    });


	// Connection div - double
	var doubleDiv = $j('.column-right-content .login-adherent').size();
	if(doubleDiv == 1){
		$j('.column-right .popup-adherent:first').remove();
		$j('.btn-adherent').click(function(){
			$j('body').scrollTo( $j('#secondary'), 1000);
			$j(this).removeClass('adherent-active');
			//return false;
		});
	}

	//Cufon.replace('h1'); // Works without a selector engine
	
	// Ajax loader GIF - home page
	$j('#displayed').find('.ajax-loader').hide();
	$j('.ajax-form').click(function(){
		$j('#displayed').find('.ajax-loader').show();
	});
	
	// connect to leave comments 
	$j('a[href*=wp-login.php]').each(function()
		{ 
		  //this.href = this.href.replace(this, "http://localhost/apprendreetsorienter/?page_id=76");
		});
	
	
	// Highlight Keywords
	var myString = "école orientation projets rencontrer connaissances savoir apprendre agir réussite volonté orientación creación partager share devenir orienter" ; 
	myArray = myString.split(" "); 
	for(i=0;i<myArray.length;i++) 
	{ 
	$j('.single .entry-content p, .page .entry-content p').highlight(myArray[i]); 
	}
	
	// remove on links & wp-caption-text
	$j('.entry-content a, .entry-content .wp-caption-text, blockquote').removeHighlight();
	
	// Go menu : "haut de page"
	$j(".single .column-right-content, .page .column-right-content").append('<span class="go-menu"><span class="li-go-menu">Revenir au menu</span></span>');
	$j(".go-menu").click(function(){
		$j('body').scrollTo(0, 800);
	});
	
	// contact page
	$j('#captcha-text').attr({
		value: 'Code ...',
		onfocus: "if(this.value == 'Code ...'){this.value = '';}",
		onblur: "if(this.value == ''){this.value = 'Code ...'}"
	});
	
	 // COMMENTS
	 $j('.commentlist li.comment:even').addClass('comment-even');
	 $j('.commentlist li.comment:odd').addClass('comment-odd');
	
});
