function showbox(elmnt) {document.getElementById('hiddencats').style.display = 'block';} 
function hidebox() {document.getElementById('hiddencats').style.display = 'none';}
function fixURL() {parts = window.location.href.split("#/");if(parts.length > 1) {window.location.href = parts[parts.length - 1];}}
function changeURL(href) {href = (href == "") ? "/" : href;uri = window.location.href.split("#/");window.location.href = uri[0] + "#/" + href;}

if(typeof jQuery == "function") {
	jQuery(document).ready(function($) {
		fixURL();
		jQuery(".af-menu").megamenu();
		jQuery("#arsip-post").css("display", "block");
		$("#mTab" ).tabs({ selected: 0 });
		init(jQuery, "body");
	});
	function init($, id) {
		id = (typeof(id) == 'undefined') ? "body" : id;
		
		$(".morecomments a").click(function() {
			href = $(this).attr('href');
			uri = href.split("#")[0];
			
			stylesheet_uri = $("link[rel='stylesheet']:eq(0)").attr("href").split("/");
			stylesheet_uri.length--;
			img = "<img src='"+stylesheet_uri.join("/") + "/images/indicator_small.gif"+"' alt='Loading' style='padding-left:15px;' />";
			$(this).html("Tampilkan seluruhnya" + img);
			$("div#comments").parent().load(uri + " #commentlist");
			//$(this).parent().html(img).parent().load(uri + " div#comments #commentlist");
			return false;
		});
		
		$("a.respondlink").click(function() {
			post_id = $(this).attr('id').split("-")[1];
			if(typeof(post_id) != "undefined") {
				$("div.single").css("display", "none");
				$("#comment_form").css("display", "block");
				$("#comment_form .focus:first").focus();
			} else {
				$(".respondtext").parent().css("display", "none");
				$("div#comment_form").css("display", "block");
				$("#commentform .focus:first").focus();
			}
			return false;
		});
		
		$(".respondtext").click(function() {
			$(this).parent().css("display", "none");
			if($(this).hasClass("single")) {
				$("a.respondlink").click();
			} else {
				$(this).parent().prev().prev().children("a.respondlink").click();
			}
		});
		$("#batal").click( function() {
			$("#comment_form").hide();
		});
		
		site = $("meta[name='home']").attr("content");
		dashboard = $("meta[name='url']").attr("content") + "/wp-admin";
		wplogin = $("meta[name='url']").attr("content") + "/wp-login.php";
			
		$(id + " #mie-navigasi a").each(function() {
			if (
				$(this).attr('href') != '#' && //bukan utk link
				$(this).attr('href').indexOf(site) == 0 && //internal site
				$(this).attr('href').indexOf(dashboard) == -1 && //dashboard
				$(this).attr('href').indexOf(wplogin) == -1 && //menuju login
				$(this).attr('target') != '_blank' //target buka page baru
			) {
				$(this).click(function() {
					
					hrefs = $(this).attr("href").split("#");
					href = hrefs[0];			
					stylesheet_uri = $("link[rel='stylesheet']:eq(0)").attr("href").split("/");
					stylesheet_uri.length--;
					img = "<img src='"+stylesheet_uri.join("/") + "/images/load_2.gif"+"' alt='Loading' />";
					$('#load-nav').html('<div id="load">'+img+'</div>');
					$(".loop").animate({ opacity: 0.3 }, "slow");
					$("#arsip-post")
						.load(href + " #post-ajax", {}, function() {
							if($("#arsip-post").html() == "") {
								window.location.href = href;
								return false;
							}
						 					
						document.title = $("input[type='hidden'][name='title']").attr("value");
						//document.getElementById("udin").html = $("Dodol");
						site = (site.charAt(site.length - 1) == "/") ? site : site + "/";
						href = href.replace(site, "");
						if(hrefs.length > 1)
							href += "#" + hrefs[hrefs.length - 1];
						changeURL(href);
						init($, "#post-ajax"); //Kumpulin database	
							
						window.scrollTo(0,$("#container").position().top);
						$(".loop").animate({ opacity: 1 }, "slow");
						$('#load').remove();
					});
					//$("#container").focus();	
					return false;
				});					
			}
		});
		$('textarea').not(".respondtext").autogrow({
			minHeight: 70
		});			
	}	
	
} // end if
