jQuery.fn.extend({

	clanceyCarousel :
			
			function(){
			
				var thisID = $(this).attr("id");

				var numOfItems = $("#"+thisID+" #items ul li").size();
				var numOfBlocks = Math.ceil( numOfItems / 5 );
				var currentBlockGroup = 1;

				
				// Cycle Thru and add Classes To Items
				
				for( i = 0; i <= ( numOfItems -1 ) ; i++ ){
					
					var blockItemNumber = parseInt( i / 5 );
					$("#"+thisID+" #items ul li:eq("+i+")").addClass("blockItem-"+(blockItemNumber+1)+"");
					$("#"+thisID+" #items ul li:eq("+i+")").addClass("item-"+(i+1)+"");
				
				}


				
				// Get Tallest Image
				var tallestItemImageHeight = 0;
				
				for( i = 0; i <= ( numOfItems -1 ) ; i++ ){
					var currentItemImageHeight = $("#"+thisID+" #items ul li:eq("+i+") a img").height();
					if ( currentItemImageHeight >= tallestItemImageHeight ) {
						tallestItemImageHeight = currentItemImageHeight
					}
				}

				// Set Padding to Items

				for( i = 0; i <= ( numOfItems -1 ) ; i++ ){

					 var currentItemImageHeight = $("#"+thisID+" #items ul li:eq("+i+") a img").height();
					 var currentTopPadding = tallestItemImageHeight - currentItemImageHeight; 
					 //alert(currentTopPadding)
					 $("#"+thisID+" #items ul li:eq("+i+") a").css({ "padding-top" : ""+(currentTopPadding + 13)+"px" });
				}





				// Get Tallest Item and Set Slider Mod Height
				var tallestItem = 0;
				
				for( i = 0; i <= ( numOfItems -1 ) ; i++ ){
					
					var currentItemHeight = $("#"+thisID+" #items ul li:eq("+i+")").height();
					
					if ( currentItemHeight >= tallestItem ) {
						tallestItem = currentItemHeight
					}

				}			
				
				




				$("#"+thisID+" #items ul li:gt(4)").css({ "display" : "none" });


				// Generate Section Indicator

				if ( numOfItems > 5 ) {
					
					$("#"+thisID+" #items").after('<ul class="section_indicator"><li class="indicator i01"><a class="on">&bull;</a></li></ul>');
					
					var numOfIndicators = parseInt( numOfItems / 5 );
					
					for( i = 1; i <= numOfIndicators && i < numOfBlocks; i++ ){

						$("#"+thisID+" div.inner_wrap ul.section_indicator li.i0"+i+"").after('<li class="indicator i0'+( i + 1 )+'"><a href="#">&bull;</a></li>');

					}
					
				
				
				}

				// Set Nav Arrows
				
				if ( numOfItems > 5 ) {
					
						$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").removeClass("disabled");
				}



				$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").click(
					function(){

						
						
						
						if ( currentBlockGroup < numOfBlocks ) {
				
							currentBlockGroup = currentBlockGroup + 1;

							if( numOfBlocks == 2 && currentBlockGroup == 2 ){
								
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").addClass("disabled");
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.left a").removeClass("disabled");
								
							} else if( currentBlockGroup == 2 ){
								
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.left a").removeClass("disabled");	
							
							} else if ( currentBlockGroup >=  numOfBlocks  ) {
							
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").addClass("disabled");
							
							}


							$("#"+thisID+" div.inner_wrap #items ul li").css({ "float" : "right" })

							$("#"+thisID+" #items ul li.blockItem-"+(currentBlockGroup-1)+"").hide( "drop", { direction : "left" } , 480 ,
								function(){
									$("#"+thisID+" #items ul li.blockItem-"+currentBlockGroup+"").show().css({ "display" : "block" });
									$("#"+thisID+" ul.section_indicator li.i0"+(currentBlockGroup-1)+" a").removeClass("on");
									$("#"+thisID+" ul.section_indicator li.i0"+currentBlockGroup+" a").addClass("on");
								}
							);

						} else {
							
							currentBlockGroup = numOfBlocks;
							return false
				
						}




					
					}
				);





				$("#"+thisID+" div.inner_wrap span.scroll_buttons span.left a").click(
					function(){


						if( currentBlockGroup > 1 ){

							currentBlockGroup = currentBlockGroup - 1;		
						
							$("#"+thisID+" div.inner_wrap #items ul li").css({ "float" : "right" })

							$("#"+thisID+" #items ul li.blockItem-"+(currentBlockGroup+1)+"").hide( "drop", { direction : "right" } , 480 ,
								function(){
									$("#"+thisID+" #items ul li.blockItem-"+currentBlockGroup+"").show().css({ "display" : "block" });
									$("#"+thisID+" ul.section_indicator li.i0"+(currentBlockGroup+1)+" a").removeClass("on");
									$("#"+thisID+" ul.section_indicator li.i0"+currentBlockGroup+" a").addClass("on");
								}
							);

							
							
							if( numOfBlocks == 2 && currentBlockGroup == 1 ){
								
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.left a").addClass("disabled");
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").removeClass("disabled");
							
							} else if( currentBlockGroup == 1 ){
								
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.left a").addClass("disabled");
								currentBlockGroup = 1;
								
							}	else if ( currentBlockGroup > 1 ) {
								
								$("#"+thisID+" div.inner_wrap span.scroll_buttons span.right a").removeClass("disabled");	
							
							}


						}	else {
						
							currentBlockGroup = 1;
							return false;
						
						}	


			
					}
				);







				$("#"+thisID+"").css({ "height" : tallestItem });
				//$("#"+thisID+"").css({ "display" : "block" })












			
			}

});
