var elementsSrcs = new Array();
var i = 0;
var curSrc = 0;
var frontFrame;
var backFrame;
var fadeSpeed = 500;
var imageTimeout = 10000;
var instantPause = 0;
var pause = 0;
var direction = '+';
dcmaAnimateINIT = function () {
	$('div.promoboxImage').hide();
	$('div.promoboxImage:first').show();
	$('div.promoboxImage').each(function()
		{
			elementsSrcs[i++] = $(this).attr('id');
		});
	$('img.dcmaAnimateButton')
		.mouseover(function(){
			$(this).attr('src',$(this).attr('src').replace(/_out/gi,'_over'));
		})
		.mouseout(function(){
			if($(this).attr('title') != "pause" || !pause){
				$(this).attr('src',$(this).attr('src').replace(/_over/gi,'_out'));
			}
		})
		.mouseup(function(){
			$(this).attr('src',$(this).attr('src').replace(/_click/gi,'_over'));
		})
		.mousedown(function(){
			$(this).attr('src',$(this).attr('src').replace(/_over/gi,'_click'));
		})
		.bind('click',function(){
			instantPause = 0;
			direction = '+';
			switch($(this).attr('title')){
				case "right":
					dcmaAnimateSlideShowAction();
					if (!pause){
						$('img#imgScrollPause').trigger('click');
					}
					break;
				case "left":
					direction = '-'
					dcmaAnimateSlideShowAction();
					if (!pause){
						$('img#imgScrollPause').trigger('click');
					}
					break;
				case "pause":
					if(pause){
						pause = 0;
					}else {
						pause = 1;
						$(this).attr('src',$(this).attr('src').replace(/_out/gi,'_over'));
						$(this).attr('src',$(this).attr('src').replace(/_click/gi,'_over'));
					}
					instantPause = pause;
					dcmaAnimateSlideShowAction();
					break;
				default:
			}
		});
	frontFrame = elementsSrcs[1];
	backFrame = elementsSrcs[0];
	setTimeout("dcmaAnimateSlideShowAction()",imageTimeout);
}
dcmaAnimateSlideShowAction = function (){
	if (!instantPause){
		frontFrame = elementsSrcs[curSrc];
		if (direction == '+'){
			if(++curSrc >= elementsSrcs.length) curSrc = 0;
		}else{
			if(--curSrc < 0) curSrc = elementsSrcs.length-1;
		}
		backFrame = elementsSrcs[curSrc];
		$('#'+frontFrame).fadeOut('slow');
		$('#'+backFrame).fadeIn('slow');
		if (!pause){
			setTimeout("dcmaAnimateSlideShowAction()",imageTimeout);
		}
	}
}
$(document).ready(dcmaAnimateINIT);
