/************************************************************************************************************
**  Author: Bernardino Todoli Lopez 															
**  Contact: amarukensai(at)gmail.com														
**  Url: http://www.btodoli.net																
**  Creation Date: 8-11-2007 (DD-MM-YYYY)													
*************************************************************************************************************/
	
var websites = new Array();						 
var active;			
var element;			 

document.observe('dom:loaded', function()
{	
	//Fotos
	if ($('aikidoLink')) {
		$('aikidoLink').observe('click', function(e){
			moveTo('fotos-wrapper','aikido');
			Event.stop(e);
		});
		$('barcelonaLink').observe('click', function(e){
			moveTo('fotos-wrapper','barcelona');
			Event.stop(e);
		});
		$('menorcaLink').observe('click', function(e){
			moveTo('fotos-wrapper','menorca');
			Event.stop(e);
		});
		$('japonLink').observe('click', function(e){
			moveTo('fotos-wrapper','japon');
			Event.stop(e);
		});
		$('yoLink').observe('click', function(e){
			moveTo('fotos-wrapper','yo');
			Event.stop(e);
		});
	}	
	
	//Portafolios
	if ($('cv')) {
		$('cvFold').observe('click', function(e){
			Event.stop(e);
			new Effect.Morph('cv', {
			  style: {
			    width: '400px',
			    height: '300px',
				marginLeft: '550px'
			  },
			  duration: 0.4
			});
		});
		
		$('cv').observe('click', function(e){
			new Effect.Morph('cv', {
			  style: {
			    width: '0px',
			    height: '0px',
				marginLeft: '950px'
			  },
			  duration: 0.4
			});
		});
		
		active = websites[0]; 
		for(var i=1; i<websites.length; i++)
			$(websites[i]).hide();
	}
	
	if($('blogPosts')){
		$('blogPosts').setOpacity(0.75);
	}
});



// Private methods

//ponemos los datos de la web en datosWeb
function addData(id)
{
	websites.push(id);
}

//hace visible o invisible la capa id
function toggleDisplayWeb(id)
{
	if(active != id)
	{
		Effect.BlindDown(id,{duration: 0.5});
		element = id;
		new PeriodicalExecuter(function(pe) {
			Effect.BlindUp(active,{duration: 0.2});
		    active = element;
		    pe.stop();
		}, 0.75);
	}
}

function showEnlarge(id)
{
	//new Effect.Opacity(id + '_image', { from: 1, to: 0.50, duration: 1 });
	$(id+ '_image').setOpacity(0.50);
}

function hideEnlarge(id)
{
	//new Effect.Opacity(id + '_image', { from: 0.50, to: 1, duration: 1 });
	$(id+ '_image').setOpacity(1);
}	



//Code from http://pastie.org/36461
Effect.Scroll = Class.create();
Object.extend(Object.extend(Effect.Scroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    } else {

    }
  },
  update: function(position) {   
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

//Code from http://elia.wordpress.com/2007/01/18/overflow-smooth-scroll-with-scriptaculous/
function moveTo(container, element){
  Position.prepare();
  container_x = Position.cumulativeOffset($(container))[0];
  element_x = Position.cumulativeOffset($(element))[0];
  container_y = Position.cumulativeOffset($(container))[1];
  element_y = Position.cumulativeOffset($(element))[1];
  new Effect.Scroll(container, {x:(element_x-container_x), y:(element_y-container_y)});
  return false;
}
