	var ImagesToLoad = 0;
	var LoadedImages = 0;

$.fn.hyhrollover = function(a_options)
{
    function cssCut(val)
    {
	if (val.indexOf('px') == -1)
		return 0;
	return parseInt(val.substr(0, val.indexOf('px')));
    }

    if ($(this).length == 0)
    {
	return;
    }
	
    var Object = $(this);
    var Items = $('> *', Object);
    var ItemsCnt = Items.length;
	var exit = false;
	Object.find('img').each(function(){
		var img = $(this);
		if (!img[0].complete) {
			exit = true;/*
			++ImagesToLoad;
			img.load(function(){
			alert('loaded');
				++LoadedImages;
				if (LoadedImages == ImagesToLoad) {
					Object.hyhrollover(a_options);
				}
			})*/
		}
	})
	if (exit) {
		window.hyhRollover = Object;
		window.hyhRolloverOptions = a_options;
		setTimeout('window.hyhRollover.hyhrollover(window.hyhRolloverOptions)', 100);
		return;
	}



	var options = { 
		itemHeight:'auto',
		itemWidth: 'auto',
		speed: 75,
		elemNext: null,
		elemPrev: null
	};

	if (typeof(a_options) != 'undefined') {
		for (var key in a_options) {
			options[key] = a_options[key];
		}
	}
	var GalleryWidth = Object.width();
	if (Items.length == 0) 
		return;
    var ItemsWidth = 0;
	if (options.itemWidth == 'auto') {
	    for(var i=0; i<ItemsCnt; ++i) {
		ItemsWidth += Items.eq(i).width() +
			cssCut(Items.eq(i).css('marginLeft')) + cssCut(Items.eq(i).css('marginRight')) +
			cssCut(Items.eq(i).css('paddingLeft')) + cssCut(Items.eq(i).css('paddingRight')) +
			cssCut(Items.eq(i).css('borderLeftWidth')) + cssCut(Items.eq(i).css('borderRightWidth'));
	    }
	} else {
	    ItemsWidth = ItemsCnt*options.itemWidth;
	}
    var newGalleryWidth = GalleryWidth*2+20;
	var i=0;
    while (newGalleryWidth > GalleryWidth) {
		var newItem = Items.eq(i%ItemsCnt).clone();
		newItem.unbind('click');
		newItem.data('myObject',Items.eq(i%ItemsCnt));
		newItem.hover(function(){$(this).data('myObject').find('a').trigger('mouseenter');}, function(){$(this).data('myObject').find('a').trigger('mouseleave');});
newItem.addClass('mirror').click(function(){$(this).data('myObject').find('a').click();return false;});
		Object.append(newItem);
		++i;
		newGalleryWidth-=Items.eq(i%ItemsCnt).width() +
			cssCut(newItem.css('marginLeft')) + cssCut(newItem.css('marginRight')) +
			cssCut(newItem.css('paddingLeft')) + cssCut(newItem.css('paddingRight')) +
			cssCut(newItem.css('borderLeftWidth')) + cssCut(newItem.css('borderRightWidth'));
	}
	Items = $('> *', Object);
	Object.css({'overflow':'hidden', position:'relative'});
    var wrapper = $(document.createElement('div')).css({width: (ItemsWidth*3)+'px', position:'relative'});
	if (options.itemHeight != 'auto') {
		wrapper.css('height', options.itemHeight+'px');
	}
	Items.wrapAll(wrapper);
	wrapper = Items.parents('div').eq(0);
	
	var Speed = options.speed;
	var API = {};
	API.speed = options.speed;
	API.defaultSpeed = options.speed;
	API.wrapper = wrapper;
	API.galleryWidth = GalleryWidth;
	API.imageWidth = options.itemWidth;
	API.itemsCnt = ItemsCnt;
    API.itemsWidth = ItemsWidth;
	API.object = Object;
	API.move = function() {
		var api = this;
/*		if (api.speed==0) {
			setTimeout("window.rollOverApi.move()", 1000);
			return;			
		}*/

		var pos = api.object.scrollLeft();

		if (pos >= (api.itemsWidth)) {
			pos -= (api.itemsWidth);
			api.object.stop().scrollLeft(pos);
		}

		pos += api.speed;
		api.object.stop().animate({scrollLeft:/*pos*/'+='+api.speed+'px'}, 1000, 'linear');
		setTimeout("window.rollOverApi.move()", 1000);			
	}
	window.rollOverApi = API;
	API.move();
	Object.hover(function(){API.object.stop();API.speed=0;}, function(){API.speed=API.defaultSpeed;API.move()});

}

