// JavaScript Document

$(document).ready(function()
{

  resize();
  
  
  stribe.stribe1 = $(".stribe #stribe1");
  stribe.stribe2 = $(".stribe #stribe2");
  setInterval ( "moveStribe()", 50 );
  setInterval ( "newIcon()", 5000 );
  setTimeout( "setInterval ( 'hideIcon()', 5000 )", 2000);
  
  setSplats();
  
  $(".lightbox").lightbox({
          loopImages: true,

            imageClickClose: true,

            disableNavbarLinks: true
    


        });
  
  $(".mSubmenu").each(function()
                      {
                        document.getElementById($(this).attr("id")).style.zIndex = "12";
                        
                      });
  


  
});

$(window).resize(function ()
{
  
  resize();
  
});


function setSplats()
{
  var h = $(".contentBack").height();
  var i = Math.floor(Math.random()*100);
  
  var imgIndex;
  
  while (i<(h-50))
  {
    imgIndex = Math.floor(Math.random()*5)+1;
    $(".panel")
      .append("<img src=\"/gfx/splat_l_0" + imgIndex + ".png\" class=\"splatL\" style=\"top: " + i + "px\" />");
    i += Math.floor(Math.random()*200+20);
  }
  
  
  
  
  i = Math.floor(Math.random()*100);
  while (i<(h-50))
  {
    imgIndex = Math.floor(Math.random()*5)+1;
    $(".panel")
      .append("<img src=\"/gfx/splat_r_0" + imgIndex + ".png\" class=\"splatR\" style=\"top: " + i + "px\" />");
    i += Math.floor(Math.random()*200+20);
  }
  
  
  
  //  Set icons
  icons.height = h = Math.floor((h-icons.offsetH)/85)*4;
  //alert(h*90);
  var top;
  
  i = Math.floor(Math.random()*5); // Where to set the first icon
  while (i<h)
  {
    imgIndex = Math.floor(Math.random()*icons.iconCount)+1;
    top = Math.floor(i/4);
    $(".panel")
      .append("<img src=\"" + icons.path + imgIndex + ".png\" class=\"icon\" style=\"top: " + (top*85+icons.offsetH) + "px; left: " + ((i-top*4)*85+12) + "px\" />");
    i += Math.floor(Math.random()*10);
  }
  icons.icons = $(".panel .icon");
  icons.current = $(icons.icons[Math.floor(Math.random()*icons.icons.length)]);
}



function newIcon()
{
  $(icons.current)
    .fadeIn("slow", function ()
      {
      }
    );
}

function hideIcon()
{
  icons.current = $(icons.icons[Math.floor(Math.random()*icons.icons.length)]);
  $(icons.current).fadeOut("slow", function ()
    {
  
      var i = Math.floor(Math.random()*icons.height);
      var top = Math.floor(i/4);

      $(this).css("top", (top*85+icons.offsetH) + "px");
      $(this).css("left",((i-top*4)*85+12) + "px");
      $(this).attr("src", icons.path + (Math.floor(Math.random()*icons.iconCount)+1) + ".png");
    }
  );
}

function resize ()
{
  var offset = Math.round($(".headerBack").width()/2);
  offset = offset - 960;
  if (offset<-697) offset=-697;
  //alert(":" + offset);
  $(".headerBack").css("background-position", "" + offset + "px 0");
  $(".footerBack").css("background-position", "" + offset + "px 0");
  
  
}

function moveStribe()
{
  stribe.pos -= 1;
  
  if (stribe.pos<-stribe.width)
  {
    stribe.pos = stribe.pos+stribe.width;
    var o = stribe.stribe1;
    stribe.stribe1 = stribe.stribe2;
    
    
    $(o).attr("src", "/gfx/" + stribe.path + "/stribe" + Math.floor(Math.random()*4+1) + ".png");
    stribe.stribe2 = o;
    
    
  }
  
  $(stribe.stribe1).css("left", stribe.pos + "px");
  $(stribe.stribe2).css("left", (stribe.pos+stribe.width) + "px");

}
