jQuery(document).ready(function(){

// Clignotement nouveau MP
$("span.new-message").html("<blink>"+($("span.new-message").html())+"</blinh>");

// Listing rétractable
jQuery(".retract dt").mouseenter(function(){
	jQuery(this).next("dd").slideDown();
});
jQuery(".retract dt").mouseleave(function(){
	jQuery(this).next("dd").slideUp();
});

// Liste déroulante

$(".expand").find("dt").toggle(function(){
	var content = $(this).html();
	$(this).html(content.replace(/\+/,"-"));
	$(this).next("dd").slideDown();
},
function(){
	var content = $(this).html();
	$(this).html(content.replace(/\-/,"+"));
	$(this).next("dd").slideUp();
});


// Config MARQUEE
$("marquee").attr("scrollamount","1");
$("marquee").mouseover(function() { this.stop(); })
			.mouseout(function() { this.start();});

// Spoiler
$("[onClick='$(this).parents(\'.codebox\').find(\'.spoiler_content\').toggleClass(\'hidden\');']").attr('onClick',"$(this).parents('.codebox').find('.spoiler_content').slideToggle();");
/*---------------------------------------------
	Addon : Pop-up nouveau membre
---------------------------------------------*/
var vsize = $(window).height();
var hsize = $(window).width();
vsize = vsize*0.80 ; vsize_content = vsize - 125;
hsize = hsize*0.60 - 20 ; 
jQuery("#pop-up").children(jQuery("div[id='']")).css({overflow: "auto", maxHeight: vsize_content});
jQuery("#pop-up").css({display:"none", top: "10%", left: "20%", width: hsize, padding: "50px", position: "fixed", zIndex: "10000", maxHeight: vsize});


if (document.getElementById("preview"))	// Annulation de la pop-up au preview
{
	jQuery("#pop-up").remove();
}

jQuery("#pop-up #close").click(function(){	// Ferme la pop-up et ne la réaffiche pas
	jQuery("#pop-up").slideUp(2000);
	setTimeout("jQuery('#pop-up').remove()",2000);
});  


var speed = jQuery("#text_editor_textarea");
speed.focus(function(){
	var pop_up = jQuery("#pop-up");
	var count = jQuery("#count").html();
	if ( count == 0 ) {
	  pop_up.show().slideUp(0).slideDown(2000);
	}
});
var subject = jQuery("input[name=subject]");
subject.focus(function(){
	var pop_up = jQuery("#pop-up");
	var count = jQuery("#count").html();
	if ( count == 0 ) {
	  pop_up.show().slideUp(0).slideDown(2000);
	}
});

jQuery.fn.redirectPost = function (option) {
	var target = option || "false" ;
	if ( target == "false" ) { return ; }

	var count = jQuery("#count").html();
	if ( count == 109 )
	{
		var link = jQuery("a[href*='post.forum']");
		link.attr("href","post.forum?mode=newtopic&f="+target);
		jQuery("#quick_reply").remove();
	}
}

/*---------------------------------------------
	Addon : Pop-up
---------------------------------------------*/
var vsize = $(window).height();
var hsize = $(window).width();
vsize = vsize*0.80 ; vsize_content = vsize - 125;
hsize = hsize*0.60 - 20 ; 
jQuery(".popup").children(jQuery("div[id='']")).css({overflow: "auto", maxHeight: vsize_content});
jQuery(".popup").css({top: "10%", left: "20%", width: hsize, padding: "50px", position: "fixed", zIndex: "10000", maxHeight: vsize});
jQuery(".popup .close").click(function(){
	jQuery(this).parent(".popup").slideUp(2000);
});  

//Partenaire
jQuery("a[href*='mode=newtopic&f=8']").attr("href","#").click(function(){
	jQuery("#partenaire").show().slideUp(0).slideDown(2000);
});
jQuery("a[href*='mode=newtopic&f=9']").attr("href","#").click(function(){
	jQuery("#partenaire").show().slideUp(0).slideDown(2000);
});
jQuery("form[name='form']").find("input[name='submit']").click(function(){
	var form = jQuery("form[name='form']");
	var submit = jQuery("form[name='submit']");
	
	var sitename = form.find("[name='sitename']").attr("value");
	var siteURL = form.find("[name='siteURL']").attr("value");
	var categorie = form.find("select[name='categorie']").attr("value") + form.find("input[name='categorie']").attr("value");
	var buttonURL = form.find("[name='buttonURL']").attr("value");
	var description = form.find("[name='description']").attr("value");
	var msg = form.find("[name='message']").attr("value");
	//Traitement de variable
	var spChar = /(['"])/g;
	sitename = sitename.replace(spChar,"&#146;");
	siteURL = siteURL.replace(spChar,"&#146");
	categorie = categorie.replace(spChar,"&#146");
	buttonURL = buttonURL.replace(spChar,"&#146");
	description = description.replace(spChar,"&#146");
	msg = msg.replace(spChar,"&#146");
	
	var subject = "Demande partenaria pour "+sitename;
	var message = "Site : [url="+siteURL+"]"+sitename+"[/url]\nCatégorie : "+categorie+"\nBouton Pub : [img]"+buttonURL+"[/img]\n\n";
	message += "Description du site :\n"+description+"\n\nMessage du contact :"+msg ;
	
	submit.append("<input type='hidden' name='subject' value='"+subject+"'/>");
	submit.append("<input type='hidden' name='message' value='"+message+"'/>");
	submit.trigger('submit');
});

/*---------------------------------------------
	Plugin : Tag des titre de sujet
---------------------------------------------*/
jQuery("a.topictitle").each(function(i){
	var title = jQuery(this);
	var string = title.html();
	
	string = string.replace(/\[r[eé]solu\]/i,"<img src='http://storage.web64.fr/smileys/bouton/resolu.png'/>");
	string = string.replace(/\[tutoriel\]/i,"<img src='http://storage.web64.fr/smileys/bouton/tuto.png'/>");
	string = string.replace(/\[en cours\]/i,"<img src='http://storage.web64.fr/smileys/bouton/encours.png'/>");
	string = string.replace(/\[astuce\]/i,"<img src='http://storage.web64.fr/smileys/bouton/astuce.png'/>");
	string = string.replace(/\[(.*)\]/ig,"<span class='tag'>$1</span>");
	
	title.html(string);
});

/*---------------------------------------------
	Censure positive
---------------------------------------------*/
$(".content").each(function(i){
	var string = $(this).html();
	
	string = string.replace(/\sforumactif/gi,"&nbsp;<b><a href='http://forum.forumactif.com' target='_blank'><font color='#00A5CD'>Forum</font><font color='#7CBA2C'>Actif</font></a></b>");
	string = string.replace(/\szsfa/gi,"&nbsp;<b><a href='http://zonescript.forumactif.com' target='_blank'>Zone Script <font color='#00A5CD'>Forum</font><font color='#7CBA2C'>Actif</font></a></b>");
	string = string.replace(/\sfdf/gi,"&nbsp;<b><a href='http://forum.forumactif.com' target='_blank'>Forum des Forums</a></b>");
	string = string.replace(/\scssa/gi,"&nbsp;<b><a href='http://www.css-actif.com/' target='_blank'><font color='#8FA5CE'>CSSActif</font></a></b>");
	string = string.replace(/\[php\]/gi,"<b><a href='http://php.net/manual/fr/index.php' target='_blank'>PHP</a></b>");
	string = string.replace(/\sgoogle chrome/gi,"&nbsp;<b><a href='http://google.com/chrome/' target='_blank'><span style='color:#1849b5'>G</span><span style='color:#de3018'>o</span><span style='color:#edb800'>o</span><span style='color:#1849b5'>g</span><span style='color:#31b639'>l</span><span style='color:#de3018'>e</span> Chrome</a></b>");
	string = string.replace(/\sgoogle(?! chrome)/gi,"&nbsp;<b><a href='http://google.com' target='_blank'><span style='color:#1849b5'>G</span><span style='color:#de3018'>o</span><span style='color:#edb800'>o</span><span style='color:#1849b5'>g</span><span style='color:#31b639'>l</span><span style='color:#de3018'>e</span></a></b>");
	$(this).html(string);
});

/*--------------------------------------------
	Remplacement du règlement
--------------------------------------------*/
jQuery("a[href*='/register']").each(function(i){
	jQuery(this).attr("href","http://zonescript.forumactif.com/CGU-h1.htm");
});


/*--------------------------------------------
	Moddon
--------------------------------------------*/
jQuery("#modif_topic_title").attr("maxlength",120); //Unlimit change topic title

if(!document.getElementById('text_editor_textarea'))
{
	jQuery("#moddon").closest(".module").remove();
}

//Message
jQuery("#moddon_msgList").find(".moddon_msg").each(function(){
	var title = jQuery(this).attr("title");
	var newOption = "<option>"+title+"</option>";
	jQuery("#moddon_msgSelector").append(newOption);
});
jQuery("#moddon_msgGo").click(function(){
	var title = jQuery("#moddon_msgSelector").find("option:selected").html();
	var moddonMsg = jQuery("#moddon_msgList").find(".moddon_msg[title*="+title+"]").html();
	var message = jQuery("#text_editor_textarea").attr("value");
	message += moddonMsg;
	jQuery("#text_editor_textarea").attr("value",message);
});

//Tag
jQuery("#moddon_tagList").find("p").each(function(){
	var tag = jQuery(this).html();
	var newOption = "<option>"+tag+"</option>";
	jQuery("#moddon_tagSelector").append(newOption);
});
jQuery("#moddon_tagGo").click(function(){
	var tag = jQuery("#moddon_tagSelector").find("option:selected").html();
	var title = jQuery("#modif_topic_title").attr("value");
	title = "["+tag+"]"+title;
	jQuery("#modif_topic_title").attr("value",title);
});

//Censure rapide
var censureButtom = "<input type='button' value='Censure' class='moddon_censure' />";
jQuery("a[href*='mode=editpost']").parent().append(censureButtom);
jQuery(".moddon_censure").click(function(){
	var post = jQuery(this).parent().find("a[href*='mode=editpost']").attr("href");
	var catcher = /mode=editpost&p=([0-9]*)/i;
	post = post.replace(catcher,"$1");
	var message = (jQuery("#moddon_censure").html()) +"";
	var form = "<form name='moddon_temp' method='POST' action='http://zonescript.forumactif.com/posting.forum'></form>";
	jQuery("body").append(form); form = jQuery("form[name='moddon_temp']") ;
	var temp = "<input type='hidden' name='mode' value='editpost'/>";
	temp += "<input type='hidden' name='p' value='"+post+"'/>";	
	temp += "<input type='hidden' name='message' value='"+message+"'/>";
	temp += "<input type='hidden' value='Prévisualiser' name='preview' /> ";
	form.append(temp + post);
	form.trigger('submit');
});

//Crédit
var credit = "<div style='font-size:8;font-style:italic;text-align:center;margin-top:5px;'>Addon distribué par<br/><a href='http://zonescript.forumactif.com' target='_blank'>la Zone Script ForumActif</a></div>";
jQuery("#moddon").append(credit);


});

