﻿$(function(){
 speed = 40;
 mpause = 1; //set to 0 if it should't pause on mouseover
 // no need to edit below //
 btop = 20;
 mheight = $("marquee").attr("height");
 mwidth = $("marquee").width();
 mwidth = mwidth - 10;
 $(".alternate").height(mheight).css("position", "relative").css("overflow", "hidden").appendTo("#test");
 $("marquee").hide().children().each(function(){
 $(this).addClass("article").css("width", mwidth).appendTo("div.alternate");
 $(this).css("top", btop).css("position", "absolute");
 btop = btop + $(this).height();
 });
 ccount = 0;
 populate();
 fall = $("div.article").length - 1;
 $("div.alternate").show();
 function kjoer(){
 $("div.article").each(function(){
 var atop = parseInt($(this).css("top"));
 $(this).css("top", atop - 1 + "px");
 });
 var ttest = $("div.article:eq(0)").height();
 var atop = parseInt($("div.article:eq(0)").css("top"));
 var ttop = 0 - ttest;
 if (ttop == atop)
 {tick();}
 else {}
 };
 function tick() {
 var eq0 = btop - $("div.article:eq(0)").height();
 $("div.article:eq(0)").clone().insertAfter("div.article:eq(" + fall + ")");
 $("div.article:eq(0)").remove();
 $("div.article:eq(" + fall + ")").css("position", "absolute").css("top", eq0);
 };
 var scrollit = setInterval(kjoer,speed);
 $("<div></div>").addClass("toggle").height(0).attr("id", "0").prependTo("body");
 $("<a></a>").appendTo(".toggle");
 function mout(){
 clearInterval(scrollit);
 $("div.alternate").css("overflow", "auto");
 $("div.article:eq(0)").css("top", "0px");
 ttemp = 0;
 $("div.article").each(function(){
 var atop = parseInt($(this).css("top"));
 $(this).css("top", ttemp);
 ttemp = ttemp + $(this).height();
 });
 };
 function mback(){
 $("div.alternate").css("overflow", "hidden");
 scrollit = setInterval(kjoer,speed); 
 };
 function select(){
 selec = $(".toggle").attr("id")
 if( selec == 0){$(".toggle").attr("id", "1");mout();}
 else {$(".toggle").attr("id", "0"); mback();};
 };
 $(".toggle").click(select);
 if (mpause == 1) {
 $("div.alternate").hover(function(){clearInterval(scrollit);},
 function(){
 if ( $(".toggle").attr("id") == 0) {
 scrollit = setInterval(kjoer,speed);
 };});};
 });
