/**
 * jQuery Banner Plugin v1.0
 * @author 	Jonathan Cochran <jono.cochran@gmail.com>
 * @uri		http://www.project66.net/jquery-banners/
 * 
 * SLIDES IMAGES HORIZONTALLY OR VERTICALLY
 * Requires the jQuery Easing Plugin: http://gsgd.co.uk/sandbox/jquery/easing/
 * Require the jQuery Timer Plugin (if used): http://jquery.offput.ca/every/
 *
 * Open source under the BSD License. 
 * 
 * Copyright © 2010 Jonathan Cochran
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 *
 * USAGE 
 * ---------------------------------------------------------- *
 * @param	orient 		- (str)		horiztontal or vertical
 * @param	imgW 		- (int)		width of images
 * @param	imgH 		- (int)		height of images
 * @param	iSpeed 		- (int)		milliseconds
 * @param	strEasing 	- (str)		easing function (requires jquery easing plugin)
 * @param	trigger	 	- (mixed)	(obj or str): object to trigger clicks eg: $('a.scroll-right'), 
 *					      OR str timer. Use like timer=5000 where 5000 milliseconds
 * @example: 				
			//Homepage banner - orient = vertical or horizontal
			$('#banner ul').slideImages('horizontal', 960, 285, 200, 'expoinout', 'timer=5000');  
 * --------------------------------------------------------- */

(function($) {
	jQuery.fn.slideImages = function(orient, iImgW, iImgH, iSpeed, strEasing, trigger) {
		//Starting positions
		var iBannerX = 0;
		var iBannerY = 0;
		var objBanner = $(this);
		var objBannerImages = $('img', objBanner);
		var iBannerWidth = Number(objBannerImages.length)*iImgW;
		var iBannerHeight = Number(objBannerImages.length)*iImgH;
		
		//Establish the trigger to cycle images...
		//Use a timer instead
		if (typeof(trigger) == "string" && trigger.substr(0,5) == "timer")
		{
			iMilliSeconds = Number(trigger.replace('timer=', ''));
			trigger = objBanner; //Make it the banner, to fire only once
			function resumeTime()
			{
				$(document).everyTime(iMilliSeconds, function(i) { 
					trigger.trigger('click');
				});
			}
			resumeTime();
		}
		//Object will trigger the slide
		else if(trigger != "" && typeof(trigger) == "object") 
		{
			//do nothing... keep it as an object
		}
		else
		{
			//make the images clickable
			trigger = objBannerImages;
		}
				
		//Slide banners vertically
		if (orient == "vertical")
		{	
			objBanner.height(iBannerHeight);
			trigger.click(function() {
				iBannerY -= iImgH;
				((-1*iBannerY) == iBannerHeight) ? iBannerY = 0 : "";

				objBanner.stop().animate( { 'marginTop' : iBannerY }, iSpeed, strEasing );
			});
		}

		//Slide banners horizontally
		if (orient == "horizontal")
		{			
			objBanner.width(iBannerWidth);
			trigger.click(function() {
				iBannerX -= iImgW;
				((-1*iBannerX) == iBannerWidth) ? iBannerX = 0 : "";
				objBanner.animate( { 'marginLeft' : iBannerX }, iSpeed, strEasing );
			});
		}
		

	};   
})(jQuery);
