//
// FEDERICA CAU 2009
//
var curr_img = 1;
var prev_img = 1;
var max_img  = 2;

function doShow()
{
  $('test_slide').tween('left', (curr_img - 1)*-530+'px');
    
  prev_img = curr_img;
  curr_img++;
  if(curr_img > max_img) curr_img = 1;
}

function doShowNext() 
{
  doShow();
}

function doShowPrev() 
{
  curr_img = prev_img - 1;
  if(curr_img < 1) curr_img = max_img;
  doShow();  
}

function doMakeMenu(k,x)
{
  k.addEvent('mouseover'  ,function() { this.setStyle('background-position',''+x+' -33px'); }  );
  k.addEvent('mouseleave' ,function() { this.setStyle('background-position',''+x+' 0'); }  );  
}

function doSlider( id , bpage)
{
  bpage = (typeof bpage == 'undefined') ? -1 : bpage;
  var x = new Fx.Slide('slider', {'mode': 'horizontal'});
  var req = new Request.HTML({
  		url: 'http://www.federicacau.com/details/get/'+id+'/'+bpage,		// l'url da contattare
  		update: $('slider'),			// l'elemento che verrą aggiornato al completamento della richiesta
  		onComplete: function(tree, elements, html, js) {  		
    		var myFx = new Fx.Scroll(window).toElement('slider',{ offset: { 'x': 0, 'y': 0}});
  			x.slideIn();
  		}
  	});
  	
  x.slideOut().chain( function() { req.get(); });
}

window.addEvent('domready',function()
{
  // EMAIL OBFUSCATION
	$$('a[href^=mailto:]').each(function(anchor) {
		var address = anchor.innerHTML.replace('-at-', '@').replace('-dot-', '.');
		anchor.innerHTML = address;
		anchor.href = 'mailto:' + address;
	});

	// ACTIVATE SMOOTHSCROLL
  new SmoothScroll({ duration: 2000 }, window);

  var periodicalID;
  var begin = function() { 
    periodicalID = (function() {
      var scroll = document.body.getScroll(); 
      $('fixed_badge').tween('top', scroll.y ); 
    }).periodical(1000);
  }
	begin();
	
  // INIT MENU
  doMakeMenu($('m_home'), '0');   
  doMakeMenu($('m_folio'), '-160px');   
  doMakeMenu($('m_contact'), '-415px');   

  
});
