/* Bookmark */
function makeHome(){
   var url = self.location;
   var title = document.title;
   
}
/*
 Flickr style pagination;
 will need prototype.js (1.6.0.2 was the tested version)
 */

gFlickerPaginator = Class.create({
   initialize: function(o,m){
     this.conTainer = $(o);
     this.psScenes = this.conTainer.immediateDescendants();
     this.movePixels = m;
     if(Prototype.Browser.IE)
	 this.movePixels += 3;
     this.showing = 0;
     Event.observe('n_' + o, 'click', this.navClick.bindAsEventListener(this));
     Event.observe('p_' + o, 'click', this.navClick.bindAsEventListener(this));
   },
   navClick: function(e){
     var act = Event.element(e).id;
     switch(act.substr(0,1)){
        case 'p':
          this.slideRight();
        break;
        case 'n':
          this.slideLeft();
        break;
     }
     Event.stop(e);
   },
   slideLeft: function(){
    if(this.sliding) return;
    this.sliding = true;
     if(this.conTainer.style.left && this.conTainer.style.left.replace(/px/,'') * 1 <= ( -1 * this.movePixels)){
         var l = this.psScenes.length;
         var n = [];
         for(i = 1; i < l; i++)
           n.push(this.psScenes[i]);
         n.push(this.psScenes[0]);
         this.psScenes.invoke('remove');
         var l = n.length;
         for(i = 0; i < l; i++)
            this.conTainer.appendChild(n[i]);
         this.psScenes = n;   
         this.conTainer.style.left =  (this.conTainer.style.left.replace(/px/,'') * 1 + this.movePixels) + 'px';
      }
    this.homePos = (this.conTainer.style.left.replace(/px/,'') * 1) - this.movePixels;
    var x = new Effect.Move(this.conTainer, {x: -1 * this.movePixels, y: 0, mode: 'relative'});
    setTimeout('tSlider.slidingOff()', 1200);    
   },
   slideRight: function(){
    if(this.sliding) return;
    this.sliding = true;
     if(this.conTainer.style.left && this.conTainer.style.left.replace(/px/,'') * 1 > ( -1 * this.movePixels)){
         var l = this.psScenes.length - 1;
         var n = [this.psScenes[l]];
         for(i = 0; i < l; i++)
           n.push(this.psScenes[i]);
         this.psScenes.invoke('remove');
         var l = n.length;
         for(i = 0; i < l; i++)
            this.conTainer.appendChild(n[i]);
         this.psScenes = n;
         this.conTainer.style.left =  (this.conTainer.style.left.replace(/px/,'') * 1 - this.movePixels) + 'px';
      }         
    this.homePos = (this.conTainer.style.left.replace(/px/,'') * 1) + this.movePixels;
     var x = new Effect.Move(this.conTainer, {x: this.movePixels, y: 0, mode: 'relative'});
    setTimeout('tSlider.slidingOff()', 1200);    
   },
   slidingOff: function(){
	this.sliding = false;
	this.conTainer.style.left = this.homePos + 'px';
   }
});

// make sure this is initiated after page has been rendered
// you can call this for any number of such small ul/li 
// paginated scenes; will later on find a method to optimize
// image loads.. 
var tSlider = new gFlickerPaginator('featured-news', 300);
var auSlide;

var auStart = function(){
  if(auSlide) return;
  auSlide = setInterval('tSlider.slideLeft()', 5000);
}

var auStop = function(){
  if(auSlide){
    clearTimeout(auSlide);
    auSlide = false;
  }
}

Event.observe('featured-div','mouseover', auStop);
Event.observe('featured-div','mouseout', auStart);

auStart();

