var slideShowImages = [ 
  '/shared/images/img1.png',
  '/shared/images/img2.png',
  '/shared/images/img3.png',
  '/shared/images/img4.png',
  '/shared/images/img5.png',
  '/shared/images/img6.png',
  '/shared/images/img7.png',
  '/shared/images/img8.png',
];

var slideShowImageIndex = 0;
function displayImage() {
  slideShowImageIndex = ( slideShowImageIndex + 1 ) % slideShowImages.length;  
  if( slideShowImageIndex % 1 == 0 ) {
    $('#slideshow').attr( 'style', "background: url('" + $('#slideshow-image').attr('src') + "') no-repeat;" );
    setTimeout( function() {
      $('#slideshow-image').hide();
      $('#slideshow-image').attr( 'src', slideShowImages[ slideShowImageIndex ] );
      $('#slideshow-image').one( 'load', function() {
        $(this).fadeIn(2000);
      } ).each( function() {
        if( this.complete )
          $(this).trigger('load');
      } );
    }, 100 );
  }
}

$(document).ready(function() {
  /* Tabs Click and Hover */
  var orignalBgColor = '#ffffff';
  
  $( '.tabs-tab:not(.selected)' ).each( function() { orignalBgColor = $(this).css( 'backgroundColor' ); } );

  $( '.tabs-tab' ).click( function() {
    id = parseInt( $(this).attr( 'id' ).substr( 11 ) );
    
    $( '.tabs-tab' ).each( function() {
      this_id = parseInt( $(this).attr( 'id' ).substr( 11 ) );
      
      if( this_id == id ) {
        $(this).addClass( 'selected' );
        $('#tab' + this_id).css( 'display', 'block' );
      }
      else {
        $(this).removeClass( 'selected' );
        $(this).animate( { backgroundColor: orignalBgColor }, 300 );
        $('#tab' + this_id).css( 'display', 'none' );
        
      }
    });
  });
  
  $( '.tabs-tab' ).hover( function() {
    if( !$(this).hasClass( 'selected' ) ) {
      $(this).animate( { backgroundColor: '#fafafa' }, 300 );
    }
  },
  function() {
    if( !$(this).hasClass( 'selected' ) )
      $(this).animate( { backgroundColor: orignalBgColor }, 300 );
  } );
  
  /* Menu Click and Hover */
  $( '.menu-button:not(.selected)' ).hover( function() {
    $(this).addClass( 'selected' );
  },
  function() {
    $(this).removeClass( 'selected' );
  });
  
  $( '.menu-button' ).click( function() {
    document.location = $( 'a', this ).attr('href');  
  })
  
  /* Slideshow */
  if( $('#slideshow-image').length > 0 ) {
    $('#slideshow-image').delay(800).fadeIn(2000);
    setTimeout( 'setInterval( displayImage, 4000 );', 1000 );
  }
  /*Screenshots */
  $("a.screenshot").fancybox({
    'titleShow'     : false,
    'transitionIn'  : 'elastic',
    'transitionOut' : 'elastic'
  });

});
