$(document).ready(function()
{
  jQuery.easing.easeOutQuart = function (x, t, b, c, d) {return -c * ((t=t/d-1)*t*t*t - 1) + b;};
  
  var slideshow = $(".crosslide");
  if(slideshow.html() != null)
  {
    if(slideshow.find('li').size() > 1) slideshow.crossfade({interval: 5000});
  }
  
  
  /*
  if($('.campaign').html() != null)
  {
    if($('.campaign').length > 1)
    {
      $('.campaign').each(function()
      {
        campaignNav = $(document.createElement("div")).attr("class","nav").appendTo($(this).find('.description'))
        
        if(!$(this).is(':first-child'))
        { 
          var prevID = $(this).prev().attr('id');
          var up = $(document.createElement("a")).attr("class","up").attr("href", "#" + prevID).html("prev campaign").appendTo(campaignNav);
          up.click(function(event){event.preventDefault(); $.scrollTo($(this).parent().parent().parent().prev(), 'slow', {onAfter: function(){window.location = '/news-room/#' + prevID;}})})
        }
    
        if(!$(this).is(':last-child'))
        {
          var nextID = $(this).next().attr('id');
          var down = $(document.createElement("a")).attr("class","down").attr("href", "#" + nextID).html("next campaign").appendTo(campaignNav);
          down.click(function(event){event.preventDefault(); $.scrollTo($(this).parent().parent().parent().next(), 'slow', {onAfter: function(){window.location = '/news-room/#' + nextID;}})})
        }
      
        if(!$(this).is(':first-child'))
        {
          var firstID = $('.campaign').eq(0).attr('id');
          var top = $(document.createElement("a")).attr("class","top").attr("href", "#" + firstID).html("top").appendTo(campaignNav);
          top.click(function(event){event.preventDefault(); $.scrollTo($('.campaign').eq(0), 'slow', {onAfter: function(){window.location = '/news-room/#' + firstID;}})})
        }
      })
    }
    
  }
  */
  
  
  if($(".slideshow").html() != null)
  {    
    
    $('.slideshow').each(function()
    {
      var container = $(this);
      var slideshowWidth = container.width();
      container.wrapAll("<div class='slideshow'></div>");
      container.removeClass('slideshow').addClass('container');
      var slideshow = container.parent('.slideshow');
      var containerWidth = 0;
      container.find('li').each(function(){containerWidth += ($(this).width() + 5); $(this).css('float','left'); $(this).height(350); $(this).width(520)});
      slideshow.width(519).height(350).css('overflow','hidden');
      container.width(containerWidth).css('z-index',-1);
      
      if(container.find('li').length > 0)
      {
        slideshow.css('border','1px solid #666');
      }
      
      if(container.find('li').length > 1)
      {
        slideshow.css('cursor','pointer');
        if(container.hasClass('solo'))
        {
          var controller = $(document.createElement('div')).attr('class', 'controller').insertAfter(slideshow);
        }
        else
        {
          var controller = $(document.createElement('div')).attr('class', 'controller').appendTo(slideshow.parent().find('.description'));
        }
        
        prev = $(document.createElement("a")).attr("class","prev").attr("href", "#").html("< prev |").appendTo(controller);
        next = $(document.createElement("a")).attr("class","next").attr("href", "#").html(" next >").appendTo(controller);

        slideshow.serialScroll({
          items:'li',
          prev: prev,
          next: next,
          offset:0,
          start:0,
          duration:1200,
          force:true,
          stop:true,
          lock:false,
          cycle:true,
          easing:'easeOutQuart',
          jump: true
        });

        container.find('li img').parent().click(function(){container.trigger('next');})
      }
      
    });
    
  } 
  
/*
  $("#campaigns-list .body").hide()
  $(".campaign-read-more").toggle(function()
  {
    $(this).text("Hide Text");
    $(this).prev('.body').slideDown();
  },function()
  {
    $(this).text("Read More...")
    $(this).prev('.body').slideUp();
  })
*/
});