function ini_menu(){
	$("#menu a").hover(function(){
			var em=$(this).find("em");
			$(em).stop();
			$(em).css("height","10px");
			$(em).slideDown("slow",function(){});
			
	}, function(){
			var em=$(this).find("em");
			$(em).stop();
			$(em).slideUp(function(){});
	});
}

function ini_social_slide(){
	$("#social_slide a").hover(function(){
			var em=$(this).find("em");
			var span=$(this).find("span");
			$(span).fadeOut(0,function(){$(em).fadeIn(0)});
	}, function(){
			var em=$(this).find("em");
			var span=$(this).find("span");
			$(em).fadeOut(0,function(){$(span).fadeIn(0)});
	});
}

function getXhr() {
	var xhr = null; 
	
	if(window.XMLHttpRequest) {
		xhr = new XMLHttpRequest(); 
	}
	else if(window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
	
	return xhr
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

function article_prev(article) {
	$("#blog_inner").fadeOut("fast",function(){
	var xhr = getXhr()
	
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById('blog_inner').innerHTML = xhr.responseText;
			$("#content").animate({"height": $("#blog_inner").height()+15},
			function (){
			$("#blog_inner").fadeIn("fast");
			});
			alert($("#blog_inner").height());
		}
	}
	
	xhr.open("GET","includes/blog.php?article_prev="+escape(article),true);
	xhr.send(null);
});
}

function article_next(article) {
	$("#blog_inner").fadeOut("fast",function(){
	var xhr = getXhr()
	
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById('blog_inner').innerHTML = xhr.responseText;
			$("#content").animate({"height": $("#blog_inner").height()+15},
			function (){
			$("#blog_inner").fadeIn("fast");
			});
			alert($("#blog_inner").height());
		}
	}
	
	xhr.open("GET","includes/blog.php?article_next="+escape(article),true);
	xhr.send(null);
});
}

function comments_open(id) {
	var xhr = getXhr()
	xhr.onreadystatechange = function() {
		if(xhr.readyState == 4 && xhr.status == 200) {
			document.getElementById('comments_inner').innerHTML = xhr.responseText;
			$("#content").animate({"height": $("#blog_inner").height()+$("#comments_inner").height()+15},
			function (){
			$("#comments_inner").fadeIn("fast");
			});
		}
		else {
			document.getElementById('comments_inner').innerHTML = '<div style="padding-top: 10px;text-align:center;"><img src="img/ajax-loader.gif" alt="AJAX LOADING..." /></div>';
		}
	}
	document.getElementById('comments_toggler').innerHTML = '<a href="#" onclick="comments_close('+escape(id)+'); return false;" title="- Commentaires">- Commentaires</a>';
	
	xhr.open("GET","includes/comments.php?id_com="+escape(id),true);
	xhr.send(null);
}

function comments_close(id) {
	$("#comments_inner").fadeOut("fast",function(){
			$("#content").animate({"height": $("#blog_inner").height()},
			function (){
			document.getElementById('comments_inner').innerHTML = '';
			});
			document.getElementById('comments_toggler').innerHTML = '<a href="#" onclick="comments_open('+escape(id)+'); return false;" title="+ Commentaires">+ Commentaires</a>';
		});
}

function sendData(param, page, secpage, divpart, secdiv, postid){

   		if(document.all)
		{
			var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
			var XhrObj2 = new ActiveXObject("Microsoft.XMLHTTP") ;
		}
		else
		{
			var XhrObj = new XMLHttpRequest();
			var XhrObj2 = new XMLHttpRequest();
		}

        document.getElementById(divpart).innerHTML  = "Envoi en cours...";

		 var content = document.getElementById(divpart);
		 var content_illu = document.getElementById(secdiv);

		XhrObj.open("POST", page);
		XhrObj2.open("POST", secpage);

	 	XhrObj.onreadystatechange = function()
		{
			if (XhrObj.readyState == 4 && XhrObj.status == 200)
				content.innerHTML = XhrObj.responseText ;
		}
		XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		XhrObj.send(param);
		XhrObj2.onreadystatechange = function()
		{
			if (XhrObj2.readyState == 4 && XhrObj2.status == 200){
				content_illu.innerHTML = XhrObj2.responseText ;
				$("#content").animate({"height": $("#blog_inner").height()+$("#comments_inner").height()+15});
				}
		}
		XhrObj2.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		XhrObj2.send(param);
	}

function card(){
	
	//selectors
	var sNavSelector 	= "#menu";
	var sCardSelector 	= "#main";
	var sContent		= "#content"; 
	
	//object refs
	var oCard, oNav, oContent;
	var self = this;
	
	function clickNav( e ){
		
		//make a ref to this
		var oThis = $(this);
		
		//fadeout the current content...after fade show the clicked on
    	$(oNav.find('.current a').attr('href')).fadeOut('fast');
    	oContent
    		.stop()
    		.animate( 
    			{'height': $(oThis.attr('href')).height()},
    			function(){
    				//show this area
    				oThis.parent('li').addClass('current');
    				
    				//get the height of the area to show
    				$(oThis.attr('href')).fadeIn();
    				
    				//hide the others
    				oThis.parent('li')
    					 .siblings()
    					 .removeClass('current')
    					 .find('a')
    					 .each( function(){ $($(this).attr('href')).hide(); } );				
    			}
    		);	
	}
	
	this.init = function(){
		
		//setup the object refs
		oNav 		= $(sNavSelector);
		oCard 		= $(sCardSelector);
		oContent	= $(sContent);
		
		//init nav
		self.initNav();
		
	}
	
	//setup the click handlers on the nav
	this.initNav = function(){
		
		//setup the click functions
		oNav.find('a').click( clickNav );
				
		//if there is a hash location in the url, go there, 
		//otherwise goto the current class in the markup
		var sHashSelector = 'a[href=' + document.location.hash + ']';
		if( document.location.hash && oNav.find(sHashSelector).length > 0 ){
			oNav.find(sHashSelector).click();						
		}else{
			oNav.find('li.current a').click();
		}
		
	}
	
	//when instantiating a new card, call the init function
	$(window).load( function(){ self.init(); } );
}
var oCard = new card();

$(document).ready(function() {
		
	ini_menu();
	ini_social_slide();
	
});
