$(document).ready(function() {
  $.ajaxSetup({
    cache    : true,
    dataType : 'json',
    timeout  : 12000,
    type     : 'POST',
    async    : false
  });

  load_mottos();
  load_project_thumbs();
    
});

function load_mottos(){
  $.ajax({
    url      : 'admin/index.php/mottos/list',
    success: function(json) {
      var html = [], h = -1;
      for(var motto,i=-1;motto=json[++i];)
        html[++h] = '<img src="' + motto['picture_url'] + '" />';
      $('#featured').html(html.join(''));
      
      orbit_mottos();
    }
  });
}
function orbit_mottos(){

  $('#featured').orbit({
    "animation" : "horizontal-push",
    animationSpeed: 300,                // how fast animtions are
    timer: true, 			 // true or false to have the timer
    advanceSpeed: 5000, 		 // if timer is enabled, time between transitions
    pauseOnHover: false, 		 // if you hover pauses the slider
    directionalNav: false 		 // manual advancing directional navs
  });
  
}


function load_project_thumbs(){
  $.ajax({
    url      : 'admin/index.php/homepageThumbnails/list',
    dataType : 'html',
    success: function(html) {
      $('#projectsThumbnails').html(html);
      do_captions();
    }
  });
}

function do_captions(){
  $('.project_thumb').hover(
    function() {
      $(this).find('div.caption').stop(false,true).fadeIn(0);
    },
    function() {
      $(this).find('div.caption').stop(false,true).fadeOut(0);
    });
}

