var currNum = -1;
var ids = new Array();
ids[0] = "rest";
ids[1] = "news";
ids[2] = "events";
ids[3] = "menus";
ids[4] = "bios";
ids[5] = "priv";
ids[6] = "ret";
ids[7] = "gal";
ids[8] = "sus";
ids[9] = "dir";
ids[10] = "cont";
var bio = 0;
var menus = 1;
var rest = 1;
var gal = 1;
var priv = 1;
$(document).ready(function() {
  var left = ($(window).width() - 750) / 2;
  $("#ajaxCont").css("left", left + "px");
  slide(0);
  $.get("news.php", { "total" : true }, function(data) {
    $("#totalPages").val(data);
  });
  $.get("vid_ajax.php", { "total" : true }, function(data) {
    $("#vidTotalPages").val(data);
  });
  $.get("events_ajax.php", { "total" : true }, function(data) {
    $("#eventTotalPages").val(data);
  });
});
function slide(num) {
  if (num == currNum)
    return;
  if (currNum == -1) {
    num = 0;
    currNum = 0;
  }
  var left = -(num * 772);
  if (num == 0) {
    $("#rest_frame1").fadeIn('slow');
    $("#rest_frame2").hide();
    $("#rest_frame3").hide();
    $("#rest_frame4").hide();
    $("#rest_frame5").hide();
    $("#rest_frame6").hide();
    rest = 1;
  }
  if (num == 3) {
    $("#menus_frame2").hide();
    $("#menus_frame3").hide();
    $("#menus_frame4").hide();
    $("#menus_frame5").hide();
    $("#menus_frame1").show();
    menus = 1;
  }
  if (num == 4) {
    $("#bios_frame1").hide();
    $("#bios_frame2").hide();
    $("#bios_frame3").hide();
    bio = 0;
  }
  if (num == 5) {
    $("#priv_frame2").hide();
    $("#priv_frame3").hide();
    $("#priv_frame4").hide();
    $("#priv_frame5").hide();
    $("#priv_frame1").show();
    priv = 1;
  }
  if (num == 7) {
    $("#gal_frame2").hide();
    $("#gal_frame1").show();
    gal = 1;
  }
  $("#" + ids[currNum] + "_sub").fadeOut("fast", function() {
    $("#" + ids[currNum] + "_bg").fadeOut("fast");
    $(".divrestMove").animate({ left: left + "px" }, 400, "linear", function(){
      $("#" + ids[num] +"_sub").fadeIn("slow");
      $("#" + ids[num] +"_bg").fadeIn("slow");
      if (num == 1)
        pagination(1);
      if (num == 2)
        eventsPagination(1);
      //$("#" + ids[num] +"_bg").fadeTo("slow", 0.7);
      currNum = num;
    });
  });
}
function swapBio(num) {
  if (bio > 0) {
    $("#bios_frame" + bio).fadeOut('fast', function() {
      $("#bios_frame" + num).fadeIn('slow');
    });
  }
  else
    $("#bios_frame" + num).fadeIn('slow');
  bio = num;
}
function swapRest(num) {
  $("#rest_frame" + rest).fadeOut('fast', function() {
    $("#rest_frame" + num).fadeIn('slow');
  });
  rest = num;
}
function swapMenus(num) {
  $("#menus_frame" + menus).fadeOut('fast', function() {
    $("#menus_frame" + num).fadeIn('slow');
  });
  menus = num;
}
function swapPriv(num) {
  $("#priv_frame" + priv).fadeOut('fast', function() {
    $("#priv_frame" + num).fadeIn('slow');
  });
  priv = num;
}
function swapGal(num) {
  $("#gal_frame2").fadeIn('slow');
  $("#gal_frame" + gal).fadeOut('fast', function() {
    $("#gal_frame" + num).fadeIn('slow');
  });
  if (num == 2)
    vidPagination(1);
  gal = num;
}
function pagination(page) {
  $("#news_bg").html("<div class=\"ajax_loader\"></div>");
  $(".ajax_loader").fadeIn('fast');
  $.get("news.php", { "page" : page, "total_pages" : $('#totalPages').val() }, function(data) {
    $(".ajax_loader").fadeOut('fast');
    $("#news_bg").html(data);
    $(".cont_news").fadeIn('slow');
  }, "html");
}
function vidPagination(page) {
  $("#vid_ajax").html("<div class=\"vidAjax_loader\"></div>");
  $(".vidAjax_loader").fadeIn('fast');
  $.get("vid_ajax.php", { "page" : page, "total_pages" : $('#vidTotalPages').val() }, function(data) {
    $("#vid_ajax").fadeOut('fast', function() {
      $(this).html(data);
      $(this).fadeIn('slow');
    });
  }, "html");
}
function eventsPagination(page) {
  $("#events_bg").html("<div class=\"eventsAjax_loader\"></div>");
  $(".eventsAjax_loader").fadeIn('fast');
  $.get("events_ajax.php", { "page" : page, "total_pages" : $('#eventTotalPages').val() }, function(data) {
    $(".eventsAjax_loader").fadeOut('fast');
    $("#events_bg").html(data);
    $(".cont_events").fadeIn('slow');
  }, "html");
}
function moreNews(id) {
  $("#loader").show();
  $("#ajaxCont").fadeIn('slow', function() {
    $.get("moreNews.php", { 'id' : id }, function(data) {
      $("#ajaxContHolder").html(data);
        $("#loader").hide();
        $("#ajaxCont").animate({ "width" : "750px", "min-height" : $("#ajaxContHolder").height() + 10 }, 'slow', 'swing', function() {
          $("#ajaxContHolder").fadeIn("slow");
      });
    });
  });
}
function hideMoreNews() {
  $("#ajaxCont").hide();
  $("#ajaxContHolder").hide();
  $("#ajaxCont").css("width", "");
  $("#ajaxCont").css("min-height", "");
}
function printNews(page) {
  window.open('http://rmseafood.com/news_print.php?page=' + page + ' &total_pages=' + $('#totalPages').val() + '&print=true', 'News, Page: $page', 'height=300, width=200, location=no');
}
