/*!
 * Overscroll v1.3.0
 *  A jQuery Plugin for emulating the iPhone scrolling experience in a browser.
 *  http://azoffdesign.com/overscroll
 *
 * Intended for use with the latest jQuery
 *  http://code.jquery.com/jquery-latest.min.js
 *
 * Copyright 2010, Jonathan Azoff
 * Dual licensed under the MIT or GPL Version 2 licenses.
 *  http://jquery.org/license
 *
 * Date: Wednesday, March 31st 2010
 */

/* 
 * Usage:
 * 
 * $(selector).overscroll([options]);
 *  "options" is an optional JavaScript object that you may pass if you would like to customize
 *  the experience of the overscroll element. Below is a list of properties that you may set on
 *  the options object and their respective effect:
 *   - options.showThumbs   {Boolean} Designates whether or not to show the scroll-bar thumbs
 *                                    on the scrollable container (default true).
 *   - options.openedCursor {String}  A url pointing at a .cur file to be used as the cursor when
 *                                    hovering over the overscrolled element (default 'opened.cur').
 *   - options.closedCursor {String}  A url pointing at a .cur file to be used as the cursor when
 *                                    dragging the overscrolled element (default 'closed.cur').
 *
 * Notes:
 * 
 * In order to get the most out of this plugin, make sure to only apply it to parent elements 
 * that are smaller than the collective width and/or height then their children. This way,
 * you can see the actual scroll effect as you pan the element.
 *
 * You MUST have two cursors to get the "hand" to show up, open, and close during the panning 
 * process. You can store the cursors wherever you want, just make sure to reference them in 
 * the code below. I have provided initial static linkages to these cursors for your 
 * convenience.        
 *
 * Changelog:
 *
 * 1.3.0
 *   - Merged iThumbs and Overscroll
 *   - Added the ability to pass in options
 *   - Moved all code to GitHub
 *   - Several improvements to the thumb code
 *   - Greased up the scroll a bit more
 *   - Removed the jerky animation on mouse wheel
 *   - Added caching for cursors
 * 1.2.1
 *   - Made "smart" click support "smarter" :)
 *   - Added JSLint validation to the build process
 *	 - Removed unused variables and cleaned up code
 * 1.2.0
 *   - Updated license to match the jQuery license (thanks Jesse)
 *   - Added vertical scroll wheel support (thanks Pwakman)
 *   - Added support to ignore proprietary drag events (thanks Raphael)
 *   - Added "smart" click support for clickable elements (thanks Mark)
 * 1.1.2
 *   - Added the correct click handling to the scroll operation (thanks Evilc)
 * 1.1.1
 *   - Made scroll a bit smoother (thanks Nick)
 * 1.1.0
 *   - Optimized scrolling-internals so that it is both smoother and more memory efficient 
 *     (relies entirely on event model now). 
 *   - Added the ability to scroll horizontally (if the overscrolled element has wider children).
 * 1.0.3
 *   - Extended the easing object, as opposed to the $ object (thanks Andre)
 * 1.0.2
 *   - Fixed timer to actually return milliseconds (thanks Don)
 * 1.0.1
 *   - Fixed bug with interactive elements and made scrolling smoother (thanks Paul and Aktar)
 */

/*jslint onevar: true, strict: true */
/*global jQuery: false */
"use strict"; 

