
/**
 * Home
 */
 
var Home = {
  
  slides: false,
  current_slide: false,
  is_play: false,
  
  init: function(slides) {
    Home.slides = new Array();
    $.each(slides, function(key, slide) {
      var $slide = $('<img/>').attr('src', 'data/slides/' + slide.image).data('slide_data', slide).css({position: 'absolute', left: '-9000px', zIndex: 1, width: '663px', height: '401px'}).appendTo('#slideshow_holder');
      Home.slides.push($slide);
    });
    Home.current_slide = 0;
    Home.show();
    $('#play_slideshow').click(Home.play);
    $('#slideshow_holder').click(Home.slide_click);
  },
  
  play: function() {
    $('div.banner-play').fadeOut('slow', function() {
      Home.is_play = true;
      var $slide = Home.slides[Home.current_slide];
      Home.current_slide++;
      setTimeout(Home.show, $slide.data('slide_data').delay_seconds * 1000);
    });
    return false;
  },
  
  show: function() {
    $('#slideshow_holder img.current_slide').removeClass('current_slide').fadeOut('slow');
    if (Home.current_slide == Home.slides.length)
    {
      Home.stop();
    }
    else
    {
      var $slide = Home.slides[Home.current_slide];
      $slide.addClass('current_slide').hide().css({left: '0px', top: '0px'}).fadeIn('slow');
      $('#slideshow_holder').css('cursor', $slide.data('slide_data').link == '' ? 'normal' : 'pointer');
      $('#slide_slogan').hide().html($slide.data('slide_data').slogan).fadeIn('slow');
      if (Home.is_play)
      {
        Home.current_slide++;
        setTimeout(Home.show, $slide.data('slide_data').delay_seconds * 1000);
      }
    }
  },
  
  slide_click: function() {
    var $slide = $('#slideshow_holder img.current_slide');
    if ($slide.data('slide_data').link != '')
    {
        window.location.href = $slide.data('slide_data').link;
    }
    return false;
  },
  
  stop: function() {
    $('div.banner-play').fadeIn('slow', function() {
      Home.is_play = false;
      Home.current_slide = 0;
      Home.show();
    });
  }
  
}


