/**
 * studiolift.com
 */

function slideSwitch() {
  var head = $('#slideshow span:first-child');
  var tail = $('#slideshow span:last-child');
  var active = $('#slideshow span.active');

  if (active.length == 0){
    active = tail;
  }
  
  var next = $(active).next();

  if (next.length == 0){
    next = head;
  }

  //$(next).addClass('active');
  $(active).addClass('last-active');
  $(next).css({opacity: 0.0})
      .addClass('active')
      .animate({opacity: 1.0}, 1000, function() {
          $(active).removeClass('active last-active');
      });

  //$(active).removeClass('active');
  
  t = setTimeout( "slideSwitch()", 5000 );
}

$(document).ready(function(){

   var t = setTimeout( "slideSwitch()", 5000 );
   
   $('#la_dropdown select option').each(function(){
     if ($(this).val() == location){
       $(this).attr('selected', 'selected');
     }
   });
   
   $('#la_dropdown select').change(function(){
     if ($(this).val()){
       location = $(this).val();
     }
   });

});
