$(document).ready(function()
{	
	//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
$("#secondpane h4.menu_head").click(function()
{
   $(this).css({backgroundImage:"url(images/top_small_bg.png)"}).next("div.menu_body").slideDown(500).siblings("div.menu_body").slideUp("slow");
   $(this).siblings().css({backgroundImage:"url(images/top_small_bg.png)"});
});

		$('#defaultloadtab').slideDown(500);

				$('textarea.resizable:not(.processed)').TextAreaResizer();
				$('iframe.resizable:not(.processed)').TextAreaResizer();


//ratings
				$("a.vote_up").click(function(){
					var host = $('#host').val();
				 //get the id
				 the_id = $(this).attr('id');
				 
				 // show the spinner
				 $("#thespinner").show();
				 
				 //fadeout the vote-count 
				 $("span#votes_count"+the_id).fadeOut("fast");
				 
				 //the main ajax request
				  $.ajax({
				   type: "POST",
				   data: "action=vote_up&id="+$(this).attr("id"),
				   url: host + "/process/ratearticle.php",
				   success: function(msg)
				   {
				    $("span#votes_count"+the_id).html(msg);
				    //fadein the vote count
				    $("span#votes_count"+the_id).fadeIn();
				    //remove the spinner
				    $("#thespinner").hide();
				   }
				  });
				 });
				$("a.vote_down").click(function(){
					var host = $('#host').val();
				 //get the id
				 the_id = $(this).attr('id');
				 
				 // show the spinner
				 $("#thespinner").show();
				 //the main ajax request
				  $.ajax({
				   type: "POST",
				   data: "action=vote_down&id="+$(this).attr("id"),
				   url: host + "/process/ratearticle.php",
				   success: function(msg)
				   {
				  //  $("span#votes_count"+the_id).fadeOut();
				    $("span#votes_count"+the_id).html(msg);
				    $("span#votes_count"+the_id).fadeIn();
				    $("#thespinner").hide();
				   }
				  });
				 });
				 
});

$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};

var searchClassifieds = function(){
	var host = $('#host').val();
	var string = $('#search').val();
	if(string == ""){
		exit;
	}
	
	$.ajax({
	   type: "GET",
	   url: host + "/process/searchclassifieds.php",
	   data: "string=" + string,
	   ajaxSend: $('#loading').show(),
	   success: function(msg){
	   //	alert(div);
	     $('#searchresults').html(msg);
		$('#searchresults').slideDown();
		$('#loading').hide();
	   }
 });
}


var postClassifieds = function(){
	var host = $('#host').val();
	var string = $('#search').val();
	
	var title = $('#title').val();
	var category = $('#category').val();
	var description = $('#description').val();
	var contactname = $('#contactname').val();
	var contactnumber = $('#contactnumber').val();
	var profile = $('#profile').val();
	
		if(category == "blank"){
			alert("ކެޓަގަރީ ސެލެކްޓް ކުރައްވާ");
			exit;
		}
	
	$.ajax({
	   type: "POST",
	   url: host + "/process/postclassifieds.php",
	   data: "title=" + title + "&category=" + category + "&description=" + description +  "&contactname=" + contactname +  "&contactnumber=" + contactnumber +  "&profile=" + profile,
	   success: function(msg){
	   //	alert(div);
	     $('#posted').html(msg);
		$('#newclassified').slideUp();
		$('#posted').slideDown();
		
	   }
 });
}


 jQuery.timer = function (interval, callback)
 {
	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };

