(function($){

  $.fn.highLight = function(options) {
	var highOpt = {
      'type' : 'classic',
	  'activeclass' : 'active',
	  'rightclass' : 'nextlink',
	  'leftclass' : 'prevlink',
	  'method' : 'click',
	  'time' : 500,
	  'auto' : true,
	  'autotime' : 12000
    };
	
	if ( options ) { 
        $.extend( highOpt, options );
    }	
		
    slider = this;
    slidertype = highOpt.type;
	activeCL = highOpt.activeclass;
	rightelement = highOpt.rightclass;
	leftelement = highOpt.leftclass;
	method = highOpt.method;
	time = highOpt.time;
	auto = highOpt.auto;
	autotime = highOpt.autotime;
	
	return this.each(function() {		
	
		/* Values */
		helementClass = $(this).attr('class');
		hhelementsList = $(this).children('ul');
		hhelementsHtml = $(this).html();
		helements = $(this).children('ul').children('li');
		helementWidth = $(this).children('ul').children('li').width();
		helementsCount = helements.size();
		hallWidth = parseInt(helementsCount * helementWidth);
		hhelementsList.width(hallWidth);
			
		helements.first().addClass(activeCL);
		
		$(document).bind("hNext", function(e, myName, myValue) {
			highLightChange(activeCL, helementWidth, helementsCount, helementClass, "right");
		});
		
		$('.'+ rightelement).click(function() { $(document).trigger('hNext'); });
		$('.'+ leftelement).click(function() { highLightChange(activeCL, helementWidth, helementsCount, helementClass, "left"); });
		
		if (auto == true) { setInterval("$(document).trigger('hNext')", autotime); }
	});

  };
  
  function highLightChange(index, width, size, hcontClass, type) {
		hList = $('.'+ hcontClass).children('ul');
		
    // if (hList.is(":animated") == false) {
        
		if (index == size) {
			index = 0;
		} 
		
		if (index < 0) {
			index = size -1;
		}
		
		if (type == "list") {
			marginLeft = parseInt(index * width);
			hList.animate({ "right": "" + marginLeft + ""}, time);
			hList.children('li').removeClass(activeCL);
			hList.children('li').eq(index).addClass(activeCL);
		} else {
			hList.find('li').each(function() {
					if ( $(this).hasClass(index) ) { indexVal1 = $(this).index(); }
			});
				
			if (type == "right") {
				indexVal = indexVal1+1;
			} else {
				indexVal = indexVal1-1;
			}
			type = "list";		
			highLightChange(indexVal, width, size, hcontClass, type);
		}
  }
  
})(jQuery);
