$(function () {

  // Variables

  $.config = {
    sequence : 0,
    section : "",
    subSection : "",
    offer : 0,
    offersMax : $("#offers .offer").size()
  }
  
  
  // Data
   
   $.config.section = $("body").attr("class");
   $("#data .section").css({ display : "none"});
   $("#data .section." + $.config.section).css({ display : "block"});
   
  // Canvas

  $(".shoploader").hide();
  $(".fileUploading").hide();
  
  if($("body").attr("post") == "false") {
    $("#canvas").hide();
    $("#header").hide();
    $("#content").hide();
    $("#footer").hide();
    $(".flash").hide();
    setInterval(function () {
      $.config.sequence ++;
      if($.config.sequence == 3) {
        $("#canvas").fadeIn(1500);
      }
      if($.config.sequence == 7) {
        $("#header").fadeIn(800);
        $("#content").fadeIn(800);
        $("#footer").fadeIn(800);
        $(".flash").show(10);
      }
    }, 500);
  };
  
  // Upload File Button
  
  $("#uploadFileButton").click(function () {
    $(".fileUploading").fadeIn(300);
  });
  
  // Offers
  
  setInterval(function () {
    $.config.offer ++;
    $.config.offer = $.config.offer > $.config.offersMax - 1 ? 0 : $.config.offer;
    $("#offers .list").animate({ left: -$.config.offer * 260 }, { duration: 600, easing: "easeOutBack" });
  }, 3000);
  
  // Search
  
  $("#searchinput").focus(function() {
    $(this).val("");
  });
  
  // Navigation
  
  $("#meta ul li a").click(function () {
    $("#meta ul li").removeClass("active");
    $.config.section = $(this).parent().attr("class");
    $(this).parent().addClass("active");
    $("#data .section").css({ display : "none"});
    $("#data .section." + $.config.section).css({ display : "block"});
    $("body").attr("class", $.config.section);
    return false;
  });
    
  // Sub-Navigation
  
  $("div.section div.image a").each(function () {
    if(!$(this).hasClass("active")) {
      $(this).css({ display : "none" });
    }
  });
  
  $("div.section li").mouseover(function () {
    $("div.section." + $.config.section + " li").removeClass("active");
    $.config.subSection = $(this).attr("class");
    $(this).addClass("active");
    $("div.section." + $.config.section + " div.image a").css({ display : "none" });
    $("div.section." + $.config.section + " div.image a." + $.config.subSection).css({ display : "block" });
  });
  
  $("div.section li a").click(function () {
    $(".shoploader").fadeIn(300);
  });
  
  $(".offer a").click(function () {
    $(".shoploader").fadeIn(300);
  });
  
  // EOF
})