var rotateElements =
function _obj(container, delay, element, autoplay, fadespeed) {

    if (!delay) delay = 5000;
    if (!element) element = 'ul li';
    if (!fadespeed) fadespeed = 'fast';
    if (autoplay) autoplay = true;
    intCurrent = 0;
    intTotal = 0;
    strClass = container.substring(1, container.length);
    rotator = '';

    this.init = function() {

        $(container + ' .rotator ' + element).hide();
        $(container + ' .rotator ' + element).each(
			function(intIndex) {
			    $(this).addClass('ElEm' + intIndex);
			    if ($(this).hasClass('on'))
			        intCurrent = intIndex;
			    $(this).hover(
					function() {
					    if (rotator) {
					        pause();
					    } else {
					        rotator = 'paused';
					    }
					},
					function() {
					    if (rotator) {
					        pause();
					    } else {
					        play();
					    }
					});
			    intTotal = intIndex;
			});
        caption();
        $(container + ' .rotator ' + element + '.ElEm' + intCurrent).fadeIn(fadespeed);
        intCurrent = (intCurrent + 1);
        if (autoplay && intTotal > 1) {
            play();
        } else {
            pause();
        }

        $(container + ' a.rotatorpause').click(function() {
            if (rotator)
                pause();
            return false;
        });

        $(container + ' a.rotatorplay').click(function() {
            if (!rotator)
                play();
            return false;
        });

        $(container + ' a.rotatortoggle').click(function() {
            if (!rotator) {
                play();
                $(this).parent().addClass('on');
            } else {
                pause();
                $(this).parent().removeClass('on');
            }
            return false;
        });

        $(container + ' a.rotatornext').click(function() {
            if (rotator) {
                pause();
            } else {
                rotator = 'paused';
            }
            rotate();
            if (rotator) {
                pause();
            } else {
                play();
            }
            return false;
        });

        $(container + ' a.rotatorprevious').click(function() {
            if (rotator) {
                pause();
            } else {
                rotator = 'paused';
            }
            previous();
            if (rotator) {
                pause();
            } else {
                play();
            }
            return false;
        });
    }

    this.caption = function() {
        $(container + ' a.rotatorcaption').each(
		function(intIndex) {
		    $(this).addClass('CaP' + intIndex);
		    if (intCurrent == intIndex)
		        $(this).parent().addClass('on');
		    $(this).hover(function() {
		        if (rotator) {
		            pause();
		        } else {
		            rotator = 'paused';
		        }
		        intCurrent = intIndex;
		        $(container + ' .rotator ' + element).hide();
		        $(container + ' .rotator ' + element + '.ElEm' + intCurrent).fadeIn('fast');
		        $(container + ' a.rotatorcaption').parent().removeClass('on');
		        $(this).parent().addClass('on');
		    },
			  function() {
			      intCurrent = (intCurrent + 1);
			      if (rotator) {
			          pause();
			      } else {
			          play();
			      }
			  });
		});
    }

    this.rotate = function() {
    if (!$(container + ' .rotator ' + element + '.ElEm' + intCurrent).attr('class'))
            intCurrent = 0;
        $(container + ' a.rotatorcaption').parent().removeClass('on');
        $(container + ' .rotator ' + element).hide();
        $(container + ' a.CaP' + intCurrent).parent().addClass('on');
        $(container + ' .rotator ' + element + '.ElEm' + intCurrent).fadeIn(fadespeed);
        intCurrent = (intCurrent + 1);
    }

    this.previous = function() {
        intCurrent = (intCurrent - 2);
        if (intCurrent == -1)
            intCurrent = intTotal;
        $(container + ' a.rotatorcaption').parent().removeClass('on');
        $(container + ' a.CaP' + intCurrent).parent().addClass('on');
        $(container + ' .rotator ' + element).hide();
        $(container + ' .rotator ' + element + '.ElEm' + intCurrent).fadeIn(fadespeed);
        intCurrent = (intCurrent + 1);
    }

    this.pause = function() {
        clearInterval(rotator);
        $(container + ' a.rotatorplay').parent().removeClass('on');
        $(container + ' a.rotatortoggle').parent().removeClass('on');
        $(container + ' a.rotatorpause').parent().addClass('on');
        rotator = null;
    }

    this.play = function() {
        rotator = setInterval('this.rotate()', delay);
        $(container + ' a.rotatorpause').parent().removeClass('on');
        $(container + ' a.rotatorplay').parent().addClass('on');
        $(container + ' a.rotatortoggle').parent().addClass('on');
        return false;
    }


    this.init();

}