
	var timer;
	var lastMarker = "";
  var currentIndex = 0;
  var splashWinObj = new Array();
  var locked = false;
  

   
  //define class SplashObject
  var SplashObject = Class.create({
      initialize: function(obj) {
          this.duration = obj.readAttribute('duration') *1000;
          this.link = obj.readAttribute('href');
          this.id = obj.readAttribute('id');
          
          //add click event listener for object with href attribute
          if(this.link != null){
            Event.observe(this.id,'click', this.gotoURL.bind(this));
            obj.setStyle({cursor:'pointer'});
          }
      },
      
      gotoURL: function(event) {
          if(this.link.substring(0,4) == 'http') //open new window if url is external
            window.open(this.link,'newWin');
          else //open in same window if url is internal
            window.location = this.link;
      }      
  });
  
	function startTimer() {
		timer = setTimeout("scroll()",splashWinObj[0].duration);
	}

	function createSplashObjects() {
	       var splashObjs = $('spotObj').childElements();
         for(var i=0; i < splashObjs.length; i++) {
              splashWinObj.push(new SplashObject(splashObjs[i]));
         }
         //start splashWin
         scroll();
  }
  function manualScroll(direction) {
    if(!locked) {
        clearTimeout(timer);
        if(direction == "right") {
        
        }
    }  
  }
  function toggleButton(e) {

        evtObj = e.element();
        if(evtObj.id != 'btnRight' && evtObj.id != 'btnLeft') {
            var toObj = e.relatedTarget || e.fromElement;
            var obj = evtObj.descendants();

            if(e.type == "mouseover" && !locked) {
                    if((evtObj.id == 'areaRight' && currentIndex != 0) || (evtObj.id == 'areaLeft' && currentIndex != 1)) {
                            Effect.Appear(obj[0], {duration:0.1});
                            if(evtObj.id == 'areaLeft')
                                    $('areaLeft').addClassName('scrollAreaActive');
                    }
            } else if(e.type == "mouseout" && toObj.id != 'btnRight' && toObj.id != 'btnLeft')
                Effect.Fade(obj[0], {duration:0.1});
        }      

  }
  function createScrollBtn() {
    var btn = new Element('div',{'class':'scrollBtn','id':'scrollBtnR'});
    
  }
  
	function scroll() { //fades between elements inside splashWin

    //fade out current element    
		if(currentIndex > 0)
          Effect.Fade(splashWinObj[currentIndex -1].id, {duration: 2.0});
    else
          Effect.Fade(splashWinObj[(splashWinObj.length -1)].id, {duration: 2.0});
        
    //fade in next element 
    locked = true;   	    
    Effect.Appear(splashWinObj[currentIndex].id, {duration: 2.0, afterFinish:function(){locked=false;timer = setTimeout("scroll()", splashWinObj[currentIndex].duration);updateMarkers();}});
		
}
	
	
function updateMarkers() { //swaps classes for markers inside splashWin

  //add class for current marker	
	var marker = $("marker_"+currentIndex);
  marker.addClassName('markerSelected');
  
  //remove class for all other markers
	if(lastMarker != undefined && lastMarker !="")
		lastMarker.removeClassName('markerSelected');

	lastMarker = marker;	
  currentIndex++;	
  
  if(currentIndex < 0 || currentIndex >= splashWinObj.length) {
		  currentIndex = 0;
	 }
}

function createMarkers() { //dynamically creates a marker for each element inside splashWin
  
  //create event listeners NOTE! Commented out because scrolling when clicking arrows not yet implemented
  /*$('areaRight').observe('mouseover', toggleButton);
  $('areaRight').observe('mouseout', toggleButton);
  $('areaLeft').observe('mouseover', toggleButton);
  $('areaLeft').observe('mouseout', toggleButton);
  
  Event.observe('btnRight','mouseout', function(e) {
      var toObj = e.relatedTarget || e.fromElement;
      if(toObj.id != 'areaRight') 
          $(this).fade({duration:0.1});
  });
  Event.observe('btnLeft','mouseout', function(e) {
      var toObj = e.relatedTarget || e.fromElement;
      if(toObj.id != 'areaLeft') 
          $(this).fade({duration:0.1});
  }); */
  
    for(var i=0; i < $('spotObj').childElements().length; i++) {
      var div = new Element('div', {'class':'marker', 'id':'marker_'+i});
      $('markerCounters').appendChild(div);      
    }
     
    //create splashWin Objects
    createSplashObjects();
}
