/** 
  * TOUTS ANIMATION EFFECTS
  * Author: Karen Chiu
  * Last Modified: 07/08/09
**/

// Global variable across touts to set if zoom animation is applied or not
var noZoom = false;

// MAIN TOUT FUNCTION CALLED FROM COMMON.JS
var toutpanel = this.toutpanel = function(){
	
	// Initialise tout boxes 
	var toutBoxes = JQ("div.toutbox");
	toutBoxes.find("div a").css({overflow:"hidden",height:"195px"});
	toutBoxes.find("span.toutflash").css({opacity:0});
	
	var toutBootcamp = toutBoxes.find("a.toutbootcamp");
	var toutHisboot = toutBoxes.find("a.touthisboot");
	var toutEquipment = toutBoxes.find("a.toutequipment");
	var toutNikeid = toutBoxes.find("a.toutnikeid");
	var toutNikePro = toutBoxes.find("a.toutnikepro");
	var toutChoose = toutBoxes.find("a.toutchoose");
	var toutBootEliteLarge = toutBoxes.find("a.toutbootelitelarge");
	var toutBootElite = toutBoxes.find("a.toutbootelite");
	
	
	// Large Touts
	if (toutBootcamp.length > 0) {
		toutAnimationBootcamp(toutBootcamp, 0.1);
	}
	if (toutHisboot.length > 0) {
		toutAnimationHisBoot(toutHisboot, true, 0.05);
	}
	if (toutEquipment.length > 0) {
		toutAnimationExplore(toutEquipment);
	}
	// Small Touts
	if (toutNikeid.length > 0) {
		if (toutNikeid.attr('id') == 'idClubReplica') {
			toutAnimationNikeId(toutNikeid, 0);
		}
		else {
			toutAnimationNikeId(toutNikeid);
		}
	}
	if (toutNikePro.length > 0) {
		toutAnimationExplore(toutNikePro, true);
	}
	if (toutChoose.length > 0) {
		toutAnimationChoose(toutChoose);
	}
	
	if (toutBootEliteLarge.length > 0) {
		toutAnimationNikeEliteLarge(toutBootEliteLarge);
	}		
	
	if (toutBootElite.length > 0) {
		toutAnimationNikeElite(toutBootElite);
	}	
}

// Animation - Bootcamp Tout
var toutAnimationBootcamp = function(toutObject, zoomFactor) {
	// Set font according to tout type
	var toutType = JQ(toutObject).attr("class");
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Rhode-SemiboldCondensed');
	} 
	else if (useSiteFont == 2) {
		JQ(toutObject).find('span.touttitle span').css({'font-size': '20px', height: '20px'});
		JQ(toutObject).find('em').css({'font-size': '28px', height: '24px'});
		JQ(toutObject).find('span.touttext span.touttextline').css({'font-size': '20px', height: '20px'});
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttitle span')('a.' + toutType + ' span.touttext span.touttextline');
	
	// Initialise event queuing vars
	var currentBootcampAnimation = null;
	var nextBootcampAnimation = null;
	
	// Initialise animation vars
	if (zoomFactor == undefined) {
		var zoomFactor = 0.1;
	}
	var zoomWidth = parseInt(toutObject.width() * zoomFactor);
	var zoomHeight = parseInt(toutObject.height() * zoomFactor);		
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutTexts = JQ(toutObject).find("span.touttext span.touttextline");
	var toutImg = JQ(toutObject).find("img.zoom");
	var toutEm = JQ(toutObject).find("em");
	if (toutEm.length > 0) {
		toutEm.each(function(i){
			var h = JQ(this).height();
			JQ(this).parent().css({height: h});
		});
	}
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			if (currentBootcampAnimation) {
				nextBootcampAnimation = "enter";
				return;
			}
			currentBootcampAnimation = "enter";
			noZoom = false;
			toutTitle.fadeOut(100, function() {
				setTimeout(function() { 
					slideIn(toutTexts, 0, function() { 
						currentBootcampAnimation = null;
						if (nextBootcampAnimation == "enter") {
							nextBootcampAnimation = null;
						}
						else if (nextBootcampAnimation == "leave") {
							toutObject.mouseleave();
						}
					}); 
				}, 100);
			});
			zoomIn(toutImg,zoomWidth,zoomHeight);
		}
	);
	toutObject.mouseleave(
		function() {
			if (currentBootcampAnimation) {
				nextBootcampAnimation = "leave";
				return;
			}
			currentBootcampAnimation = "leave";
			noZoom = false;
			zoomOut(toutImg,zoomWidth,zoomHeight);
			slideOut(toutTexts, 0, function() { 
				toutTitle.fadeIn(300, function() {
					currentBootcampAnimation = null;  
					if (nextBootcampAnimation == "leave") {
						nextBootcampAnimation = null;
					}
					else if (nextBootcampAnimation == "enter") {
						toutObject.mouseenter();
					}
				}); 
			});
		}
	);
}