(function($, o){
	// create overscroll
	o = $.fn.overscroll = function(options) {
		return this.each(function(){
			o.init($(this), options);
		});
	};
	
	$.extend(o, {
		
		// events handled by overscroll
		events: {
			wheel: "mousewheel DOMMouseScroll",
			start: "select mousedown touchstart",
			drag: "mousemove touchmove",
			end: "mouseup mouseleave touchend",
			scroll: "scroll",
			ignored: "dragstart drag",
			click: "click"
		},
		
		// to save a couble bits
		div: "<div/>",
		
		// constants used to tune scrollability and thumbs
		constants: {
			scrollDuration: 1000,
			captureThreshold: 4,
			wheelDeltaMod: -18,
			scrollDeltaMod: 5.7,
			thumbThickness: 8,
			thumbOpacity: 0.7,
			boundingBox: 1000000,
			securityBufferLenght: 4
		},
		
		globals: {
			currentArrayIndex:0,
			imageToSwitch:0,
			scollablePics: null,
			bufferPics:null
			
		},
		
		// main initialization function
		init: function(target, options, data) {
			while (options.imgArray.length < 3 * options.showedImages) {
				var actualImgArray = options.imgArray.slice();
				var actualCaptionArray = options.captionArray.slice();
				for(i=0;  i<actualImgArray.length; i++ ){
					var singleImage = actualImgArray[i];
					var singelCaption = actualCaptionArray[i];
					options.imgArray.push(singleImage);
					options.captionArray.push(singelCaption);
				}
			}
			
			var scrollStyle = {'width': options.imageWidth * options.showedImages + 'px', 'height': options.imageHeight + 'px'};
            
            var scrollPicsStyle = {'width': options.imageWidth * options.showedImages * 3 + 'px'};
            
           	var picsDivStyle = {'width': options.imageWidth + 'px', 'height': options.imageHeight + 'px'};
			
						
			var captionStart = "" +
				"<span class=\"caption\">" +
				"<span class=\"socialnet\">" +
				"<img onclick=\"animateSN(this)\" class=\"folpetto\" src=\"" + options.themeBaseUrl + "/images/scroll_gallery/folpetto.png\" border=\"0\" alt=\"logo\" /><br />" +
				
				//"<a  onClick=\"window.open('http://www.facebook.com/sharer.php?u={imageLoaded}&t={title}','name', 'width=620, height=440')\"><img class=\"sn-facebook\" src=\"" + options.themeBaseUrl + "/images/custom_bcom/FaceBook-icon.png\" border=\"0\" alt=\"facebook\" /></a><br />" +
				//"<a  onClick=\"window.open('http://twitter.com/home?status={imageLoaded}','name', 'width=1024, height=650')\"><img class=\"sn-twitter\" src=\"" + options.themeBaseUrl + "/images/custom_bcom/Twitter-icon.png\" border=\"0\" alt=\"twitter\" /></a>" +
				
				"<a  onClick=\"window.open('http://www.facebook.com/sharer.php?u={currentPath}&t={title}','name', 'width=620, height=440')\"><img class=\"sn-facebook\" src=\"" + options.themeBaseUrl + "/images/custom_bcom/FaceBook-icon.png\" border=\"0\" alt=\"facebook\" /></a><br />" +
				"<a  onClick=\"window.open('http://twitter.com/home?status={currentPath}','name', 'width=1024, height=650')\"><img class=\"sn-twitter\" src=\"" + options.themeBaseUrl + "/images/custom_bcom/Twitter-icon.png\" border=\"0\" alt=\"twitter\" /></a>" +
				
				
				"</span>" +
				"<span style=\"visibility:hidden;width:" + (options.imageWidth - 20) + "px;\" onclick=\"hideCaption(this)\" class=\"content captionToHide\">";
			var captionEnd = "</span>" + 
				"<img width=\"21\" height=\"21\" style=\"top:" + (options.imageHeight - 31) + "px\" class=\"info\" onclick=\"showCaption(this)\" src=\"" + options.themeBaseUrl + "/images/custom_bcom/info.png\" border=\"0\" alt=\"info\" />" + 
				"</span>";
			
			target.addClass("scroll"); 
			
			target.append("<div></div>").children(':last').addClass("pics").addClass("showed");
			
			target.after("<div></div>").next().addClass("pics").addClass("buffer");
			
			target.after("<div></div>").next().addClass("securityBuffer");
			
			
			for(i=0; i<o.constants.securityBufferLenght ;i++){
				$(".securityBuffer").append("<div></div>");
				$(".securityBuffer").children(':last').addClass("securityBufferChild"+i);
			}
			o.globals.scollablePics= $(".showed");
			o.globals.bufferPics = $(".buffer").hide();
			o.globals.captionStart = captionStart;
			o.globals.captionEnd = captionEnd;
			
			for(i=0; i< options.showedImages*3 ;i++){
				var initFotoIndex=0;
				if (i<options.showedImages ){
					initFotoIndex = options.imgArray.length +i - options.showedImages;	
				}else{
					initFotoIndex = i - options.showedImages;
				}
				
				var pathname = window.location.pathname;
				
				var imgLoaded =  options.imgArray[initFotoIndex];
				//var currCaptionStart = captionStart.replace(/{imageLoaded}/g, "http://www.benetton.com/" + escape(imgLoaded));
				var d = new Date();

				var currCaptionStart = captionStart.replace(/{currentPath}/g, "http://www.benetton.com/" + pathname+escape("?imageIndex=" +initFotoIndex));
				
				currCaptionStart = currCaptionStart.replace(/{title}/g, "www.benetton.com");
				o.globals.scollablePics.append("<div>" + currCaptionStart + options.captionArray[initFotoIndex] + ((options.captionArray[initFotoIndex]!="")?(captionEnd):("</span></span>")) + "</div>");
				var scollablePicsChild = o.globals.scollablePics[0].children[i];
				scollablePicsChild.style.backgroundImage="url("+imgLoaded+")";
				o.globals.bufferPics.append("<div>" + currCaptionStart + ((options.captionArray[initFotoIndex]!="")?(captionEnd):("</span></span>")) + "</div>");
				var bufferPicsChild = o.globals.bufferPics[0].children[i];
				bufferPicsChild.style.backgroundImage="url("+imgLoaded+")";
			}
			
			o.globals.currentArrayIndex = options.imgArray.length - options.showedImages;
			if(options.imageSearchIndex && options.imageSearchIndex!=0){
				(options.imageSearchIndex<0)?(options.imageSearchIndex=-options.imageSearchIndex):(options.imageSearchIndex);
				(options.imageSearchIndex>options.imgArray.length)?(options.imageSearchIndex=options.imgArray.length):(options.imageSearchIndex);
				var bufferPics= o.globals.bufferPics;
				var scollablePics = o.globals.scollablePics;
				if(options.imageSearchIndex>=options.showedImages){
					o.globals.currentArrayIndex = options.imageSearchIndex-options.showedImages;
				}else{
					o.globals.currentArrayIndex = options.imgArray.length-options.showedImages+options.imageSearchIndex;
				}
				var arrayShift = o.globals.currentArrayIndex;
					for (var i = 0; i < options.showedImages * 3; i++) {
						var modifiedIndex = i + arrayShift;
						if (modifiedIndex >= options.imgArray.length) {
							modifiedIndex = modifiedIndex - options.imgArray.length;
							if (arrayShift >= options.imgArray.length) {
								o.globals.currentArrayIndex = arrayShift - options.imgArray.length;
							}
						}
						if (modifiedIndex < 0) {
							modifiedIndex = modifiedIndex + options.imgArray.length;
							if (arrayShift < 0) {
								o.globals.currentArrayIndex = arrayShift + options.imgArray.length;
							}
						}
						var imgLoaded = options.imgArray[modifiedIndex];
						var singleChild = bufferPics[0].children[i];
						singleChild.style.backgroundImage = "url(" + imgLoaded + ")";
					}	
				scollablePics.html(bufferPics.html());
				options.imageSearchIndex=0;
			}
			
			
			
			for(i=0; i<o.constants.securityBufferLenght ;i++){
			    var imgLoaded;
				if(i<o.constants.securityBufferLenght/2){
					imgLoaded =  options.imgArray[o.globals.currentArrayIndex-i-1];
				}else{
					imgLoaded =  options.imgArray[options.showedImages*2 +i-1];
				}
				$(".securityBufferChild"+i).css({
					'background-image': 'url(' + imgLoaded + ')'
				});
			}
			
			$(".scroll").css(scrollStyle);
			$(".scroll .pics").css(scrollPicsStyle);
			$(".pics div").css(picsDivStyle);
			
			data = {
				sizing: o.getSizing(target)
			};
			
			options = $.extend({
				openedCursor: options.themeBaseUrl + "/cursors/opened.cur",
				closedCursor: options.themeBaseUrl + "/cursors/closed.cur",
				showThumbs: true,
				showedImages : 1,
				imageWidth:0,
				imageHeight:0,
				imgArray : [],
				imageSearchIndex: 0								
			}, (options || {}));
			
			
			// cache cursors
			options.cache = { openedCursor: new Image(), closedCursor: new Image() };
			options.cache.openedCursor.src = options.openedCursor;
			options.cache.closedCursor.src = options.closedCursor;
			
			if(options.imgArray.length>options.showedImages ){
			target.css({"cursor":"url("+options.openedCursor+"), default", "overflow": "hidden"})
				.bind(o.events.wheel, data, o.wheel)
				.bind(o.events.start, data, o.start)
				.bind(o.events.end, data, o.stop)
				.bind(o.events.ignored, function(){return false;}); // disable proprietary drag handlers
			}else{
				target.css({"overflow": "hidden"});
				try {
					$(".scrollable-left-arrow").css({"opacity": 0, "filter" : alpha(opacity=0)});
				}

				catch(e) {}
				try {
           				$(".scrollable-right-arrow").css({"opacity": 0, "filter" : alpha(opacity=0)});
				}
				catch(e){}
			}	
				
			
			
			$(".scrollable-left-arrow").bind(o.events.click,data, function(event) {
				o.stop(event, 0, 0, "right");
            });
            $(".scrollable-right-arrow").bind(o.events.click,data, function(event) {
                o.stop(event, 0, 0, "left");
            });
			
			
			target.scrollTop(0).scrollLeft(options.imageWidth*options.showedImages);// to ensure correct initialization	
			
			if(options.showThumbs) {
				
				data.thumbs = { visible: false };
								
				if(data.sizing.container.scrollWidth > 0) {
					data.thumbs.horizontal = $(o.div).css(o.getThumbCss(data.sizing.thumbs.horizontal)).fadeTo(0, 0);
					target.prepend(data.thumbs.horizontal);	
				}
				
				if(data.sizing.container.scrollHeight > 0) {
					data.thumbs.vertical = $(o.div).css(o.getThumbCss(data.sizing.thumbs.vertical)).fadeTo(0, 0);
					target.prepend(data.thumbs.vertical);				
				}
				
				data.sizing.relative = data.thumbs.vertical || data.thumbs.horizontal;
				
				target.scrollTop(0).scrollLeft(options.imageWidth*options.showedImages);// to ensure correct initialization	
				
				if(data.sizing.relative) {
					data.sizing.relative.oldOffset = data.sizing.relative.offset();
					target.scrollTop(o.constants.boundingBox).scrollLeft(o.constants.boundingBox);
					data.sizing.relative.remove().prependTo(target);
					data.sizing.relative.newOffset = data.sizing.relative.offset();
					data.sizing.relative = 
						data.sizing.relative.oldOffset.left != data.sizing.relative.newOffset.left ||
						data.sizing.relative.oldOffset.top != data.sizing.relative.newOffset.top;
					target.scrollTop(0).scrollLeft(options.imageWidth*options.showedImages);
					
					target.bind(o.events.scroll, data, o.scroll);
				}

			}
			
			data.target = target;
			data.options = options;
		},
		
		// handles mouse wheel scroll events
		wheel: function(event, delta) {
			
			return false;
			
		},
		
		// starts the drag operation and binds the mouse move handler
		start: function(event) {

			event.data.target
				.css("cursor", "url("+event.data.options.closedCursor+"), default")
				.bind(o.events.drag, event.data, o.drag)
				.stop(true, true);
			
			
			event.data.position = { 
				x: event.pageX,
				y: event.pageY
			};
			
			event.data.clickPosition = { 
				x: event.pageX,
				y: event.pageY
			};
			
			event.data.capture = {};
			
			event.data.isDragging = false;
			
			return false;
			
		},
		
		// updates the current scroll location during a mouse move
		drag: function(event) {
			
			this.scrollLeft -= (event.pageX - event.data.position.x);
			this.scrollTop -=0;//(event.pageY - event.data.position.y);
			event.data.position.x = event.pageX;
			event.data.position.y = event.pageY;
			
			if (typeof event.data.capture.index === "undefined" || --event.data.capture.index === 0 ) {
				event.data.isDragging = true;
				event.data.capture = {
					x: event.pageX,
					y: event.pageY,
					index: o.constants.captureThreshold
				};
				
				if(event.data.thumbs && !event.data.thumbs.visible) {
					event.data.thumbs.visible = true;
					if(event.data.thumbs.vertical) {
						event.data.thumbs.vertical.stop(true, true).fadeTo("fast", o.constants.thumbOpacity);
					}
					if(event.data.thumbs.horizontal) {
						event.data.thumbs.horizontal.stop(true, true).fadeTo("fast", o.constants.thumbOpacity);
					}
				}
			}

			return true;
		
		},
		
		// called after a scroll event, moves the thumbs
		scroll: function(event, ml, mt, left, top) {

			left = event.data.target.scrollLeft();
			
			top = event.data.target.scrollTop();

			if (event.data.thumbs.horizontal) {
				ml = left * event.data.sizing.container.width / event.data.sizing.container.scrollWidth;
				mt = event.data.sizing.thumbs.horizontal.top;
				if(event.data.sizing.relative) { ml += left; mt += top; }
				event.data.thumbs.horizontal.css("margin", mt + "px 0 0 " + ml + "px");	
			}
			
			if (event.data.thumbs.vertical) {
				ml = event.data.sizing.thumbs.vertical.left;
				mt = top * event.data.sizing.container.height / event.data.sizing.container.scrollHeight;
				if(event.data.sizing.relative) { ml += left; mt += top; }
				event.data.thumbs.vertical.css("margin", mt + "px 0 0 " + ml + "px");
			}

		},
		
		// ends the drag operation and unbinds the mouse move handler
		stop: function(event, dx, dy, arrow) {
			if( typeof event.data.position !== "undefined" || arrow) {
                        $(".captionToHide").each(
                                function() {
                                        hideCaption($(this));
                                }
                        );

				var delta;
				if (typeof event.data.position !== "undefined") {
				event.data.target
					.css("cursor", "url("+event.data.options.openedCursor+"), default")
					.unbind(o.events.drag, o.drag);
				
					delta = event.pageX - event.data.clickPosition.x;
                    			var imgWidth = event.data.options.imageWidth;
					}
					else {
						delta = 0;
						var imgWidth = event.data.options.imageWidth;
					}
					if (delta >0 && delta>imgWidth/3) {
                        var divisionRemainder = delta%imgWidth;
						absoluteImageToSwitch = Math.abs((delta - divisionRemainder)/imgWidth) + 1;
						dx = absoluteImageToSwitch*imgWidth - delta;
						o.globals.imageToSwitch = -absoluteImageToSwitch;
                    }else if(delta >= 0 && this.scrollLeft>0){
						dx = - delta;
						o.globals.imageToSwitch = 0;
					}
					else if (arrow == "left") {
						o.globals.imageToSwitch = 1;
						dx = -imgWidth;
					}
					else if (arrow == "right") {
                                                o.globals.imageToSwitch = -1;
                                                dx = imgWidth;
					}
					else if (delta < 0 && delta<-imgWidth/3) {
                        var divisionRemainder = delta%imgWidth;
						absoluteImageToSwitch = Math.abs((delta - divisionRemainder)/imgWidth) + 1;
						dx = -absoluteImageToSwitch*imgWidth - delta;
						o.globals.imageToSwitch = absoluteImageToSwitch;
                    }else if (delta <= 0 && this.scrollLeft < this.offsetWidth*imgWidth*event.data.options.showedImages -imgWidth){
						dx = - delta;
						o.globals.imageToSwitch = 0;
					}
					
						var bufferPics= o.globals.bufferPics;
						o.globals.currentArrayIndex += o.globals.imageToSwitch;
						var arrayShift = o.globals.currentArrayIndex;
					if (o.globals.imageToSwitch != 0) {
						for(var i=0; i<event.data.options.showedImages*3 ;i++){
							var modifiedIndex=i +arrayShift;
							if(modifiedIndex>= event.data.options.imgArray.length ){
								modifiedIndex=modifiedIndex - event.data.options.imgArray.length;
								if(arrayShift>= event.data.options.imgArray.length ){
									o.globals.currentArrayIndex = arrayShift - event.data.options.imgArray.length;
								}
							}
							if(modifiedIndex < 0){
								modifiedIndex=  modifiedIndex + event.data.options.imgArray.length ;
								if(arrayShift< 0){
									o.globals.currentArrayIndex = arrayShift + event.data.options.imgArray.length;
								}
							}
							var imgLoaded =  event.data.options.imgArray[modifiedIndex];
							var singleChild = bufferPics[0].children[i];
							singleChild.style.backgroundImage="url("+imgLoaded+")";
										var pathname = window.location.pathname;
										//var currCaptionStart = o.globals.captionStart.replace(/{imageLoaded}/g, "http://www.benetton.com/" + escape(imgLoaded));
			               				var currCaptionStart = o.globals.captionStart.replace(/{currentPath}/g, "http://www.benetton.com/" + pathname+escape("?imageIndex=" +modifiedIndex));
                                			currCaptionStart = currCaptionStart.replace(/{title}/g, "www.benetton.com");
							singleChild.innerHTML = currCaptionStart + event.data.options.captionArray[modifiedIndex]+ ((event.data.options.captionArray[modifiedIndex]!="")?(o.globals.captionEnd):("</span></span>"));
							
						}
					}
					for(i=0; i<o.constants.securityBufferLenght ;i++){
						var imgLoaded;
						if(i<o.constants.securityBufferLenght/2){
							imgLoaded =  event.data.options.imgArray[(o.globals.currentArrayIndex-i<1)?(event.data.options.imgArray.length-i-1):(o.globals.currentArrayIndex-i-1)];
						}else{
							imgLoaded =  event.data.options.imgArray[(o.globals.currentArrayIndex + event.data.options.showedImages*3 +i>event.data.options.imgArray.length)?(o.globals.currentArrayIndex + event.data.options.showedImages*3 +i-event.data.options.imgArray.length-1):(o.globals.currentArrayIndex + event.data.options.showedImages*3 +i-1)];
						}
					$(".securityBufferChild"+i).css({
						'background-image': 'url(' + imgLoaded + ')'
						});
					}
					
					dy = 0;
					
                    $(".scrollable-left-arrow").unbind(o.events.click);
                    $(".scrollable-right-arrow").unbind(o.events.click);

					event.data.target.stop(true, false).animate({
						scrollLeft: event.data.target.scrollLeft() - dx,
						scrollTop: this.scrollTop - dy
					},{ 
						queue: false, 
						duration:   0.0008*dx*dx-1.72*Math.abs(dx)+1312, 
						easing: "cubicEaseOut",
						complete: function() {
							if(event.data.thumbs && event.data.thumbs.visible) {
								event.data.thumbs.visible = false;
								if(event.data.thumbs.vertical) {
									event.data.thumbs.vertical.stop(true, true).fadeTo("fast", 0);
								}
								if(event.data.thumbs.horizontal) {
									event.data.thumbs.horizontal.stop(true, true).fadeTo("fast", 0);
								}
							}
							var scollablePics = o.globals.scollablePics;
							var bufferPics= o.globals.bufferPics;
							if (o.globals.imageToSwitch != 0) {
								scollablePics.html(bufferPics.html());
								this.scrollLeft=event.data.options.imageWidth*event.data.options.showedImages; 
							}else{
								this.scrollLeft = event.data.options.imageWidth * event.data.options.showedImages;
							}
							$(".scrollable-left-arrow").bind(o.events.click,event.data, function(event) {
                                o.stop(event, 0, 0, "right");
                        	});
                        	$(".scrollable-right-arrow").bind(o.events.click,event.data, function(event) {
                            	o.stop(event, 0, 0, "left");
                        	});
						}
					});
				event.data.capture = event.data.position = undefined;
			}
			return !event.data.isDragging;
		},
		// gets sizing for the container and thumbs
		getSizing: function(container, sizing) {
		
			sizing = { };
			
			sizing.container = {
				width: container.width(),
				height: container.height()
			};
			
			container.scrollLeft(o.constants.boundingBox).scrollTop(o.constants.boundingBox);
			sizing.container.scrollWidth = container.scrollLeft();
			sizing.container.scrollHeight = container.scrollTop();							
			container.scrollTop(0).scrollLeft(0);
					
			sizing.thumbs = {
				horizontal: {
					width: sizing.container.width * sizing.container.width / sizing.container.scrollWidth,
					height: o.constants.thumbThickness,
					corner: o.constants.thumbThickness / 2,
					left: 0,
					top: sizing.container.height - o.constants.thumbThickness
				},
				vertical: {
					width: o.constants.thumbThickness,
					height: sizing.container.height * sizing.container.height / sizing.container.scrollHeight,
					corner: o.constants.thumbThickness / 2,
					left: sizing.container.width - o.constants.thumbThickness,
					top: 0
				}
			};
			
			sizing.container.width -= sizing.thumbs.horizontal.width;
			sizing.container.height -= sizing.thumbs.vertical.height;
			
			return sizing;
			
		},
		
		// gets the CSS object for a thumb
		getThumbCss: function(size) {
		
			return {
				position: "absolute",
				"background-color": "black",
				width: size.width + "px",
				height: size.height + "px",
				"margin": size.top + "px 0 0 " + size.left + "px",
				"-moz-border-radius": size.corner + "px",
				"-webkit-border-radius":  size.corner + "px", 
				"border-radius":  size.corner + "px"
			};
			
		}
		
	});

	// jQuery adapted Penner animation
	//    created by Jamie Lemon
	$.extend($.easing, {
		
		cubicEaseOut: function(p, n, firstNum, diff) {
			var c = firstNum + diff;
			return c*((p=p/1-1)*p*p + 1) + firstNum;
		}
	});
})(jQuery);
