window.onload = function(){
var refreshed_content = Array('!ajax-content','member-logged', 'facebookconnector');
 // Config
 bda.transitionTweenType = Tween.regularEaseOut;
 bda.transitionAlpha = false;
 bda.calculateText = "<div class='post loader'><div class='entry'><p align='center'><img src='wp-content/themes/renanluce/images/spinner.gif' align='absmiddle' />&nbsp;Rendu de la page...</p></div></div>";
 bda.loadText = "<div class='post loader'><div class='entry'><p align='center'><img src='wp-content/themes/renanluce/images/spinner.gif' align='absmiddle' />&nbsp; Chargement en cours...</p></div></div>";

// Restriction liens
bda.denyURLRules.push('url.contains("/wp-admin/")');
bda.denyURLRules.push('url.contains("?feed=")');
bda.denyURLRules.push('url.contains("/trackback/")');
bda.denyURLRules.push('url.contains("wp-comments-post.php")');
bda.denyURLRules.push('url.contains("javascript")');
bda.denyURLRules.push('url.contains("daLoginForm")');
//bda.denyURLRules.push('url.contains("wp-signup.php")');
//bda.denyURLRules.push('url.contains("wp-login.php")');
bda.denyURLRules.push('url.contains("stfform")');
bda.denyURLRules.push('url.contains("store")');
bda.denyURLRules.push('url.contains("checkform")');
bda.denyURLRules.push('url.contains("#overlay")');

// Restriction formulaires
//bda.denyFormRules.push('action.contains("wp-comments-post.php")');
bda.denyFormRules.push('action.contains("login")');
bda.denyFormRules.push('action.contains("wp-login.php")');
bda.denyFormRules.push('action.contains("send_to_friend_db.php")');
bda.denyFormRules.push('action.contains("checkform")');

bda.addEventListener('load_complete','loadCompleteHandler'); 
bda.addEventListener('load_begin','loadBeginHandler'); 

 bda.start(refreshed_content); // initiate the script
 FB.XFBML.Host.parseDomTree();
}

function loadBeginHandler(e){
	var urlz = e.url;
	if (urlz.indexOf('fbconnect_action_logout') > 0) {
		FB.Connect.logout(function(){
			update_logout_user_box();
		})
	}
	
	if (urlz.indexOf('logout-memberacces') > 0) {
		jQuery.get(
			'index.php?fbconnect_action=logout',
			{  },
			function(data){
				document.getElementById("member-logged").style.display = "none";
				document.getElementById("al_login").style.display = "block";
				bda.getURL( "index.php" );
			}
		);
	}
	
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	if(!isIE){
		var section = gup( 'section' );
		if( section != "" ){
			getFlashMovie( "header" ).changeSection( section );
		}
	}
	
}
 
function loadCompleteHandler(e){
	var urlz = e.url;
	if (urlz.indexOf('show-comments') > 0) {
		overComment();
	}
	var allstatusbox = document.getElementById("wajdiii");
	if(allstatusbox!= null && allstatusbox!=undefined){
		jQuery.get(
			'facebook-platform/index.php',
			{  },
			function(data){
				document.getElementById("wajdiii").innerHTML=data;
				FB.XFBML.Host.parseDomTree();
			}
		);
	}
	var fb_user = FB.Connect.get_loggedInUser();
	if(fb_user!=null){
		hideMemberBox();
	}else{
		//showMemberZone();
	}
	FB.XFBML.Host.parseDomTree();
}

function publishStream(msgTxt){
	FB.init("cb02a172ba11122b1bf42f228df6c4de", "xd_receiver.htm");
	FB.Connect.streamPublish(msgTxt);
}

