
window.addEvent('domready', function(){
	// Pre-defined Animation Styles ===================================== [ DO NOT EDIT BELOW HERE ] ===========
	if(mooblinds_animation_type=='pow'){
		mooblinds_animation_type = 'pow:out' ;
		mooblinds_animation_duration = 700 ;
	} else if (mooblinds_animation_type=='bounce'){
		mooblinds_animation_type = 'bounce:out' ;
		mooblinds_animation_duration = 600 ;
	} else if (mooblinds_animation_type=='basic'){
		mooblinds_animation_type = 'linear' ;
		mooblinds_animation_duration = 200 ;
	}
	// Setup functional arrays, styles and variables
	mooblinds_links = $('mooblinds').getElements('a') ; // Initialise the images array
	mooblinds_images = $('mooblinds').getElements('img') ; // Initialise the images array
	mooblinds_stage_width = parseFloat($('mooblinds').getStyle('width')) ;
	mooblinds_width_static = parseInt(mooblinds_stage_width/mooblinds_images.length)+1 ;
	mooblinds_width_open = parseFloat(mooblinds_images[0].getStyle('width')) ;
	mooblinds_width_closed = parseInt((mooblinds_stage_width-parseFloat(mooblinds_images[0].getStyle('width')))/(mooblinds_images.length-1))+1 ;
	// Animation properties based on selected effect
	mooblinds_images.set('morph', {duration: mooblinds_animation_duration, transition: mooblinds_animation_type});
	// Opener Function
	function open_me(open_who){
		moo_count = 1 ;
		current_margin = 0 ;
		open_who = parseFloat(open_who.replace(mooblinds_functional_prefix,'')) ;
		mooblinds_images.each(function (moo_image){
			if(mooblinds_animated_mode==true){
				moo_image.morph({'margin-left':current_margin}) ;
			} else {
				moo_image.setStyles({'margin-left':current_margin}) ;
			}
			if(moo_count==open_who){
				// Large Window
				current_margin = current_margin + mooblinds_width_open ;
			} else {
				// Small Window
				current_margin = current_margin + mooblinds_width_closed ;
			}
			moo_count++ ;
		});
	}
	// Reset Function
	function reset_us(is_initial){
		moo_count = 1 ;
		current_margin = 0 ;
		mooblinds_links.each(function (moo_link){
			if((is_initial==true)||(mooblinds_animated_mode!=true)){
				moo_link.getElement('img').setStyles({'margin-left':current_margin}) ;
			} else {
				moo_link.getElement('img').morph({'margin-left':current_margin}) ;
			}
			current_margin = current_margin + mooblinds_width_static ;
			moo_count++ ;
		});
	}
	// Setup the mouse events and stuff to start with
	moo_count = 1 ;
	current_margin = 0 ;
	mooblinds_links.each(function (moo_link){
		moo_link.id = mooblinds_functional_prefix+moo_count ;
		moo_link.addEvent('mouseenter', function(){
			open_me(moo_link.id) ;
		});
		moo_count++ ;
	});
	// Reset all event when moving away from nav, if set in options
	$('mooblinds').addEvent('mouseleave', function(){
		reset_us(false) ;
	});
	// Reset (aka restore defaults) once all properties are assigned
	reset_us(true) ;
});
