
//GLOBAL VARIABLES

var currentMainImage=0;

var theJimJam;

var theJimJamHeights;


//FUNCTIONS

function mainPicFadeIn() {

var mainPicFx= new Fx.Tween('main-pic', {
	property: 'opacity',
	duration: 150,
	transition: Fx.Transitions.Quad.easeOut
});
mainPicFx.start(0,1);
}


function simpleSwitch(newCurrent){

theJimJam[currentMainImage].setStyle('opacity', 0.4);
currentMainImage = newCurrent;
theJimJam[currentMainImage].setStyle('opacity', 1);
var mainFx = new Fx.Tween('main-pic', {
	property: 'opacity',
	link: 'ignore',
	duration: 150,
	transition: Fx.Transitions.Quad.easeIn
});
mainFx.addEvents({
    'complete': function() {
        $('main').src = theJimJam[currentMainImage].id;
        $('caption').innerHTML = theJimJam[currentMainImage].alt;
        	//var x = (600 - theJimJam[currentMainImage].title);
        	//$('main').setStyle('padding-top', x);
        mainPicFadeIn();
    }
});
mainFx.start(1,0);
}


function advanceMain(){

theJimJam[currentMainImage].setStyle('opacity', 0.4);
if (currentMainImage < (theJimJam.length-1))
{currentMainImage ++;}
else
{currentMainImage = 0;}

var mainFx2 = new Fx.Tween('main-pic', {
	property: 'opacity',
	duration: 150
});
mainFx2.addEvents({
    'complete': function() {
        $('main').src = theJimJam[currentMainImage].id;
        $('caption').innerHTML = theJimJam[currentMainImage].alt;
        mainPicFadeIn();
    }
});
mainFx2.start(1,0);
theJimJam[currentMainImage].setStyle('opacity', 1);
}





//PAGE INITIALIZATION

window.addEvent('domready', function() {

	//if IE switch logo from png to gif, ensure menu opacity
   if (Browser.Engine.trident) {
   	$('logo').src="logos/logo_black.gif";
   	$('nav-list-top').getElements('a[class=selected]').setStyle('opacity', 0.4);
   	}

	//add behaviors for logo and menu
      $('logo').addEvent('mouseenter', function(event){   
             this.setStyle('opacity', 0.7);
            });
      $('logo').addEvent('mouseleave', function(event){   
             this.setStyle('opacity', 1);
         });
         
    var menuLinks = $('nav-list-top').getElements('a[class=selectable]');
    menuLinks.each(function(item, index){
       item.addEvent('mouseenter', function(event){   
          this.setStyle('opacity', 0.4);
          });
       item.addEvent('mouseleave', function(){
       	if (!(this.hasClass('selected')))
         {this.setStyle('opacity', 1);}
 	});
   });

	//detect if the page is the about page and if so, don't add the following
	if ($(document.body).id != "about-contact") {
	
   	//add behaviors for main image
      $('main').addEvent('click', advanceMain);
         
	//add behaviors for thumbs   
   theJimJam = $$('img.magicthumb');
   theJimJam[currentMainImage].setStyle('opacity', 1);
   theJimJam.each(function(item, index){
      item.addEvent('click', function(){
         simpleSwitch(index);
         });
      item.addEvent('mouseenter', function(event){   
         this.setStyle('opacity', 1);
         });
      item.addEvent('mouseleave', function(){
         if (index != currentMainImage)
        {this.setStyle('opacity', 0.4);}
	});
   });

	//add full size images to hidden images div
	var i=0;
	while (i < theJimJam.length)
	  {
		var newSrc = theJimJam[i].id;
		var newHiddenImg = new Element('img', {src: newSrc}).inject($('hiddenimages'));
	 	 i++;
	  	if (i===(theJimJam.length - 1)) {
	  		$('caption').innerhtml = "";
		  	simpleSwitch(0);
	  		} //{alert('loading complete');}
	}
}
});