function do_menu(el1, el2)
{
  $(el1).each(function()
  {
      $(this).unbind('mouseout').unbind('mouseover').unbind('click').bind('click', function()
      {   $('.selectedtab').removeClass('selectedtab');
          if($(this).find(el2).css("display") == 'none')
          {
              $(el2).slideUp();
              $('.tabs_hover').removeClass('tabs_hover');
              $(this).addClass('selectedtab').find(el2).css({top: ($(this).offset().top + $(this).height() + 6) + 'px', left: ($(this).offset().left - 1) + 'px'}).slideDown();
          }
          else
          {

              $(el2).slideUp();
          }
      }).bind('mouseover', function()
      {
            if(!$('.selectedtab').html())
            {
                $(this).addClass('tabs_hover');
            }
      }).bind('mouseout', function()
      {
            $(this).removeClass('tabs_hover');
      });
  });
}


function do_load(dothat)
{

    $("#salah").html('<img src="images/loading.gif" alt="" />');
    $("#dates").html('<img src="images/loading.gif" alt="" />');
    $("#weatherd").html('<img src="images/loading.gif" alt="" />');

    $("#hidden_data").load('req.php?do=turnip', {limit: 25}, function()
    {
        $("#selected_country").each(function()
        {
            this.src = "flags/" + $("#hidden_data").html() + ".gif";
        });
        $("#weatherd").load('req.php?do=get_weatherd', {limit: 25}, function()
        {
            if(this.innerHTML == "false2" || this.innerHTML == 'outofrange')
            {
                $("#weatherd").hide();
                $("#spweatherd").hide();
            }
            else
            {
                $("#weatherd").show();
                $("#spweatherd").show();
            }
            $("#salah").load('req.php?do=salah', {limit: 25}, function()
            {
                if(this.innerHTML == "false2" || this.innerHTML == 'outofrange')
                {
                    $("#salah").hide();
                    $("#spsalah").hide();
                }
                else
                {
                    $("#salah").show();
                    $("#spsalah").show();
                }

                $("#dates").load('req.php?do=dates', {limit: 25}, function()
                {
                    do_menu("#tbl td .tabs", ".menus");
                });
            });
        });
    });


}

function other_country(typ)
{
    $("#selected_country").each(function()
    {
        this.src = "flags/" + typ + ".gif";
         $("#salah").html('<img src="images/loading.gif" alt="" />');
        $("#dates").html('<img src="images/loading.gif" alt="" />');
        $("#weatherd").html('<img src="images/loading.gif" alt="" />');
        $("#hidden_data").load('req.php?do=turnip&newcountry=' + typ, {limit: 25}, function()
        {
            do_load();
        });
    });
}

$(document).ready(function()
{
   $("#flags__").load('req.php?do=loadflags');
   do_load();
});
