/*
 * Author: Lazzo.nl
 */


var Graphincent = {};

 
Graphincent.menu = function(){
	
	$$('.l1').each(function(node){
		
		node.observe('click', function(){
			
			$$('.sub').invoke('hide');
			$$('.l1').invoke('setStyle', {color:'rgb(150,150,150)'});
			
			node.setStyle({color:'#fff'});
			node.next('.sub').show();
		})
		
	})
	
	
}
document.observe('dom:loaded', Graphincent.menu);


Graphincent.loadPhoto = function(){
	
	var loadF = function(){
		
	}
	
	$$('.l2').each(function(node){
		
		node.observe('click', function(){
			
			$$('.l2').invoke('setStyle', {color:'rgb(150,150,150)'});
			node.setStyle({color:'#fff'});
			
			var path = node.readAttribute('path');
			var count = node.readAttribute('count');
			
			Graphincent.photoLoader.loadCollection(path, count);
			
		})
		
	})
	
	
}

document.observe('dom:loaded', Graphincent.loadPhoto);


Graphincent.PhotoLoader = Class.create({

	initialize: function(){
		this.index = 1;
		this.canvas = $('canvas');
		this.canvasHeight = this.canvas.getHeight();
		this.prev = $('prev');
		this.next = $('next');
		
		this.next.observe('click', this._next.bind(this));
		this.prev.observe('click', this._prev.bind(this));
				
	},
	
	loadCollection: function(path, count) {
		
		this.index = 1;
		
		this.path = path;
		this.count = count;
		
		this._load(1);
		this._boundChecker();
	},
	
	_load: function(index) {

		this.canvas.fade({duration:.2,afterFinish: function(){
			
			this.canvas.update();
			this.index = index;
			var span = new Element('span');
			var img = new Element('img', {src:'/categories/' + this.path + '/' + this.index + '.jpg'});
			this.canvas.insert(span);
			this.canvas.insert(img);
			this.canvas.appear({duration:.2});
			
		}.bind(this)})		
		

		
	},
	
	_boundChecker: function() {
		
		if (this.index == this.count) {
			this.next.hide();
		} else {
			this.next.show();
		}

		if (this.index == 1) {
			this.prev.hide();
		} else {
			this.prev.show();
		}
		
	},
	
	_next: function(){
		this.index++;
		this._load(this.index);
		this._boundChecker();	
	},
	
	_prev: function(){
		this.index--;
		this._load(this.index);
		this._boundChecker();
	}
	
});
document.observe('dom:loaded', function(){Graphincent.photoLoader = new Graphincent.PhotoLoader()});









