$(document).ready(function(){
	Wd.Frontend.init();      			
});

Wd = (typeof(Wd) == 'undefined') ? {} : Wd;
Wd.Frontend = new function(){

  var self = this;

  this.init = function(){};

  this.highlightNavigation = function(nav_selector){
    if(location.pathname){
      var base = location.pathname.split("/")[1]
      if(base){
        $(nav_selector).find("a[href^='/"+base+"']").parents('li').addClass('WdNavigationActive');
      }
      else{
        $(nav_selector).find('li:first-child').addClass('WdNavigationActive');
      }
    }
  }

  this.preloadImages = function(selector, callback){
    var callback = typeof(callback) != 'undefined' ? _callback : function(){};
    var imageList = [];
    var count = 0;
    var loading = false;
    $(selector).each(function(){
       imageList.push($(this).attr('href'));
    });
    var loadNext = function(){
      if(!loading){
        loading = true;
        count++;
        var pic = new Image();
        pic.onload = function(){
          loading = false;
          if(count >= imageList.length-1){
            clearInterval(loadInterval);
            callback;
          }
        }
        pic.src = imageList[count];
      }
    }
    var loadInterval = window.setInterval(loadNext, 50);    
  };
};
