//----------------------------------
// Document is ready for some JQuery
//----------------------------------
$(document).ready(function() {
  $.preloadCssImages();
  //----------------------------------------------------
  // Footer Slide-Up
  // The code below shows and hides the footer nav
  //----------------------------------------------------
    var container = $( "#container" );
    var href = window.location.pathname;
    var dir = href.replace(/\//g,'');//remove all forward slashed
    //alert(dir);
    if(dir=='direct_mail' || dir=='web_design' || dir=='print' || dir=='identity' || dir=='comps'){
      if (container.is( ":visible" )){
      // Hide - slide up.
        container.slideUp( 1000 );
      } else {
         // Show - slide down.
         container.slideDown( 1000 );
      }
    }
    
  //----------------------------------------------------
  // Preload Images
  //----------------------------------------------------
    jQuery.preLoadImages("home-hover.png", "http://www.bellhausdesign.com/images/nav/home-hover.png");
    jQuery.preLoadImages("work-hover.png", "http://www.bellhausdesign.com/images/nav/work-hover.png");
    jQuery.preLoadImages("about-hover.png", "http://www.bellhausdesign.com/images/nav/about-hover.png");
    jQuery.preLoadImages("contact-hover.png", "http://www.bellhausdesign.com/images/nav/contact-hover.png");
    

    //-------------------------------------------------
    // Main Navigation redirects
    //-------------------------------------------------
    $("ul.topnav li.home").click(function(){
      window.location = "http://www.bellhausdesign.com/";
    });
	
    $("ul.topnav li.work").click(function(){
      window.location = "http://www.bellhausdesign.com/work/";
    });
    
    $("ul.topnav li.work-on").click(function(){
      window.location = "http://www.bellhausdesign.com/work/";
    });
	
    $("ul.topnav li.about").click(function(){
      window.location = "http://www.bellhausdesign.com/about/";
    });

    
    //-------------------------------------------------
    // Sub Navigation redirects
    //-------------------------------------------------
    $("ul.subnav li.web").click(function(){
      window.location = "http://www.bellhausdesign.com/work/web/";
    });
	
    $("ul.subnav li.print").click(function(){
      window.location = "http://www.bellhausdesign.com/work/print/";
    });
	
    $("ul.subnav li.identity").click(function(){
      window.location = "http://www.bellhausdesign.com/work/identity/";
    });
    
    $("ul.subnav li.direct_mail").click(function(){
      window.location = "http://www.bellhausdesign.com/work/direct_mail/";
    });
    
    $("ul.subnav li.comps").click(function(){
      window.location = "http://www.bellhausdesign.com/work/comps/";
    });
    
    //-------------------------------------------------
    // BACK redirect
    //-------------------------------------------------
    $("ul.info li#back").click(function(){
      window.location = "http://www.bellhausdesign.com/work/"+$(this).attr('rel')+"/";
    });
    
    //-------------------------------------------------
    // IMAGE NAVIGATION
    //-------------------------------------------------
    $("ul.nav li").click(function(){
      
      var image=$(this).attr('id');
      //alert("image:"+image);
      var cat=$("ul.nav").attr('id');
      $("#info_image").attr("src", "../../images/work/"+cat+"/"+image+".jpg");
    });

});


//----------------------------------------------------
// Function for Preloading images.
// Called at the top of the script
//----------------------------------------------------
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