// Animation - His Boot Touts
var toutAnimationHisBoot = function(toutObject, setOpacity, zoomFactor) {
	// Set font according to tout type
	var toutType = JQ(toutObject).attr("class")
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Rhode-SemiboldCondensed');
	} 
	else if (useSiteFont == 2) {
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttitle span');
	Cufon.replace('a.' + toutType + ' span.touttext span.touttextline');
	
	// Initialise event queuing vars
	var currentHisBootAnimation = null;
	var nextHisBootAnimation = null;
	
	// Initialise animation vars
	if (zoomFactor == undefined) {
		var zoomFactor = 0.05;
	}
	var zoomWidth = parseInt(toutObject.width() * zoomFactor);
	var zoomHeight = parseInt(toutObject.height() * zoomFactor);		
	var opacFactor = 0.3;
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutTitleLines = toutTitle.children("span");
	var toutText = JQ(toutObject).find("span.touttext");
	var toutTextLines = JQ(toutObject).find("span.touttext span.touttextline");
	var toutImg = JQ(toutObject).find("img.zoom");
	var toutArrow = JQ(toutObject).find("span.toutarrow");

    if(!(JQ.browser.msie)){
        JQ(toutArrow).css({top: parseInt(toutText.outerHeight()) + JQ(toutText).position().top + 10 + "px"});
    }
	// Use opacity on text only if required
	if (setOpacity) {
		toutTitle.css({opacity: 0.9});
		toutText.css({opacity: 0.9});
	}
	JQ(toutObject).find('span.png').pngFix();

	// Event handlers
	toutObject.mouseenter( 
		function() {
			if (currentHisBootAnimation) {
				nextHisBootAnimation = "enter";
				return;
			}
			noZoom = false;
			currentHisBootAnimation = "enter";
			zoomIn(toutImg,zoomWidth,zoomHeight,opacFactor);
			slideOut(toutTitle, 0, 80, function() {
				slideIn(toutText, 0, 80, function() {
					setTimeout(function() { 
						slideIn(toutArrow, 0, 100, function() {
							currentHisBootAnimation = null;
							if (nextHisBootAnimation == "enter") {
								nextHisBootAnimation = null;
							}
							else if (nextHisBootAnimation == "leave") {
								toutObject.mouseleave();
							}
						})
					}, 100);
				});
			});			
		}
	);
	toutObject.mouseleave(
		function() {
			if (currentHisBootAnimation) {
				nextHisBootAnimation = "leave";
				return;
			}
			currentHisBootAnimation = "leave";
			noZoom = false;
			zoomOut(toutImg,zoomWidth,zoomHeight);
			slideOut(toutArrow, 0, 100, function() {
				setTimeout(function() { 
					slideOut(toutText, 0, 80, function() {
						setTimeout(function() { 
							slideIn(toutTitle, 0, 80, function() {
								currentHisBootAnimation = null;  
								if (nextHisBootAnimation == "leave") {
									nextHisBootAnimation = null;
								}
								else if (nextHisBootAnimation == "enter") {
									toutObject.mouseenter();
								}
							});
						}, 100);
					});
				}, 100);
			});  
		}
	);
}

