	
$(document).ready(function()
{
	 jQuery('a[rel*=facebox]').facebox();

   
	  $(".edit-prayer-times").click(function()
	  {
		  var id =  $(this).attr("id");
		  var term = $("#prayertable-time").val();
		  var prayermonthid = $("#prayermonthid").val();
		$.ajax({
		  type: "GET",
		  url: "/cms/prayertimes.php?action=edit-single",
		  data: "id="+id+"&term="+term+"&prayermonthid="+prayermonthid,
		  success: function(response)
		  {
			$("#selected-prayer").html(response);
			$("#selected-prayer-info").show();
			$("#starttime").focus();
		  }
		});
		  return false;
	  });
	  

     

	  
	 $(".remove-single").click(function()
	  {
		  var id =  $(this).attr("id");
		  if (confirm("Are you sure you want to remove this prayer time permanently?"))
		  {
			  makeAjaxCall("GET","/cms/prayertimes.php","action=remove-single&id="+id,function(response)
			  {
				$("#row-"+id).remove();
				setSuccessMessage("Prayer time succesfully removed");
			  });
		  }
		  
		  return false;
	  });
	  
  
   
	  function setSuccessMessage(msg)
	  {
		$("#message-holder").show();
		$("#ok-message").html("<li>"+msg+"</li>");
	  }
	 
	 function makeAjaxCall(type,target,data,callback)
	 {
	 	$.ajax(
		{
		  type: type,
		  url: target,
		  data: data,
		  success: function(response)
		  {
			return callback(response);
		  }
		});
	 
	 }

	// Announcements
	headline_count = $("div.headline").size();
    $("div.headline:eq("+current_headline+")").css('top', '5px');

    headline_interval = setInterval(headline_rotate,5000);
    $('#scrollup').hover(function() {
       clearInterval(headline_interval);
     }, function() {
      headline_interval = setInterval(headline_rotate,5000);
      headline_rotate();
    });
});

function checkSinglePrayerForm()
{
	var starttime = $("#starttime").val();
	var jamaat = $("#jamaat").val();
	var errormessage = "";
	var OK = true;
	if (isNaN(starttime) || starttime == "")
	{
		errormessage += "<li>Start time must be a valid prayer time</li>";
		OK = false;
	}
	
	if (isNaN(jamaat) || jamaat == "")
	{
		errormessage += "<li>Jamaat must be a valid prayer time</li>";
		OK = false;
	}
	if (!OK)
	{
		$("#error").html(errormessage);
		$("#message-holder").hide();
	}
	return OK;
}

/*************************** ANNOUNCEMENTS **********************/
      var headline_count;
      var headline_interval;
      var old_headline = 0;
      var current_headline = 0;


      function headline_rotate() {
        current_headline = (old_headline + 1) % headline_count;
        $("div.headline:eq(" + old_headline + ")")
          .animate({top: -205},"slow", function() {
            $(this).css('top', '210px');
          });

        $("div.headline:eq(" + current_headline + ")")
          .animate({top: 5},"slow");  
        old_headline = current_headline;
      }

	
	     function PageLoadedEventHandler() {  
      if(YAHOO.music.WebPlayer.loaded){        
        YAHOO.music.WebPlayer.clear();        
        YAHOO.music.WebPlayer.scrape();  
      }  
   }
   

	
	
