$(document).ready(function () {
	$(".moreArticole").click(function(){
		$(".contentArticole").toggle('slow');
	})
	
/*
----------------------
 TABBED NAVIGATION
----------------------
*/
	$(".tab ul li a").click(function() {
		
		//alert($(this).parent().prevAll().length);
		myIndex = $(this).parent().prevAll().length;
		$(this).parent().parent().parent().children("div").slideUp();
		$(this).parent().parent().parent().children("div").eq(myIndex).slideDown();
		$(this)
		    .parents('ul:first') // find the first UL parent
		      .find('a') // find all the A elements
		        .removeClass('sel') // remove from all
		      .end() // go back to all A elements
		    .end() // go back to 'this' element
		    .addClass('sel');
	});
	
	//Handle POPUP EVENTS
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});


//END DOMReady
});




/*
----------------------
 POPUP
----------------------
*/
popupStatus=0;



function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		}).fadeIn("fast");;
		$("#popup").fadeIn("fast");
		centerPopup();
		popupStatus = 1;
		
	}
}

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("fast");
		$("#popup").fadeOut("fast");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	$("#popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}




