$(document).ready(function(){
	$.fn.clearForm = function() {
	  return this.each(function() {
	    var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
	      return $(':input',this).clearForm();
	    if (type == 'text' || type == 'password' || tag == 'textarea')
	      this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
	      this.checked = false;
	    else if (tag == 'select')
	      this.selectedIndex = -1;
	  });
	};
	$('ul.mainmenu').accordion({
			active: false,
			header: '.head',
	    autoheight: false,
	    alwaysOpen: false
	});
	if ($('#tentangkami').length >0)
	{
		$('#tentangkami').accordion({
			  header: 'h3.title',
		    autoheight: false,
		    alwaysOpen: false
		});
	}
	if ($('.b2t').length>0)
	{
		$(".b2t").click(function(){
			$.scrollTo('.head',800,{easing:'easeinout'});
			return false;
		})
	}
	if ($('#tokoh').length>0){
		$.scrollTo('#tokoh',800,{easing:'easeinout'});
	}
	if ($('#komentar').length>0){
		$.scrollTo('#komentar',800,{easing:'easeinout'});
	}
  if ($(".cellmod").length > 0)
  {
    $(".cellmod .button").click(function() {
      zz = $(".cellmod select option:selected").attr('value');
      if (zz=='cari') return false;
      location.href = '/network-modernisator/organisasi/'+zz;
    });
  }
  if ($(".contrib").length > 0)
  {
    $(".contrib .button").click(function() {
      zz = $(".contrib select option:selected").attr('value');
      if (zz=='cari') return false;
      location.href = '/network-modernisator/individual/'+zz;
    });
  }
  if ($(".pilih").length > 0)
  {
    $(".pilih .button").click(function() {
      zz = $(".pilih select option:selected").attr('value');
      if (zz=='cari') return false;
      location.href = '/acara/'+zz;
    });
  }
  if ($(".blogcat, .blogarc").length > 0)
  {
    $(".blogcat, .blogarc").change(function() {
      zz = $(this).children("option:selected").attr('value');
      if (zz=='cari') return false;
      document.location.href = '/' + zz;
    });
  }
	$("form#com_post").submit(function()
	{
		clss = $(this).attr('class');
		if (clss=='artikel')
		{
			stype = 'ar';
		}
		else if (clss=='news')
		{
			stype = 'nw';	
		}
		else if (clss=='event')
		{
			stype = 'ac';
		}
    $.ajax({
			url : '/commentpost',
			type : 'post',
			data : {out  : 'ajax',
							tipe : stype,
							uid  : $("#com_post [@name=uid]").val(),							
							msgs : $("#com_post [@name=msgs]").val(),
							odd  : $("#com_post [@name=odd]").val(),
							origin  : $("#com_post [@name=origin]").val(),							
							csrf_token : $("#com_post [@name=csrf_token]").val()},
			dataType: 'html',
			success: function(data) {
				if ($("[@name=odd]").val()==0)
				{
					$("[@name=odd]").val(1);
				}
				else
				{
					$("[@name=odd]").val(0);
				}
				$("form#com_post [@name=msgs]").val('');
				$('#comlist').append(data).children('p:last').slideDown('slow');
 			}
		})
 		return false;
	});
	$("form#shout_post").submit(function()
	{
    $.ajax({
			url : '/blogshout',
			type : 'post',
			data : {
							out: 'ajax',
							blogperson : $("#shout_post [@name=blogperson]").val(),
							username : $("#shout_post [@name=username]").val(),
							msgs   : $("#shout_post [@name=msgs]").val(),
							website : $("#shout_post [@name=website]").val(),
							shout_token : $("#shout_post [@name=shout_token]").val()},
			dataType: 'html',
			success: function(data) {
    		var blue = '#f33';
				$("form#shout_post").clearForm();
				$('#shouts').prepend(data).children('li:first').slideDown('slow');
 			}
		})
 		return false;
	});
  if ($('.gallery').length > 0)
  {
    $('.gallery a').lightBox();
  }

	if ($('#login_error').length>0)
	{
		alert("Login/password anda salah.");
	}
})
