//jQuery
$(document).ready(function() {
	//Auto complete off
	$("input.autocomplete-off").attr("autocomplete", "off");
	//Navigation
	$(".main-nav .middle ul li.submenu")
        .mouseover(function() {
			$.fdvars.currentNav = $("#sitenav").find(".sub-nav-display").hide().parent();
			$.fdvars.currentNav.removeClass("current");
			//Hide Old Nav
			//$.fdvars.currentNav.find(".sub-nav-display").hide();
			//Show Current Nav
			if (!$(this).hasClass("first")) {
				$(this).addClass("current");
			}
			$("#sitenav ."+$(this).attr("nav")).show();
			
        })
        .mouseout(function() {
			//Hide Current Nav
			$(this).removeClass("current");
			$("#sitenav ."+$(this).attr("nav")).hide();
           	//Show Old Nav
			if (!$.fdvars.currentNav.hasClass("first")) {
				$.fdvars.currentNav.addClass("current");
			}
			$("#sitenav .sub-nav-display").show();
    });
	//Input With Default Value
	$(".inputDefault").focus(function(){
		if(this.value===this.defaultValue){
			this.value="";
		}else{
			this.select();
		}
	});
	$(".inputDefault").blur(function(){
		if(jQuery.trim(this.value)===""){
			this.value=(this.defaultValue?this.defaultValue:"")
		}
	});
	//Search
	$(".search .glass").click(function(){
		$(".search form").submit();
	});
	//Widget
	$(".title-fix").each(function() {
		var title = $(this).find("h3");
		var widths = $(this).outerWidth()-parseInt(title.css("padding-left"));
		if($(this).find(".likes-count").length) {
			var likes = $(this).find(".likes-count");
			widths -= likes.outerWidth()+parseInt(likes.css("margin-left"))+1;
		} else if($(this).find(".count").length) {
			var count = $(this).find(".count");
			widths -= 100;//count.outerWidth()+parseInt(count.css("margin-left"))+1;
		}
		title.css({width:widths});
	});
	//Writer
	$(".homepage-writers .inner").each(function() {
		var separator = $(this).find(".separator");
		separator.css({height:$(this).outerHeight()});
	});
	$(".writer-row-container-inner").each(function() {
		var separator = $(this).find(".writer-row-separator");
		separator.css({height:$(this).outerHeight()-(parseInt(separator.css("margin-top"))+parseInt(separator.css("margin-bottom")))});
	});	
	//Toggle
	$(".toggle").click(function(e) {
		e.preventDefault();
		var div = $($(this).attr("data-div"));
		if ($(".write-first-comment").length>0) {
			var write_first_comment = $(".write-first-comment");
			write_first_comment.toggle();
		}
		if (div.is(":hidden")) {
			div.fadeIn();
		} else {
			div.fadeOut();
		}
	});
	//Hadith Terms Dictionry
	if ($(".term-row-container").length>0) {
		var hadith_term_number_w = 0;
		var hadith_term_number_padding = 0;
		$(".term-row-container .term-row .inner .detail").each(function() {
			var number = $(this).find("span.number");
			var w = parseInt(number.width());
			hadith_term_number_padding = parseInt(number.css("paddingRight"));
			hadith_term_number_w = Math.max(hadith_term_number_w, w);			
		});
		$(".term-row-container .term-row .inner .detail span.number").css({"width":hadith_term_number_w+"px"});		
		$(".term-row-container .term-row .inner .detail div.description").css({"paddingLeft":(hadith_term_number_w+hadith_term_number_padding)+"px"});		
	}
	//Protect E-mail
	$("span.protect-email").each(function() {
		var txt = $(this).html().split(",");
		var at = String.fromCharCode(64);
		$(this).html("<a href=\"mailto:"+txt[0]+at+txt[1]+"\">"+txt[2].replace("[at]", at)+"</a>");
	});
	//Rounded Image Radius
	$('img.rounded').each(function() {
		var img = $(this);
		img.css("border-radius", img.attr("radius")+"px");
		img.css("-moz-border-radius", img.attr("radius")+"px");
		img.css("-webkit-border-radius", img.attr("radius")+"px");
		img.css("-khtml-border-radius", img.attr("radius")+"px");		
	});
	//Disable Right Click
	$('img.disable-right-click').each(function() {
		$(this).bind("contextmenu", function(e) {e.preventDefault()});
	});
});
