﻿var speed = 50;
var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 

$(window).load(function(){
    pic = $("#slider").children(".icerik");
    numImgs = pic.length;
    arrLeft = new Array(numImgs);

    for (i=0;i<numImgs;i++){

        totalWidth=0;
        for(n=0;n<i;n++){
	        totalWidth += $(pic[n]).height();
        }

        arrLeft[i] = totalWidth;
        $(pic[i]).css("top",totalWidth);
    }

    myInterval = setInterval("flexiScroll()",speed);
    
    $(pic).show();
});

$(document).ready(function() {

    $("#slider").mouseover(function(){
      clearInterval(myInterval);
    }).mouseout(function(){
      myInterval = setInterval("flexiScroll()",speed);
    });           	            
});

function flexiScroll(){

    for (i=0;i<numImgs;i++){
        arrLeft[i] -= 1;		

        if (arrLeft[i] == -($(pic[i]).height())){
	        totalWidth = 0;
	        for (n=0;n<numImgs;n++){
		        if (n!=i){
			        totalWidth += $(pic[n]).height();
		        }
	        }
	        arrLeft[i] =  totalWidth;
        }
        $(pic[i]).css("top",arrLeft[i]);
    }
}