function postComment(id){
	var msg = "";
	var bauthor = true;
	var bemail = true;
	var bcomment = true;
	var sendToFacebook = jQuery("#sendToFacebook:checked").val();
	var blogName = jQuery("#blogname").val();
	var blogUrl = jQuery("#blogurl").val();
	var postLink = jQuery("#postlink").val();
	var postTitle = jQuery("#posttitle").val();
	var author = jQuery("#author").val();
	var email = jQuery("#email").val();
	var comment = jQuery("#comment"+eval(id)).val();
	if( typeof(author)!="undefined" ){
		if(author.length < 2 ){ bauthor = false; msg += "Le champ nom est obligatoire. <br/>";}
	}
	if( typeof(email)!="undefined" ){
		if( email.length < 5 && ( email.indexOf('@') == -1 || email.indexOf('.') == -1) ){ bemail = false; msg += "Le champ email est vide ou invalide. <br/>";}
	}
	if( comment.length < 3 ){ bcomment = false; msg += "Le champ commentaire est obligatoire.";}
	
	if(bauthor && bemail && bcomment){
		var email_ajax_data = "author="+jQuery("#author").val()+"&email="+jQuery("#email").val()+"&url="+jQuery("#url").val()+"&comment="+jQuery("#comment"+eval(id)).val()+"&comment_post_ID="+jQuery("#comment_post_ID"+eval(id)).val();
		jQuery.ajax(
			{
				type:"POST",
				url:'./wp-comments-post.php',
				data:email_ajax_data,
				cache:false,
				success:function(a){
					jQuery("#oComment"+eval(id)).overlay().close();
					bda.getURL( bda.getCurrentLocation() );
					if(sendToFacebook != undefined ){
						FB.init("cb02a172ba11122b1bf42f228df6c4de", "xd_receiver.htm");
						FB.Connect.showFeedDialog(
							287990385373,
							{'blog':'<a href="'+blogUrl+'">'+blogName+'</a>', 'post':'<a href="'+postLink+'">'+postTitle+'</a>', 'body': comment },
							null,
							postTitle,
							null,
							FB.RequireConnect.promptConnect,
							null,
							"Partagez cet article sur Facebook :"
						);
						//FB.Connect.streamPublish('wajdiiiiiiii', attachment, null, null, 'What do you think?');
					}
				}
			}
		);
	}else{
		jQuery(".errorform").css({'color' : 'red'})
		jQuery(".errorform").html(msg);
	}
}

function update_user_box(){
	//bda.getURL( bda.getCurrentLocation() );
	var liaccesmembres = document.getElementById('acces-membres');
	liaccesmembres.style.display = 'none';
	
	var liajaxmembres = document.getElementById('ajax-login');
	liajaxmembres.style.display = 'none';
	FB.Connect.showPermissionDialog("read_stream,publish_stream", function(){bda.getURL( bda.getCurrentLocation() );}, true, [65335933645,283549465373]);
	//FB.XFBML.Host.parseDomTree();
}

function hideMemberBox(){
	//bda.getURL( bda.getCurrentLocation() );
	var liaccesmembres = document.getElementById('acces-membres');
	liaccesmembres.style.display = 'none';
	
	var liajaxmembres = document.getElementById('ajax-login');
	liajaxmembres.style.display = 'none';
}

function update_logout_user_box(){
	jQuery.get(
			'index.php?fbconnect_action=logout',
			{  },
			function(data){
				bda.getURL( "index.php" );
				showMemberZone();
			}
	);
}

function showMemberZone(){
	var liaccesmembres = document.getElementById('acces-membres');
	liaccesmembres.style.display = 'block';
	
	var ajaxlogin = document.getElementById('ajax-login');
	ajaxlogin.style.display = 'block';
	
	var al_login = document.getElementById('al_login');
	al_login.className = '';
	al_login.style.display = 'block';
}

function showCommentPopin(id){
		jQuery("#oComment"+eval(id)).overlay({ 
	 
	    // custom top position 
	    top: -450, 
		left : 150,
	 	expose: { 
        // you might also consider a "transparent" color for the mask 
        color: '#000', 
        // load mask a little faster 
        loadSpeed: 200, 
        // highly transparent 
        opacity: 0.5 
    }, 
	    // disable this for modal dialog-type of overlays 
	    closeOnClick: true, 
	 
	    // we want to use the programming API 
	    api: true 
	 
	// load it immediately after the construction 
	}).load();
}

function showChronicPopin(id){
		jQuery("#oComment"+eval(id)).overlay({ 
	 
	    // custom top position 
	    top: -550, 
		left : -100,
	 	expose: { 
        // you might also consider a "transparent" color for the mask 
        color: '#000', 
        // load mask a little faster 
        loadSpeed: 200, 
        // highly transparent 
        opacity: 0.5
    }, 
	    // disable this for modal dialog-type of overlays 
	    closeOnClick: true, 
	 
	    // we want to use the programming API 
	    api: true 
	 
	// load it immediately after the construction 
	}).load();
}

function getFlashMovie(movieName) {
  	var isIE = navigator.appName.indexOf("Microsoft") != -1;
 	return (isIE) ? window[movieName] : document[movieName];
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function listenTo(id, album_title){
	var divId = id;
	var playerHTML = "";
	var playerbox = document.getElementById("playermp3-"+eval(id));
	jQuery.get(
				'playermp3.php',
				{ mp3 : album_title },
				function(data){
					playerHTML = data; 
					playerbox.innerHTML = playerHTML;
				}
		);
}

function tweet(){
	jQuery.post(
			'tweet.php',
			{  },
			function(data){
				alert(data);
			}
	);
}