// Animation - Equipment & Nike Pro Touts
var toutAnimationExplore = function(toutObject,doShift) {
	// Set font
	var toutType = JQ(toutObject).attr("class");
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Rhode-MediumCondensed');
	} 
	else if (useSiteFont == 2) {
		JQ(toutObject).find('span.touttitle span').css({'font-size': '22px', height: '22px' });
		JQ(toutObject).find('em').css({'font-size': '28px', height: '28px'});
		JQ(toutObject).find('span.touttext span.touttextline').css({'font-size': '22px', height: '22px'});
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttitle span')('a.' + toutType + ' span.touttext span.touttextline');
	
	// Initialise event queuing vars
	var currentExploreAnimation = null;
	var nextExploreAnimation = null;
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutTextContainer = JQ(toutObject).find("span.touttext");
	var toutText = JQ(toutObject).find("span.touttext span.touttextline");
	var toutArrow = JQ(toutObject).find("span.toutarrow");
	var toutImg = JQ(toutObject).find("img.zoom");
	
	// Initialise animation vars (dependant on if its a zoom or shift animation)
	if (doShift) {
		var shiftFactor = toutImg.position().left;
	}
	else {
		var opacFactor = 0.4;
		var zoomFactor = 0.08;
		var zoomWidth = parseInt(toutObject.width() * zoomFactor);
		var zoomHeight = parseInt(toutObject.height() * zoomFactor);
	}
	var hrPadding = 5;
	var arrowPadding = 15;
	var toutHr = JQ(toutObject).find(".hrBase");
	var hrPos = parseInt(toutTitle.outerHeight()) + JQ(toutTitle).position().top + hrPadding;
	var hrPosOver = parseInt(toutTextContainer.outerHeight()) + JQ(toutTextContainer).position().top + hrPadding;
	JQ(toutHr).css({top: hrPos + "px" });
	JQ(toutArrow).css({top: hrPosOver + arrowPadding + "px"});
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			if (currentExploreAnimation) {
				nextExploreAnimation = "enter";
				return;
			}
			currentExploreAnimation = "enter";
			
			// Nike Pro tout shifts intead of zooms
			if (doShift) {
				toutImg.animate({left: 0}, 200);
			} else {
				noZoom = false;
				zoomIn(toutImg,zoomWidth,zoomHeight,opacFactor);
			}
			toutTitle.fadeOut(100, function() {
				toutHr.animate({top: parseInt(hrPosOver) - 3}, 170, "swing", function() {
					JQ(this).animate({top: hrPosOver },300);
					JQ(toutText).css({margin: '0px', display: 'none'}).fadeIn(150);
					setTimeout(function() { 
						slideIn(toutArrow, 0, 100, function() {
							currentExploreAnimation = null;
							if (nextExploreAnimation == "enter") {
								nextExploreAnimation = null;
							}
							else if (nextExploreAnimation == "leave") {
								toutObject.mouseleave();
							}
						});
					}, 200);
				});
			});
		}
	);
	toutObject.mouseleave(
		function() {
			if (currentExploreAnimation) {
				nextExploreAnimation = "leave";
				return;
			}
			currentExploreAnimation = "leave";
			
			if (doShift) {
				toutImg.animate({left: shiftFactor + 'px'}, 200);
			} 
			else {
				noZoom = false;
				zoomOut(toutImg,zoomWidth,zoomHeight);
			}
			slideOut(toutArrow, 0, 100);
			JQ(toutText).fadeOut(150);
			toutHr.animate({top: parseInt(hrPos)+7}, 170, "swing", function() {
				JQ(this).animate({top: hrPos },300);
				toutTitle.fadeIn(150, function() {
					currentExploreAnimation = null;  
					if (nextExploreAnimation == "leave") {
						nextExploreAnimation = null;
					}
					else if (nextExploreAnimation == "enter") {
						toutObject.mouseenter();
					}
				});
			});
		}
	);
}

