﻿
$(function(){
//user variables
var speed = 40;
var delay = 2000;
var scrollbar = 1;
var scrollimages = 1;
var runs = "unlimited"; //specify number of runs or "unlimited"
var expand_effects = 0;
var pause_between_cycles = 1;
//until here
// init()
var mheight = parseInt($("marquee").attr("height"));
var kjoer;
var go;
var runcount=0;
$("<div></div>").attr("id", "debug").css({"background":"#888", "position":"absolute", "top":"5px", "left":"5px", "opacity":".3", "filter":"alpha(opacity=30)"}).height(100).width(100).appendTo("#mw_newsfeed").hide();
$("<div></div>").addClass("alternate").height(mheight).css("position", "relative").css("overflow", "hidden").appendTo("#mw_newsfeed");
$("<div></div>").addClass("scroller").css({"position": "absolute", "top": "0px"}).appendTo(".alternate");
$("<div></div>").addClass("scrollicon").css({"position": "absolute", "top": "0px", "right": "2px", "background": "transparent", "opacity":".5", "filter":"alpha(opacity=50)"}).width(12).appendTo(".alternate");
$(".article").width($(".article").width() - 16);
$("marquee").hide().children().appendTo("div.scroller").end().remove();
var scroller_height = $(".scroller").clone().appendTo(".alternate").height();
var si_height = Math.round(mheight*mheight/scroller_height)>9?Math.round(mheight*mheight/scroller_height):10;
var scrollicon = $(".scrollicon:eq(0)");
scrollicon.height(si_height);
$(".scroller:eq(1)").css("top", scroller_height);
var elems_to_scroll = [ $(".scroller:eq(0)"), $(".scroller:eq(1)") ]
// /init()
// kjoer
var dim = new Array(0,scroller_height);
var scroll = function(){
//$("#debug").html(dim.join(":")+":"+scrollicon.css("top"));
if (dim[1] <= 0) {
runcount += 1;
if ( (pause_between_cycles != 0) && ( ( runs==('unlimited'||0) ) || (runcount < runs) ) ){
clearInterval(kjoer);
clearTimeout(go);
go = setTimeout(wait,delay);
};
dim = [0, scroller_height];
run_limiter();
};
$.each(elems_to_scroll, function(i){
this.css("top",dim[i]);
dim[i] -= 1;
});
scrollicon.css("top", Math.round( (mheight - si_height) * (0-dim[0]) / scroller_height) );
};
var manual_scrolling=0;
scrollicon.mousedown(function(u){
manual_scrolling=1;
clearInterval(kjoer);
var start = [parseInt(scrollicon.css("top")), u.pageY];
u.preventDefault();
$("body").mousemove(function(e){
var relative_move =  parseInt(e.pageY) - start[1];
//$("#debug").html(start[1]+":"+e.pageY+":"+relative_move);
var scrollicon_move = (start[0]+relative_move>0?start[0]+relative_move:0)
dim[0] = Math.round( -1 * scroller_height / (mheight-si_height) * (scrollicon_move<=(mheight-si_height)?scrollicon_move:mheight-si_height) ) - 1;
dim[1] = dim[0] + scroller_height;
scroll();
});
//$("#debug").css("background", "#c88");
});
$("body").add(window).mouseup(function(){
manual_scrolling=0;
$("body").unbind("mousemove");
//$("#debug").css("background", "#888");
});
$("#mw_newsfeed").mouseout(function(){
$("body").click();
});
$(".alternate").hover(function(){manual_scrolling=1;$(".scrollicon").fadeTo(200, .8);}, function(){manual_scrolling=0;$(".scrollicon").fadeTo(200, .5);});
function wait(){
clearInterval(kjoer);
kjoer = setInterval(scroll, speed);
}
var go = setTimeout(wait,delay)
var scroller_event = function(){
$(".alternate").hover(function(){clearTimeout(go); clearInterval(kjoer); kjoer = 0;}
,function(){
if (kjoer<1){
clearInterval(kjoer);
kjoer = setInterval(scroll, speed);
}
});
};
function run_limiter(){
if ((runs != ("unlimited"||0)) && (runcount >=  runs)) {
clearInterval(kjoer);
scroll = function(){
return false;
};
$("body").unbind("mousemove");
$(".alternate").unbind("mousein").unbind("mouseout");
if (expand_effects !=0){
$(".alternate").add(".scrollbar").animate({height:scroller_height},4000, function(){ });
$(".scrollicon").add(".scrollbar").fadeOut("5000", function(){ $(this).remove(); });
}
else {
$(".alternate").add(".scrollbar").height(scroller_height);
$(".scrollicon").add(".scrollbar").remove();
}
$(".scroller:eq(1)").remove();
$(".scroller").css("top", "0px");
}
else{ return true; };
};
scroller_event();
$(".article").hover(function(){$(this).css("background", "transparent"); }, function(){$(this).css("background", "transparent");});
});
 
   
