/* jQuery Spotlight Accordian Plugin */
/* copyright: SiteOrganic 2010 */
(function($) {
	$.fn.spotlight = function(options) {

	var defaults = {
		name: 		'spotlight',	// name for feature wrapper & for timer - NO SPACES
		height: 	'',
		width: 		'',
		slidespeed: ''
	};
	
	var options = $.extend(defaults, options); 
	
	return this.each(function(){
	
		objSpot = $(this);
		objSpot.addClass(options.name);
		objSpot.addClass('spotlight');
		objSpot.find('div').addClass('spotlight-list');
	
		$iCount = $('.spotlight-list a:last').prevAll().length;
		$zIndex = $('.spotlight-list a:last').prevAll().length;
		$cCount = 0;
		$mAdjust = 0;
		
		$('.spotlight-list a:first').addClass('spot count');
		$('.spotlight-list a:last').addClass('last');
		$('.spotlight-list a').addClass('animate');
		
		while( $cCount <= $iCount) {
			var p = $(".count h2");
			$('.count').removeClass('count').css({
					'top' : 45*$cCount,
					'z-index' : $zIndex +1
			}).next().addClass('count');
			$cCount++;
			$zIndex--;
		}
		
		$('.spotlight-list a').removeClass('count');
		
		$('.spotlight-list a.animate h2').mouseover(function () {
			
			$('.spotlight-list a.animate').removeClass('animate');
			
			currentItem = $('.spot').prevAll().length;
			countItem = 0;
			
			$('.spotlight-list .spot').removeClass('spot');
			$(this).parent().addClass('spot');
			
			newItem = $('.spot').prevAll().length;	
			
			if(newItem > currentItem){
				$('.spotlight-list .spot').addClass('open');
			} else {
				$('.spotlight-list .spot').addClass('closed');
			}
			
			//IF COLLAPSED - EXPAND LOWER ITEMS - EXPAND SELF - RETURN
			if ($('.spotlight-list a.spot').is('.closed')) {
				$('.spotlight-list a').each(function(){
					if(countItem < newItem) {
				 		// DO NOTHING IF COUNT IS LESS THAN NEW
					} else {
						$('.spotlight-list a').eq(countItem).animate({
							height: '225px'
						},500);
					}
						
					countItem++;
				});
			}	
				
			//IF OPEN - LEAVE ABOVE COLLAPESED ALONE - COLLAPSE OPEN ABOVE - DO NOTHIN UNDER - RETURN
			if ($('.spotlight-list a.spot').is('.open')) {
				$('.spotlight-list a').each(function(){
					if(countItem < newItem) {
						$('.spotlight-list a').eq(countItem).animate({
							height: '46px'
						},500);
					} else {
					  // DO NOTHING
					}
						
					countItem++;
				});
			}	
				
			$('.spotlight-list .spot.closed').removeClass('closed');
			$('.spotlight-list .spot.open').removeClass('open');
			
			//$('.spotlight-list a').addClass('animate');
			
		});
	});

	};//END
})(jQuery);
