
var carouselDev = {
	crtLogo: $('#carousel li')[2].id, // start with the third logo
	oldLogo: "",
	crtZIndex: 100,
	phrasesSpeed: 200,
	
	// ** Do Next Animation
	DoNextAnimation: function () {
		$('div#phrases .' + this.crtLogo).each(function() {
			var crtLeft, crtTop, crtWidth, crtHeight, crtFS, crtClr;
			
			if (!$(this).data('prev')) {
				crtLeft		= parseInt($(this).css('left'), 10);
				crtTop		= parseInt($(this).css('top'), 10);
				crtWidth	= parseInt($(this).css('width'), 10);
				crtHeight	= parseInt($(this).css('height'), 10);
				crtFS		= parseInt($(this).css('fontSize'), 10);
				crtClr		= $(this).css('color');
				
				$(this).data('prev', {Left: crtLeft, Top: crtTop, Width: crtWidth, Height: crtHeight, FS: crtFS, Clr: crtClr});
			}
			else {
				crtLeft		= $(this).data('prev').Left;
				crtTop		= $(this).data('prev').Top;
				crtWidth	= $(this).data('prev').Width;
				crtHeight	= $(this).data('prev').Height;
				crtFS		= $(this).data('prev').FS;
				crtClr		= $(this).data('prev').Clr;
			}
			
			$(this).animate({
				left: Math.floor(crtLeft - crtWidth/4), 
				top: Math.floor(crtTop - crtHeight/4), 
				fontSize: Math.floor(crtFS * 1.5), 
				color: '#ff9000', 
				'z-index': carouselDev.crtZIndex}, carouselDev.phrasesSpeed);
			
			carouselDev.crtZIndex++;
		});
	},

	// ** Revert Previous Animation
	RevertPreviousAnimation: function () {
		$('div#phrases .' + this.oldLogo).each(function() {
			$(this).animate({
				left: $(this).data('prev').Left,
				top: $(this).data('prev').Top,
				fontSize: $(this).data('prev').FS,
				color: $(this).data('prev').Clr
			}, carouselDev.phrasesSpeed);
		});
	},
	
	// ** Stop Auto Scroll; defined inside jCarouselLite
	StopAuto: function () {},
	
	// ** Restart Auto Scroll; defined inside jCarouselLite
	RestartAuto: function () {}
};



//** OnLoad
$(document).ready(function () {
	
	
	// ** Manage Carousel
	$("#carousel").jCarouselLite({
		btnPrev: "#prev-btn",		// direction reversed by switching buttons ID's
		btnNext: "#next-btn",
		auto: 4000,
		speed: 500,
		visible: 5,
		scroll: -1, // ± sets direction
		easing: "easeinout",
		mouseWheel: true,
		hoverPause: true,
		beforeStart: function(a) {
			carouselDev.oldLogo = carouselDev.crtLogo ;
			carouselDev.RevertPreviousAnimation();
		},
		afterEnd: function(a) {
			carouselDev.crtLogo = a[2].id;
			carouselDev.DoNextAnimation();
		}
	});
	
	
	// ** Manage Carousel Buttons
	$('#prev-btn, #next-btn').hover(function() {
			$(this).css("backgroundPosition", "-35px 0");
		}, function() {
			$(this).css("backgroundPosition", "0 0");
		}
	)
	.mousedown(function() {
			$(this).css("backgroundPosition", "-70px 0");
		}
	)
	.mouseup(function() {
			$(this).css("backgroundPosition", "-35px 0");
		}
	);

	
	// ** Set Logos
	// IE history buttons require [window.load] instead of [img.load]
	$(window).load(function() {		
		$('#carousel li').each(function() {
			var imgPath = 'images/carousel/';
			var imgType = '.png';
			var imgName = this.id;

			//$('<img />')
			//	.attr('src', imgPath + imgName + imgType)
			//	.load(function() {
					$('#carousel li#' + imgName + ' img').attr('src', imgPath + imgName + imgType); 
			//	});
		});
	});
	
	// ** Start Animation
	carouselDev.DoNextAnimation();
})