// Animation - NikeID Tout
var toutAnimationNikeId = function(toutObject, opac) {
	// Set font
	var toutType = JQ(toutObject).attr("class");
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Helvetica Bold Cond');
	} 
	else if (useSiteFont == 2) {
		JQ(toutObject).find('span.touttitle .toutlabel').css({'font-size': '11px', height: '11px'});
		JQ(toutObject).find('span.touttitle .touttextline span').css({'font-size': '9px', height: '10px'});
		JQ(toutObject).find('span.touttitle .touttextline em').css({'font-size': '9px', height: '10px'});
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttitle span.touttextline')('a.' + toutType + ' span.touttitle span.toutlabel')('a.' + toutType + ' span.touttext span');
	
	// Initialise event queuing vars
	var currentNikeIdAnimation = null;
	var nextNikeIdAnimation = null;
	
	// Initialise animation vars
	var zoomFactor = 0.2;
	var zoomWidth = parseInt(toutObject.width() * zoomFactor);
	var zoomHeight = parseInt(toutObject.height() * zoomFactor);		
	if (opac == undefined) {
		var opac = 0.5;
	}
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutText = JQ(toutObject).find(".touttext");
	var toutImg = JQ(toutObject).find("img.zoom");
	JQ(toutObject).find('span.png').pngFix();
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			if (currentNikeIdAnimation) {
				nextNikeIdAnimation = "enter";
				return;
			}
			currentNikeIdAnimation = "enter";
			
			// If ie6 - no zoom animation on transparent pngs
			if (!window.XMLHttpRequest) {
				noZoom = true;
			}
			zoomIn(toutImg,zoomWidth,zoomHeight);
			toutTitle.animate({ marginTop: '80px'}, 70, function() { 
				setTimeout(function() { 
					toutText.animate({ marginTop: '0px'}, 70, function() {
						JQ(toutObject).find('span.png').pngFix();
						setTimeout(function() {
							currentNikeIdAnimation = null;
							if (nextNikeIdAnimation == "enter") {
								nextNikeIdAnimation = null;
							}
							else if (nextNikeIdAnimation == "leave") {
								toutObject.mouseleave();
							}
						}, 200);
					});
				}, 200);
			});			
		}
	);	
	toutObject.mouseleave(
		function() {
			if (currentNikeIdAnimation) {
				nextNikeIdAnimation = "leave";
				return;
			}
			currentNikeIdAnimation = "leave";
			if (!window.XMLHttpRequest) {
				noZoom = true;
			}
			zoomOut(toutImg,zoomWidth,zoomHeight);
			toutText.animate({ marginTop: '100px'}, 70, function() { 
				setTimeout(function() { 
					toutTitle.animate({ marginTop: '0px'}, 70, function() {
						JQ(toutObject).find('span.png').pngFix();
						currentNikeIdAnimation = null;  
						if (nextNikeIdAnimation == "leave") {
							nextNikeIdAnimation = null;
						}
						else if (nextNikeIdAnimation == "enter") {
							toutObject.mouseenter();
						}
					});
				}, 300);
			});
		}
	);
}

