

/*
 * CPBHand root object
 */


var CPBHand = Class.create();


/*
 * Index's transitions
 */


CPBHand.Transitions = Class.create();
CPBHand.Transitions.prototype = {
	
	/* Constructor */
	initialize : function() 
	{


		this._prefix = 'http://www.sandballez-a-rennes.org/partenaires/';


		/* images */


		this._img_transitions = [
						this._prefix + 'preset_00.jpg',
						this._prefix + 'preset_01.jpg',
						this._prefix + 'preset_02.jpg',
						this._prefix + 'preset_03.jpg',
						this._prefix + 'preset_04.jpg'
						];
						
		this._running = false;
		this._current_index = 0;
		
		/* Duration */
		
		this._fade_duration = 3;
		this._display_duration = 5000;


	},
	
	/* Get random transition image - Can't get an image 2 times sequentially */
	getTransitionImage : function() 
	{
	
		var image = null;
	
		if(this._img_transitions != null) 
		{
		
			this._current_index++;
			
			if(this._current_index >= this._img_transitions.length) 
			{
				this._current_index = 0;
				
			}
			
			image = this._img_transitions[this._current_index] ;
						
		}
		
		return image;
	
	},
	
	change : function() {
	
		if(this._running) {
	
			crossfade($('transitions'), this.getTransitionImage(), this._fade_duration, '');
		
			var _self = this;

			setTimeout(function(){ _self.change(); }, this._display_duration);
	
		}
	
	},
	
	/* Transitions execution */
	start : function() 
	{
	
		this._running = true;
		startfade();
	
		var _self = this;
		setTimeout(function(){ _self.change(); }, this._display_duration);
	
	},
	
	stop : function()
	{
	
		stopfade();
		this._running  =false;
	
	}
	
};


/*
 * Mailer
 */


CPBHand.Mailer = Class.create();
CPBHand.Mailer.prototype = {


	initialize : function() 
	{
	
	},
	
	send_mail_contacts : function() {


		var email = $('contacts_email').value;
		var subject = $('contacts_subject').value;
		var msg = $('contacts_message').value;
	
		new Ajax.Updater('contacts-mailresult', '/Mail.php?type=contacts&from=' + email + '&subject=' + subject + '&message=' + msg);
	
	},
	
	send_mail_vosidees : function() {
	
		var email = $('vosidees_email').value;
		var msg = $('vosidees_message').value;
	
		new Ajax.Updater('vosidees-mailresult', '/Mail.php?type=ideas&from=' + email + '&message=' + msg);
	
	}


};


/*
 * Counter
 */


CPBHand.Counter = Class.create();
CPBHand.Counter.prototype = {


	initialize : function() 
	{
	
	},


	start : function() {


		new Ajax.Updater('count-display', '/Display.php');


	}



}

