/* Author: Ioannis Tziligkakis */
$(document).ready(function() {
  if ( $('#slider').length > 0 ) {
    var ft = 0.6;
    $('#thumbnails a').fadeTo(100, ft);
    $('#thumbnails a').hover(function() {
      $(this).stop(true, true).fadeTo('fast', 1);
    }, function(){
      $(this).stop(true, true).fadeTo('fast', ft);
    });

    var roll_the_pics = function() {
      var selected = $('#thumbnails a.selected');
      var target = (selected.parent().next().length > 0) ? selected.parent().next().find('a') : $('#thumbnails li:first a');
      target.click();
    };

    var tOut = setInterval(roll_the_pics, 3000);

    $('#thumbnails a').click(function(e) {
      e.preventDefault();
      var clicked = $(this);
      var index = clicked.parent().index();
      var current = $('#slides .selected');
      var target = $('#slides img:eq(' + index + ')');
      
      current.stop(true, true).fadeOut('fast', function(){
        $('#thumbnails a').removeClass('selected');
        clicked.addClass('selected');
        current.removeClass('selected');
        target.stop(true, true).fadeIn();
        target.addClass('selected');
      });
    });

    /* $('#slider').hover(function() {
      var thumbs = $('#thumbnails');
      thumbs.stop(true, true).animate({marginTop: 0}, 'fast');
    }, function() {
      var thumbs = $('#thumbnails');
      thumbs.stop(true, true).animate({marginTop: 78});
    }); */
  }

  if ($('a[rel*=colorbox-]').length > 0) {
    $('a[rel*=colorbox-]').colorbox();
  }

  $.each( $('.thumbs_container a'), function(index, item) {
    var item = $(item);
    if ( !$(item).attr('rel') ) {
      $(item).remove();
    }
  });
});