// Animation - Nike Choose Tout
var toutAnimationChoose = function(toutObject) {
	// Set font
	var toutType = JQ(toutObject).attr("class");
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Rhode-SemiboldCondensed');
	}
	else if (useSiteFont == 2) {
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttitle');
	if (useSiteFont == 1) {
		Cufon.set('fontFamily', 'Helvetica Bold Cond');
	}
	else if (useSiteFont == 2) {
		Cufon.set('fontFamily', 'Arial');
	}
	Cufon.replace('a.' + toutType + ' span.touttext span');

	// Initialise event queuing vars
	var currentChooseAnimation = null;
	var nextChooseAnimation = null;
	
	// Initialise animation vars
	var zoomFactor = 0.25;
	var zoomWidth = parseInt(toutObject.width() * zoomFactor);
	var zoomHeight = parseInt(toutObject.height() * zoomFactor);
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutText = JQ(toutObject).find("span.touttext");
	var toutImg = JQ(toutObject).find("img.zoom");
	var toutTextPos = toutText.position().top;
	var toutTextPosHide = toutTextPos+40;
	
	toutText.css({top: toutTextPosHide + 'px' });
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			if (currentChooseAnimation) {
				nextChooseAnimation = "enter";
				return;
			}
			currentChooseAnimation = "enter";
			toutImg.animate({top: -20 + 'px'}, 150, 'swing');
			toutText.animate({ top: toutTextPos + 'px'}, 100, 'swing');
			toutObject.find('span.toutflash').animate({ 
				opacity: 0.3
			}, 150, function() {
				JQ(this).animate({ 
					opacity: 0
				}, 400, function() {
					currentChooseAnimation = null;
					if (nextChooseAnimation == "enter") {
						nextChooseAnimation = null;
					}
					else if (nextChooseAnimation == "leave") {
						toutObject.mouseleave();
					}
				});
			});
		}
	);
	toutObject.mouseleave(
		function() {
			if (currentChooseAnimation) {
				nextChooseAnimation = "leave";
				return;
			}
			currentChooseAnimation = "leave";
			
			toutText.animate({ top: toutTextPosHide + 'px'}, 100, 'swing');
			toutImg.animate({top: 0 + 'px'}, 150, 'swing', function() {
				currentChooseAnimation = null;  
				if (nextChooseAnimation == "leave") {
					nextChooseAnimation = null;
				}
				else if (nextChooseAnimation == "enter") {
					toutObject.mouseenter();
				}
			});
		}
	);
}





// Animation - NikeBoot Elite Tout LEFT (large)
var toutAnimationNikeEliteLarge = function(toutObject, opac) {
	// Set font
	var toutType = JQ(toutObject).attr("class");
	
	// Initialise event queuing vars
	var currentNikeEliteAnimation = null;
	var nextNikeEliteAnimation = null;
	
	// Initialise animation vars	
	if (opac == undefined) {
		var opac = 0.5;
	}
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutText = JQ(toutObject).find(".touttext");
	
	var toutImg = JQ(toutObject).find("img.zoom");
	JQ(toutObject).find('span.png').pngFix();
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			noZoom = true;
			zoomIn(toutImg,0,0,opac);
		}
	);	
}

// - NikeBoot Elite Tout Right (small)
var toutAnimationNikeElite = function(toutObject, opac) {
	// Set font
	var toutType = JQ(toutObject).attr("class");
	
	
	// Initialise event queuing vars
	var currentNikeEliteAnimation = null;
	var nextNikeEliteAnimation = null;
	
	// Initialise animation vars	
	if (opac == undefined) {
		var opac = 0.5;
	}
	
	// Initialise objects
	var toutTitle = JQ(toutObject).find("span.touttitle");
	var toutText = JQ(toutObject).find(".touttext");
	
	var toutImg = JQ(toutObject).find("img.zoom");
	JQ(toutObject).find('span.png').pngFix();
	
	// Event handlers
	toutObject.mouseenter( 
		function() {
			noZoom = true;
			zoomIn(toutImg,0,0,opac);
			
		}
	);

	toutObject.click(
		function() {
			// resolve the problem with Opera 9 scrolling function
			if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
				JQ('html').animate({scrollTop:0}, 1500);
			} else { 
				JQ('html, body').animate({scrollTop:0}, 1500);
			}
			setTimeout(function(){  
				overlayPopup();
				var toutBootEliteVidGuid = JQ("a.toutbootelite").attr("rel");
				injectVideo('flashVid', toutBootEliteVidGuid, GLOBAL_VARIABLES.locale);
				JQ(".overlay-close-icon").click(
					function() {
						hideVideoOverlay();
						return false;
					});
			}, 2000);
			return false;
		}
	);
}



