(function($) {
$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
	});
};
})(jQuery);

var Order="ascending";
jQuery.noConflict();

jQuery(document).ready(function(){
	var fontSize=12;
	var lineHeight=1.3;
	jQuery("#FontPlus").click(function(){
		fontSize++;
		lineHeight+=0.1;
		jQuery("#dzarticleBody > *").css("font-size",fontSize+"pt");
		jQuery("#article_holder div#article_body").css("line-height",lineHeight+"em");
	});
	jQuery("#FontMinus").click(function(){
		fontSize--;
		if (lineHeight>1.3)
			lineHeight-=0.1;
		jQuery("#dzarticleBody > *").css("font-size",fontSize+"pt");
		jQuery("#article_holder div#article_body").css("line-height",lineHeight+"em");
	});
jQuery("#EmailTheAuthor").click(function(){
jQuery("#ContactForm").slideToggle("slow");
});

});

function dzCommentSort(dir){
	if(dir=="ascending" && Order!="ascending") {
		jQuery('#comment_list > div.comment_holder').reverseOrder();
		Order="ascending";
	}
	else if(dir=="descending" && Order!="descending"){
		jQuery('#comment_list > div.comment_holder').reverseOrder();
		Order="descending";
	}
}

function contact(){
    jQuery("#dzsend").html("<img src='images/loading.gif'>");
    jQuery("#dzmsg").slideUp("fast");
    var inputs=jQuery("#ContactFormR").serialize();
    jQuery.ajax({
        url:'/ara/send.php',
        type:'post',
        data:inputs,
        success:function(content) {
            if (content == 'ok') {
                jQuery("#dzmsg").removeClass();
                jQuery("#dzmsg").addClass("success", 1000);
                jQuery("#dzmsg").html("شكرا لك، رسالتك وصلت الى الكاتب");
                jQuery("#dzmsg").slideDown("fast");
                jQuery("#dzsend").html("<input class='button' value='أرسل' type='button' onclick='contact()'>");
                clear("#ContactFormR");
            }
            else {
                jQuery("#dzmsg").removeClass();
                jQuery("#dzmsg").addClass("error", 1000);
                jQuery("#dzmsg").html(content);
                jQuery("#dzmsg").slideDown("fast");
                jQuery("#dzsend").html("<input class='button' value='أرسل' type='button' onclick='contact()'>");
            }
        }
    });
    return false;
}
function clear(form) {
	jQuery(form).find(':input').each(function() {
		switch(this.type) {
		    case 'password':
		    case 'text':
		    case 'textarea':
		        jQuery(this).val('');
		        break;
		}
	});
}
