var webkitMpWidth = 250;
var webkitMpHeight = 40;
var webkitMpFirstload = 0;
var webkitMpDlButton = 0;
var webkitMpLoader = 0;
var webkitAltmediaplayer = "";

var rotatetimer;
var rotations = 0;
var paused = 0;
var rotatelength = 8000;

var shiftbanners = 0;
function startrotate() {
	clearTimeout(rotatetimer);
	if (rotations < totalpics && !paused) {
		rotatetimer = setTimeout('rotate()', rotatelength);
	}
	return false;
}

function rotate(nav) {
	var nextpic;
	var curpic;
	var lastpic;
	for (var x=0; x < totalpics; x++) {
		
		if ($('pic' + x + 'set') && $('pic' + x + 'set').style.display !== 'none') {
			// found current displayed pic		
			nextpic = x + 1;
			if (nextpic > totalpics - 1) { nextpic = 0; }
			curpic = x;
			lastpic = x - 1;
			if (lastpic < 0) { lastpic = 0; }
			
			if (nav == "pause") {
				if (paused) {
					// unpause
					document.images['pause'].src = pauseoff.src;
					paused = 0;
					startrotate();
				}
				else {
					// pause
					document.images['pause'].src = pauseactive.src;
					paused = 1;					
					clearTimeout(rotatetimer);
				}
			}
			else if (x == 0 && nav == "last") {
				// already on first pic, don't do anything
				rotations = 0;
				startrotate();
			}
			else if ((nav && nav == "next" && !paused) || !nav) {
			//	document.images['forward'].src = forwardon.src;
				new Effect.Appear('pic' + nextpic + 'set', { afterFinish: function() {
					$('pic' + nextpic + 'set').style.display = 'block';
					$('pic' + curpic + 'set').style.display = 'none';
					$('pic' + nextpic + 'set').style.zIndex = 1;
					$('pic' + curpic + 'set').style.zIndex = 2;
			//		document.images['forward'].src = forwardoff.src;										
					rotations++;
					startrotate();
					}});
			}	
			else if (nav && nav == "last" && !paused) {									
				new Effect.Appear('pic' + lastpic + 'set', { afterFinish: function() {
					$('pic' + lastpic + 'set').style.display = 'block';
					$('pic' + curpic + 'set').style.display = 'none';
					$('pic' + lastpic + 'set').style.zIndex = 1;
					$('pic' + curpic + 'set').style.zIndex = 2;
					rotations--;
					startrotate();
					}});
			}
		}
	}
}

var pauseon = new Image();
pauseon.src = "/styles/images/pausep.png";
var pauseactive = new Image();
pauseactive.src = "/styles/images/pauseon.png";
var pauseoff = new Image();
pauseoff.src = "/styles/images/pause.png";


function img_act(imgName) {
        var imgOn = eval(imgName + "on.src");
        if (imgName == "pause" && document.images['pause'].src == pauseactive.src) {
                return false;
        }
        document.images[imgName].src = imgOn;
}

function img_inact(imgName) {
        var thisbutton = imgName.replace('butt','menu');
        var imgOff = eval(imgName + "off.src");
     
        document.images[imgName].src = imgOff;
}

document.observe('dom:loaded', function(e) {
	if ($('rotatingpics')) {
		startrotate();
	}
});

function contact(address) {
	if (address == "nina") {
		Modalbox.show('/contact.php?to=' + address, { title: "Send Email to Nina", width:550, overlayClose:false });
	}
}
