var fadingImageIndex = 1;
var fadingImageCount = 1;

Event.observe(window, 'load', function() {
	if ($('rotator') != null) {
		fadingImageCount = $('rotator').childElements().size();
		setInterval('crossfade()',5000);
	}
});

function crossfade() {
	Effect.Fade('slideshow-' + fadingImageIndex,{ duration:1, from:1.0, to:0.0 });
	
	fadingImageIndex++;
	if (fadingImageIndex > fadingImageCount)
		fadingImageIndex = 1;
	
	Effect.Appear('slideshow-' + fadingImageIndex,{ duration:1, from:0.0, to:1.0 });
}

var DropDownMenu = Class.create();

DropDownMenu.prototype = {
	initialize: function(menuElement) {
		menuElement.childElements().each(function(node){
			var submenu = $A(node.getElementsByTagName("ul")).first();
			if(submenu != null){
				Element.extend(submenu).setStyle({display: 'none'});
				node.onmouseover = node.onmouseout = function(){
					Element.toggle(submenu);
					node.toggleClassName('hovering');
				}
			}
		});
	}
};

document.observe('dom:loaded', function() {
	var menu = new DropDownMenu($('topnav').down('ul'));
});


//js random image.... let's do this in ruby instead...
/*
var theImages = new Array() // do not change this

theImages[0] = '/presents/bix/designs/produce/dec09/images/subbanner_beets.jpg'
theImages[1] = '/presents/bix/designs/produce/dec09/images/subbanner_corn.jpg'
theImages[2] = '/presents/bix/designs/produce/dec09/images/subbanner_limes.jpg'
theImages[3] = '/presents/bix/designs/produce/dec09/images/subbanner_rasberries.jpg'

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
	document.write('<img src="'+theImages[whichImage]+'" border="0">');
}
*/


//no dropdowns...
/*
Event.observe(window, 'load', function() {
	var menu = new DropDownMenu($('navigation'));
});

var DropDownMenu = Class.create();

DropDownMenu.prototype = {
	initialize: function(menuElement) {
		menuElement.childElements().each(function(node){
			// if there is a submenu
			var submenu = $A(node.getElementsByTagName("ul")).first();
			if(submenu != null){
				// make sub-menu invisible
				Element.extend(submenu).setStyle({display: 'none'});
				// toggle the visibility of the submenu
				node.onmouseover = node.onmouseout = function(){
					Element.toggle(submenu);
				}
			}
		});
	}
};
*/

