$(document).ready(function(){

  // MAIN SLIDESHOW
  $('div.slidethumb').mouseover(function(){
    
    $(this).addClass('over');
    
  }).mouseout(function(){
    
    $(this).removeClass('over');
    
  });

  
  $mainslideshow = $('#slideshow-inner').cycle({
  		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  		cleartype:  false, // disable cleartype corrections
  		startingSlide: 0,
  		after: activeSlide,
  		before: nextSlide,
  		speed: 750,
  		timeout: 4000
  });
  
  function activeSlide(curr, next, opts) {
    var curindex = opts.currSlide;
    curindex = parseInt(curindex);
    //set the active class on the relevant thumbnail and remove it from the others
    $('#slidethumbs-outer div:not([rel=slide'+curindex+'])').removeClass('active');
    $('#slidethumbs-outer div a[rel=slide'+curindex+']').parent().addClass('active');
  }
  
  function nextSlide(curr, next, opts) {
    var curindex = opts.currSlide;
    nextindex = parseInt(curindex + 1);
    //set the active class on the relevant thumbnail and remove it from the others
    $('#slidethumbs-outer div:not([rel=slide'+nextindex+'])').removeClass('active');
    $('#slidethumbs-outer div a[rel=slide'+nextindex+']').parent().addClass('active');
  }
  

// main slideshows text should be clickable

$('#slideshow-inner div.slide').each(function(){
  var slidelink = $(this).find('a.slidelink').attr('href');
  var h2 = $(this).find('div.caption h2');
  var h2html = h2.html();
  h2.html('<a href="'+slidelink+'">'+h2html+'</a>');
});




$('a.slidethumb').click(function(){
  $(this).parent().addClass('active');
  var sSlide = $(this).attr('rel');
  var nSlide = sSlide.replace('slide','');
  $mainslideshow.cycle(parseInt(nSlide));
  return false;
});




  // MINI SLIDE SHOW
  $minislideshow = $('#minislideshow-inner').cycle({
  		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
  		cleartype:  false, // disable cleartype corrections
  		startingSlide: 0,
  		speed:250,
  		timeout:6500,
  		pager:'#minipages'
  });


  $('#minislideshow-inner div.slide').each(function(){
    var sllink  = $(this).find('a').attr('href');
    var capp    = $(this).find('div.caption p');
    var caphtml = capp.html();
    capp.html('<a href="'+sllink+'">'+caphtml+'</a>');
  });


  // Mini Calendar Tooltips
  $('a.tt').cluetip({ sticky: true,
                      closePosition: 'title',
                      arrows: true,
                      cluetipClass:'rounded',
                      hideLocal:'true',
                      local:'true',
                      closeText: 'X',
                      positionBy:'bottomTop',
                      hoverIntent: {
                                     sensitivity:  10,
                                     interval:     10,
                                     timeout:      0
                                    }

  });


});
