///////////////////////////////////////////////////////////////
//
//  File: global javascript file
//  Author: Craig Nelson / Classic Labs
//

  // slideshows
	function setSlideShow(slides) {
	  var currentSlide = 0;
  	var nextSlide = 1;
  	if ($("project-link")) {
  	  $("project-link").href = $(slides[currentSlide]).down("a").href;
  	}
  	var slideShow = function () {
  	  if (slides.length <= 1) { // does the current page have a slideshow and is there more than one slide?
  	    return;
  	  }
  	  Effect.Fade(slides[currentSlide], { duration: .5 });
      Effect.Appear(slides[nextSlide], { duration: .5 });
      currentSlide++;
      nextSlide++;
      if (nextSlide == slides.length) {
        nextSlide = 0;
      }
      if (currentSlide == slides.length) {
        currentSlide = 0;
      }
      $("project-link").href = $(slides[currentSlide]).down("a").href;
      setTimeout(function () {
        slideShow();
      }, 6000);
  	};
  	return slideShow;
	}
	// --slideshows
  
  Event.observe(window, "load", function () {
    // slideshow
    var slideShow = setSlideShow($$("#slideshow .slide"));
    setTimeout(function () {
      slideShow();
    }, 6000);
    // --slideshow
    
    // non-clickable and external links
    var anchors = $$('a');
    anchors.each(function (e) {
      if (e.getAttribute('rel') == 'external') {
        e.target = '_blank';
      }
      /*
      if (e.getAttribute('rel') == 'cross') {
        Event.observe(e, "click", function (event) {
          pageTracker._link(this.href);
          event.preventDefault();
        });
      }
      */
    });
    // --non-clickable and external links
  });
  
  document.observe("dom:loaded", function () {
    // photo masking for slideshow
    if ($("slideshow")) {
      var element = $("slideshow").getDimensions();
      $("slideshow-mask").style.width = element.width + "px";
      $("slideshow-mask").style.height = element.height + "px";
    }    
    // --photo masking for slideshow
  });
