// JavaScript Document

var expanded = false;

    $(document).ready(function(){ 
        $("ul.sf-menu").supersubs({ 
            minWidth:    13,   // minimum width of sub-menus in em units 
            maxWidth:    13,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish();  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
    
    //Calls the scrolling function repeatedly
    var init = setInterval("scrollBg()", scrollSpeed);
	$("ul.sf-menu li.n"+nodala).addClass("active");
	
	$("#cenradis > li > ol").css("display","none");
	$("#cenradis > li").click(function() {
		if ( $(this).children("ol").css("display") == "none"){
			$("#cenradis > li > ol").css("display","none");
	        $(this).children("ol").css("display","block");
		} else {
			$(this).children("ol").css("display","none");
		}
    });
	
	
	if($("jauna_atsauksme")){
		var ok = true;
		$("button").click(function(){
			$("#author").removeClass("error");
			$("#atsauksme").removeClass("error");
			$("#email").removeClass("error");

			if($("#author").val() == ""){
				$("#author").addClass("error");
				ok = false;
			}
			if($("#atsauksme").val() == ""){
				$("#atsauksme").addClass("error");
				ok = false;
			}
			if($("#email").val() == "" || ! /@/.test($("#email").val().toString()) || ! /\./.test($("#email").val().toString())){
				$("#email").addClass("error");
				ok = false;
			}
			if(ok){
				$("#jauna_atsauksme").submit();
			}
		});
	}
	
	
	// banners
	setInterval(function(){ tick () }, 8000);
	
	$('#expand').click(function(e) {
		if(!expanded){
        	$(this).css("background-position","bottom right");
			var count = $('#ticker').children('div.banner').length;
			$('#ticker').animate({
				height: count * 75 + "px"
			  }, 1500 );
		} else {
			$(this).css("background-position","top right");
			$('#ticker').animate({
				height: "64px"
			  }, 1500 );
		}
		expanded = !expanded;
    });
	

}); 
    var scrollSpeed = 60;       // Speed in milliseconds
    var step = 1;               // How many pixels to move per step
    var current = 0;            // The current pixel row
    var imageHeight = 581;     // Background image height
    var headerHeight = 74;     // How tall the header is.
    
    //The pixel row where to start a new loop
    var restartPosition = -(imageHeight - headerHeight);
    
    function scrollBg(){
        
        //Go to next pixel row.
        current -= step;
        
        //If at the end of the image, then go to the top.
        if (current == restartPosition){
            current = 0;
        }
        
        //Set the CSS of the header.
        $('.leaf').css("background-position","0 "+current+"px");
        
        
    }
	
	function tick(){
		if(!expanded){
			$('#ticker div:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
		}
	}

