function removePx(number){
    number = number.replace(/px/, '');
    return number*1;
    }
function sliderInt(){
	var controller =	$('controller');
	controller.set('opacity','0');
	controller.setStyle('display','block');
	controller.tween('opacity', '1');
    var sliders = $$('#slidepanel li');
    var count = 0;
    var nextslide = 1;
    var slider = $('slidepanel');
    var first = slider.getFirst('li').clone();
    var last = slider.getLast('li').clone();
    first.inject(slider, 'bottom');
    last.inject(slider, 'top');
    var width = first.getStyle('width');
    var next = $('next');
    var prev = $('prev');
    width = removePx(width);
    slider.setStyle('margin-left', (width*(-(nextslide)))+'px' );
    slider.set('morph', {duration: 600,transition: Fx.Transitions.Quad.easeOut });
    sliders.each(function(el) { 
    count = count+1
    });

    
    function animate(moveto){
    slider.morph({
        'margin-left' :moveto + 'px'
     });
    }

    function moveright(value,condition){
        if (value == 1) {
        slider.setStyle('margin-left', (width*(-(value)))+'px' );
        value = 2;
        var moveto = (value*width)*-1;
        animate(moveto);
        nextslide++;
        } else  {
        var moveto = (value*width)*-1;
        animate(moveto);
    }
    }

    function moveleft(value){
     if (value == count) {
        slider.setStyle('margin-left', (width*(-(value)))+'px' );
        value = count-1;
        var moveto = (value*width)*-1;
        animate(moveto);
        nextslide=nextslide-1;
    } else  {
        var moveto = (value*width)*-1;
    	animate(moveto);
        }
    }

    var nextauto = function () {
                if (nextslide == (count+1)) {
                nextslide=1;
                }else{
                nextslide++;
                }
                moveright(nextslide);
                }

    window.periodical = nextauto.periodical(9000);
    
    function nextpane(){
			if (nextslide == (count+1)) {
                nextslide=1;
                }else{
                nextslide++;
                }
                $clear(window.periodical);
                moveright(nextslide);
       }
  	function prevpane(){
  	if (nextslide == 0) {
                nextslide = count;
                } else {
                nextslide = nextslide-1;
                }
                $clear(window.periodical); 
                moveleft(nextslide);
  	}

    next.addEvents({
                'click': function(e) {
                e.stop();
                nextpane();
                }
                });
    prev.addEvents({
                'click': function(e) {
                e.stop();
                prevpane();
                }
                });
    document.addEvent('keyup', function(event) {
			if (event.key == 'right'){
			nextpane();
			}
			if (event.key == 'left'){
			prevpane();
			}
		})
}

