function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getElementsByClassMulti(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp(searchClass);
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function doOnLoad ()
	{
	// ÄLÄ LISÄÄ MITÄÄN TÄMÄN RIVIN JÄLKEEN
	}

function createCookie(name,value,days)
	{
	if (days)
		{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}

function readCookie(name)
	{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
		{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			{ 
			return c.substring(nameEQ.length,c.length);
			}
		}
	return null;
	}
	
function eraseCookie(name)
	{
	createCookie(name,"",-1);

	}

function showJcmmPopup(element)
	{
	hideJcmmPopup();
	showJcmmPopupMask();
	Element.show(element);
	}
function hideJcmmPopup()
	{
	
	var popupElements = getElementsByClassMulti('JcmmPopup',null,'div');
	var elLen = popupElements .length;
	
	for (i = 0; i < elLen; i++)
		{
		var element = popupElements [i].id;
		Element.hide(element);
		}
	hideJcmmPopupMask();
	}
	
function showJcmmPopupMask()
	{
	Element.show('PopupMask');
	}
function hideJcmmPopupMask()
	{
	Element.hide('PopupMask');
	}


createCookie('runLoop','1',300);
createCookie('runLoopNews','1',300);
JQ(window).load(function() { //start after HTML, images have loaded
 	JQ('.footer_banners .row').hide();
    var bannerRotator =
    {
        init: function()
        {
            //initial fade-in time (in milliseconds)
            var initialFadeIn = 2000;
 
            //interval between items (in milliseconds)
            var itemInterval = 5000;
 
            //cross-fade time (in milliseconds)
            var fadeTime = 1000;
 
            //count number of items
            var numberOfItems = JQ('.footer_banners .row').length;
            //set current item
            var currentItem = 0;
 
            //show first item
            JQ('.footer_banners .row').eq(currentItem).show();
 
            //loop through the items
            var infiniteLoop = setInterval(function(){
				if(readCookie('runLoop') == '1')
					{
					JQ('.footer_banners .row').eq(currentItem).hide("drop", { direction: "down" }, fadeTime,function(){
					
						if(currentItem == numberOfItems -1){
							currentItem = 0;
							}
						else
							{
							currentItem++;
							}
						JQ('.footer_banners .row').eq(currentItem).show("drop", { direction: "down" }, fadeTime);
						});
					}
            }, itemInterval);
        }
    };
 	
	var newsRotator =
    {
        init: function()
        {
            //initial fade-in time (in milliseconds)
            var initialFadeIn = 2000;
 
            //interval between items (in milliseconds)
            var itemInterval = 4500;
 
            //cross-fade time (in milliseconds)
            var fadeTime = 1000;
 
            //count number of items
            var numberOfItems = JQ('#frontpage_text li').length;
            //set current item
            var currentItem = 0;
 
            //show first item
            JQ('.footer_banners .row').eq(currentItem).show();
 
            //loop through the items
            var infiniteLoop = setInterval(function(){
				if(readCookie('runLoopNews') == '1')
					{
					JQ('#frontpage_text li').eq(currentItem).hide("slide", { direction: "up" }, fadeTime,function(){
					
					if(currentItem == numberOfItems -1){
						currentItem = 0;
						}
					else
						{
						currentItem++;
						}
					JQ('#frontpage_text li').eq(currentItem).show("slide", { direction: "down" }, fadeTime);
					});
				}
 
            }, itemInterval);
        }
    };
	
    bannerRotator.init();
    newsRotator.init();
	JQ('.footer_banners .row').hover(function(){createCookie('runLoop','0',300);},function(){createCookie('runLoop','1',300);});
	JQ('#frontpage_text li').hover(function(){createCookie('runLoopNews','0',300);},function(){createCookie('runLoopNews','1',300);});
	JQ("#frontpage_text table table").addClass('nextmatch-table');
	JQ("#frontpage_text li a").css('color','#FFFFFF');
	
});