function injectVideo(moduleElement, guid, loc){

	var flashVars = {};
	var flashParams = {};
	var flashAttributes = {};

	var moduleWidth = "908";
	var moduleHeight = "510";
	
	var moduleSWF = "http://www.nike.com/nikeos/global/modules/video/v1/swf/video_player_v2_0.swf";
	
	flashParams.wmode = "transparent";
	flashParams.scale = "noscale";
	flashParams.allowScriptAccess = "always";
	flashParams.allowFullScreen = "true";
	flashParams.bgColor = "ffffff";

	flashVars.guid = guid;
	flashVars.locale = GLOBAL_VARIABLES.locale;
	flashVars.regionConfig = "http://www.nike.com/nikeos/global/modules/video/v1/xml/reg/reg_config_"+loc+".xml";
	flashVars.siteConfig = "http://www.nike.com/nikefootball/global/xml/videoSiteConfig.xml";
	flashVars.currentUrl = escape(location.href);
	flashVars.disableEnablement = "true";

	swfobject.embedSWF(moduleSWF, moduleElement, moduleWidth, moduleHeight, "9", flashParams.bgColor, flashVars, flashParams, flashAttributes);

};



function overlayPopup(){
	// hide the flash from vision
//	JQ("div#flashPanel").css("visibility", "hidden");
	
	// Add container for simple video overlays
	
	JQ("#page-content").append(
		'<div id="videoOverlayContainer"></div><div id="videoOverlayContent"><a class="overlay-close-icon">x</a><div id="flashVid"></div></div>'
	);
	
};

function hideVideoOverlay(){
	JQ("#videoOverlayContent").fadeTo("fast", 0);
	JQ("#videoOverlayContainer").fadeTo("slow", 0, function(){
		JQ("#videoOverlayContainer").remove();
		JQ("#videoOverlayContent").remove();
	});
//	JQ("div#flashPanel").css("visibility", "visible");
	
};

/** ============================================================================ **/


/**
	Reusable Animation Functions 
**/

// Zoom in and "white flash" effect
var zoomIn = function(toutImg, zoomWidth, zoomHeight, opac) {
	var flashOpacity;
	if (opac != undefined) {
		flashOpacity = opac;
	}
	else {
		flashOpacity = 0.7;
	}
	if (!noZoom) {
		toutImg.animate({
			width: "+=" + zoomWidth,
			height: "+=" + zoomHeight,
			left: "-=" + parseInt(zoomWidth/2),
			top: "-=" + parseInt(zoomHeight/3)
		}, 300).parent().parent().find('span.toutflash').animate({ 
			opacity: flashOpacity
		}, 200, function() {
			JQ(this).animate({ 
				opacity: 0
			}, 500);
		});
	}
	else {
		toutImg.parent().parent().find('span.toutflash').animate({ 
			opacity: flashOpacity
		}, 200, function() {
			JQ(this).animate({ 
				opacity: 0
			}, 500);
		});
	}
}

// Zoom out effect
var zoomOut = function(toutImg, zoomWidth, zoomHeight) {
	if (!noZoom) {
		toutImg.animate({
			width: "-=" + zoomWidth,
			height: "-=" + zoomHeight,
			left: "+=" + parseInt(zoomWidth/2),
			top: "+=" + parseInt(zoomHeight/3)
		}, 300);
	}
}

// Slide text in - Optional parameters speed & callback function
var slideIn = function(elArray, index, speed, callback) {
	if (speed == undefined) {
		speed = 80;
	}
	else if (typeof(speed) == "function") {
		callback = speed;
		speed = 80;
	}
	JQ(elArray[index]).animate({ marginLeft: '0px'}, speed, function() { 
		index=index+1; 
		if (index < elArray.length) {
			slideIn(elArray, index, callback);
		} 
		else {
			if (callback != undefined)
				callback();
		}
	});
}

// Slide text out - Optional parameters speed & callback function
var slideOut = function(elArray, index, speed, callback) {
	if (speed == undefined) {
		speed = 80;
	}
	else if (typeof(speed) == "function") {
		callback = speed;
		speed = 80;
	}
	
	JQ(elArray[index]).animate({ marginLeft: '-320px'}, speed, function() { 
		index=index+1; 
		if (index < elArray.length) {
			slideOut(elArray, index, callback);
		}
		else {
			if (callback != undefined)
				callback();
		}
	});
}
