// ======================================
// = ROLL VERTICAL SLIDES WITH A BOUNCE =
// ======================================
document.observe("dom:loaded", function() {
	setTimeout("vert_preLoad(slotitems, '');",100);
	setTimeout("load_slots();",550);
	setTimeout("load_event();",550);
});

var center_event = 0;
var slide_to_remove = 0;

function vert_preLoad(imgs, directory) {
	var extent = imgs.length - 1;
	for(i=0; i<imgs.length; i++) {
		$('index-slot-machine-links').insert({ bottom : '<a href="'+imgs[i][3]+'" id="sm_img_link_'+i+'" title="" class="slot-machine-img-link"><img src="images/vertical_slides/' + imgs[i][0] + '" width="190" height="279" alt="' + imgs[i][1] + '" class="slot-machine-img" /></a>' });
	}
}

function load_slots(){
	// CENTER THE CENTER IMAGE
	$$('#index-slot-machine-links a').each(function(element){
		var img_id = element.id;
		new Effect.Move(img_id, {x:0, y:-230, duration: 0.6});
	});
}

function smroll(){
	// SLOT ROLL TO A JIGGLE-ING FINISH
	$$('#index-slot-machine-links a').each(function(element){
		var img_id = element.id;
		// The duration below and the setTimeout number work together to control speed of rotation and bounce 
		new Effect.Move(img_id, {x:0, y:-294, duration: 0.3});
	});
	setTimeout("jiggle();", 400);
	setTimeout("load_event();", 400);
}

function jiggle() {
	$$('#index-slot-machine-links a').each(function(element){
		new Effect.Bounce(element);
	});
	//load_event();
}

function load_event(){
	// SET EVENT LABEL FOR CENTER IMAGE
	center_event++;
	$$('#slot-machine-text h3').each(function(element){ element.update(""+slotitems[center_event][1]+""); });
	$$('#slot-machine-text h4').each(function(element){ element.update(""+slotitems[center_event][2]+""); });
	
	// APPEND IMAGE DETAILS FROM TOP MOST SLIDE TO THE END
	if (center_event == 1) { new_slide = initial_length; }
	$('index-slot-machine-links').insert({ bottom : '<a href="'+slotitems[slide_to_remove][3]+'" id="sm_img_link_'+new_slide+'" title="" class="slot-machine-img-link" style="position: relative; left: 0px; top: '+initial_dist+'px;"><img src="images/vertical_slides/'+slotitems[slide_to_remove][0]+'" width="190" height="279" alt="'+slotitems[slide_to_remove][1]+'" class="slot-machine-img" /></a>' });
	slotitems[new_slide] = new Array(slotitems[slide_to_remove][0], slotitems[slide_to_remove][1], slotitems[slide_to_remove][2], slotitems[slide_to_remove][3]);
	
	if (center_event > 1) {
		// REMOVE THE SLIDE FROM TWO AGO
		$('sm_img_link_' + (slide_to_remove - 1)).remove();
		// AND POSITION THE REST
		$$('#index-slot-machine-links a').each(function(element){
			element.writeAttribute('style', 'position: relative; left: 0px; top: '+initial_dist+'px;');
		});
	}
	
	// INCREMENT IN ORDER TO CONTINUE UNTIL THE PAGE IS VACATED
	new_slide++;
	slide_to_remove++;
	
	//The number below controls how long a frame stays still before it goes on to the next frame
	setTimeout("smroll();",4000);
	
	// INITITAL DIST -230, -524, -818
}

/*
* *
* Copyright (c) 2006 Millstream Web Software http://www.millstream.com.au
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* * 
*/
Effect.Bounce = function(element, options) {
	element = $(element);
	var opt = Object.extend({ height : -4, fps : 30 }, {} | options);
	var oldStyle = { top: element.getStyle('top'), left: element.getStyle('left') };
	var h = opt.height;
	var f = opt.fps;
    return new Effect.Move(element, 
      { x: 0, y: 0-h, duration: 0.04, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: h, duration: 0.0, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: 0-(Math.round(h*0.0)), duration: 0.02, fps:f, afterFinishInternal: function(effect) {
    new Effect.Move(effect.element,
      { x: 0, y: Math.round(h*0.0), duration: 0.05, fps:f, afterFinishInternal: function(effect) {
        //effect.element.undoPositioned();
        //effect.element.setStyle(oldStyle);
      }}) }}) }}) }});
}
