$.fn.imageCarousel = function(do3){

	
	var imgs = $(this).find('img');
	var containerWidth = parseFloat($(this).width());
	var containerHeight = parseFloat($(this).height());
	var imgWidth = parseFloat($(this).find('img:first').width());
	var imgHeight = parseFloat($(this).find('img:first').height());
	//var heightRatio = imgWidth/imgHeight;
	
	//var imgWidth = containerWidth*.3;
	//var imgHeight = imgWidth/heightRatio;
	
	var scrollableWidth = containerWidth-(imgWidth*.66);
	var imgCount = $(this).find('img').length;
	var seconds = (scrollableWidth/2) * 0.7;
	var thirds = (scrollableWidth/2);
	
	function evenOdd(input){
		if(input % 2 == 0){
			return 'even';
		}
		else{
			return 'odd';
		}
	}
	
	$(this).css({'overflow':'hidden','z-index':'1000'});
	$(this).find('img').css({'position':'absolute'});
	
	if(evenOdd(imgCount) == 'odd'){
		var middleIndex = ((imgCount + 1)/2)-1;
		var middleImg = $(this).find('img:eq('+middleIndex+')');
	}
	else{
		var middleIndex = (imgCount/2)-1;
		var middleImg = $(this).find('img:eq('+middleIndex+')');
	}
    
	var middleInit = (containerWidth/2);
	var middleTop = (containerHeight/2)-(imgHeight/2);
	var secondsInit = (containerWidth*.3);
	var secondsMod = (imgWidth*.78)/2;
	var secondsTop = (containerHeight/2)-(imgHeight/2)+(imgHeight*.11);
	var thirdsInit = (containerWidth*.5);
	var thirdsMod = (imgWidth*.66)/2;
	var thirdsTop = (containerHeight/2)-(imgHeight/2)+(imgHeight*.17);
	var endsTop = (containerHeight/2)-(imgHeight/2)+(imgHeight*.20);
	//var thirdsInit = ();
	$(middleImg).css({'left':middleInit-(imgWidth/2),'width':imgWidth,'height':imgHeight,'opacity':'100','z-index':'100','top':middleTop}).attr('position','3');
	
	$($(this).find('img:eq('+(middleIndex-1)+')')).css({'left':(middleInit-secondsInit-secondsMod),'top':secondsTop,'width':(imgWidth*.78),'height':(imgHeight*.78),'z-index':'78'}).attr('position','2');
	$($(this).find('img:eq('+(middleIndex-2)+')')).css({'left':(middleInit-thirdsInit-thirdsMod),'top':thirdsTop,'width':(imgWidth*.66),'height':(imgHeight*.66),'z-index':'66'}).attr('position','1');
	$($(this).find('img:lt('+(middleIndex-2)+')')).css({'left':(middleInit-thirdsInit-thirdsMod),'top':endsTop,'width':(imgWidth*.60),'height':(imgHeight*.60),'z-index':'50'});
	
	$($(this).find('img:eq('+(middleIndex+1)+')')).css({'left':(middleInit+secondsInit-secondsMod),'top':secondsTop,'width':(imgWidth*.78),'height':(imgHeight*.78),'z-index':'78'}).attr('position','4');
	$($(this).find('img:eq('+(middleIndex+2)+')')).css({'left':(middleInit+thirdsInit-thirdsMod),'top':thirdsTop,'width':(imgWidth*.66),'height':(imgHeight*.66),'z-index':'66'}).attr('position','5');
	$($(this).find('img:gt('+(middleIndex+2)+')')).css({'left':(middleInit+thirdsInit-thirdsMod),'top':endsTop,'width':(imgWidth*.60),'height':(imgHeight*.60),'z-index':'50'});
	
	if (imgCount > 5) {
		var lessThan = 0;
		for (less = middleIndex - 3; less >= 0; less--) {
			var img = $(this).find('img:eq(' + less + ')');
			$(img).attr('position',lessThan);
			lessThan--;
		}
		var greaterThan = 6;
		for (more = middleIndex + 3; more <= imgCount; more++) {
			var img = $(this).find('img:eq(' + more + ')');
			$(img).attr('position',greaterThan);
			greaterThan++;
		}
	}
	
	$.fn.moveLess=function(){
		var newZ = Number($(this).css('z-index'));
		newZ = newZ -10;
		$(this).animate({
			left:(middleInit-thirdsInit-thirdsMod),
			top:endsTop,
			width:imgWidth*.60,
			height:imgHeight*.60
		},800).css('z-index',newZ);
	}
	
	$.fn.moveFirst=function(){
		$(this).animate({
			left:(middleInit-thirdsInit-thirdsMod),
			top:thirdsTop,
			width:imgWidth*.66,
			height:imgHeight*.66
		},800).css('z-index',66);
	}
	
	$.fn.moveSecond=function(){
		$(this).animate({
			left:(middleInit-secondsInit-secondsMod),
			top:secondsTop,
			width:imgWidth*.78,
			height:imgHeight*.78
		},800).css('z-index',78);
	}
	
	$.fn.moveThird=function(){
		$(this).animate({
			left:(middleInit-(imgWidth/2)),
			top:middleTop,
			width:imgWidth,
			height:imgHeight
		},800).css('z-index',100);
	}
	
	$.fn.moveFourth=function(){
		$(this).animate({
			left:(middleInit+secondsInit-secondsMod),
			top:secondsTop,
			width:imgWidth*.78,
			height:imgHeight*.78
		},800).css('z-index',78);
	}
	
	$.fn.moveFifth=function(){
		$(this).animate({
			left:(middleInit+thirdsInit-thirdsMod),
			top:thirdsTop,
			width:imgWidth*.66,
			height:imgHeight*.66
		},800).css('z-index',66);
	}
	
	$.fn.moveMore=function(){
		var newZ = Number($(this).css('z-index'));
		newZ = newZ -10;
		$(this).animate({
			left:(middleInit+thirdsInit-thirdsMod),
			top:endsTop,
			width:imgWidth*.60,
			height:imgHeight*.60
		},800).css('z-index',newZ);
	}
	
	$.imgUp=function(many){
		$(imgs).each(function(){
			if (many == 1) {
				var posUp = Number($(this).attr('position')) + 1;
				$(this).attr('position', posUp);
				if (posUp == 1) {
					$(this).moveFirst();
				}
				else 
					if (posUp == 2) {
						$(this).moveSecond();
					}
					else 
						if (posUp == 3) {
							$(this).moveThird();
						}
						else 
							if (posUp == 4) {
								$(this).moveFourth();
							}
							else 
								if (posUp == 5) {
									$(this).moveFifth();
								}
								else 
									if (posUp > 5) {
										$(this).moveMore();
									}
									else {
										$(this).moveLess();
									}
			}
			else if (many == 2){
				var posUp = Number($(this).attr('position')) + 2;
				$(this).attr('position', posUp);
				if (posUp == 1) {
					$(this).moveLess();
					$(this).moveFirst();
				}
				else 
					if (posUp == 2) {
						$(this).moveFirst();
						$(this).moveSecond();
					}
					else 
						if (posUp == 3) {
							$(this).moveSecond();
							$(this).moveThird();
						}
						else 
							if (posUp == 4) {
								$(this).moveThird();
								$(this).moveFourth();
							}
							else 
								if (posUp == 5) {
									$(this).moveFourth();
									$(this).moveFifth();
								}
								else 
									if (posUp > 5) {
										$(this).moveMore();
										$(this).moveMore();
									}
									else {
										$(this).moveLess();
										$(this).moveLess();
									}
			}
		});
	}
	
	$.imgDown=function(many){
		$(imgs).each(function(){
			if (many == 1) {
				var posDown = Number($(this).attr('position')) - 1;
				$(this).attr('position', posDown);
				if (posDown == 1) {
					$(this).moveFirst();
				}
				else 
					if (posDown == 2) {
						$(this).moveSecond();
					}
					else 
						if (posDown == 3) {
							$(this).moveThird();
						}
						else 
							if (posDown == 4) {
								$(this).moveFourth();
							}
							else 
								if (posDown == 5) {
									$(this).moveFifth();
								}
								else 
									if (posDown > 5) {
										$(this).moveMore();
									}
									else {
										$(this).moveLess();
									}
			}
			else if (many == 2){
				var posDown = Number($(this).attr('position')) - 2;
				$(this).attr('position', posDown);
				if (posDown == 1) {
					$(this).moveSecond();
					$(this).moveFirst();
				}
				else 
					if (posDown == 2) {
						$(this).moveThird();
						$(this).moveSecond();
					}
					else 
						if (posDown == 3) {
							$(this).moveFourth();
							$(this).moveThird();
						}
						else 
							if (posDown == 4) {
								$(this).moveFifth();
								$(this).moveFourth();
							}
							else 
								if (posDown == 5) {
									$(this).moveMore();
									$(this).moveFifth();
								}
								else 
									if (posDown > 5) {
										$(this).moveMore();
										$(this).moveMore();
									}
									else {
										$(this).moveLess();
										$(this).moveLess();
									}
			}
		});
	}
	
	$(imgs).click(function(){
        if(Number($(this).attr('position')) != 3){
			var clickPos = Number($(this).attr('position'));
			
			maxValue = function(array){
	            mxm = array[0];
	            for (i = 0; i < array.length; i++) {
	                if (array[i] > mxm) {
	                    mxm = array[i];
	                }
	            }
	            return mxm;
	        };
	
	        minValue = function(array){
	            mn = array[0];
	            for (i = 0; i < array.length; i++) {
	            
	                if (array[i] < mn) {
	                    mn = array[i];
	                }
	            }
	            return mn;
	        };
			
			var posits = new Array();
			$(imgs).each(function(){
				var thePosition = Number($(this).attr('position'));
				posits.push(thePosition);
			});
						
			if(clickPos < 3){
				if(minValue(posits) <= 3 && maxValue(posits) >= 3){
					if (clickPos == 2) {
						$.imgUp(1);
					}
					else if (clickPos == 1){
						$.imgUp(2);
					}
				}
			}
			else{
				if(minValue(posits) <= 3 && maxValue(posits) >= 3){
					if (clickPos == 4) {
						$.imgDown(1);
					}
					if (clickPos == 5) {
						$.imgDown(2);
					}
					
				}
			}
			$.timeCount=function(){
				
			}
			counting = setInterval('$.timeCount();',100);
			setTimeout('clearInterval(counting);',800);
			return false;

		}
		else{
			eval(do3);
		}
	});
	
};