window.onload = function() {	

if(document.getElementById("osavaltiopopup")) {
	var osavaltiolink = document.getElementById("nayta_osavaltiopopup");
	var osavaltiocont = document.getElementById("osavaltiopopup");
	var osavaltioclose = document.getElementById("osavaltioclose");

	osavaltiolink.onclick = function() {
		osavaltiocont.style.display = "block";
	}

	osavaltioclose.onclick = function() {
		osavaltiocont.style.display = "none";
		return false;
	}
}


	
/*if (document.getElementById("closeuutispopup")) {
	var uutisetlink = document.getElementById("openuutisarkisto");
	var uutisetcont = document.getElementById("uutispopup");		
	var uutisetclose = document.getElementById("closeuutispopup");
	
	uutisetlink.onclick = function(){
		uutisetcont.style.display = "block";
	}

	uutisetclose.onclick = function(){
		uutisetcont.style.display = "none";
		return false;
	}
}*/
		
}

var highlights = [],
          index = 0,
          width = 670,
          delay = 9000,
		  suunta = 1,
		  interval;

$(document).ready(function(){ 

       $('a[rel*=facebox]').facebox({
        	loadingImage : '/files/mynthon/gfx/blank.gif',
	        closeImage   : '/files/mynthon/gfx/close-btn.gif',
			opacity      : 0.8, 
		    overlay      : true,
			width: '477px'
      	})
        

/* Get highlight images and links */
          highlights = $('#nostokaruselli .container').children('a,img,div,object');

          /* Animate, if there is more than one highlight */
          if (highlights.length > 1) {
			  $('#nostokaruselli .prev').show();
			  $('#nostokaruselli .next').show();
			  
			  $('#nostokaruselli .prev').click(function() {
				  clearTimeout(interval);
				  suunta = -1;
				  loopHighlights();
			  });
			  
			  $('#nostokaruselli .next').click(function() {
				  clearTimeout(interval);
				  suunta = 1;
				  loopHighlights();
			  });

              /* Clone first highlight as the last highlight */
              $('#nostokaruselli .container').append($(highlights[0]).clone());

              /* Get updated highlights and remove all other elements */
              highlights = $('#nostokaruselli .container').children('a,img,div,object');
              $('#nostokaruselli .container').html(highlights);

              /* Calculate container width */
              $('#nostokaruselli .container').css('width', highlights.length * width + 'px');

              /* Start animation */
              interval = setTimeout(loopHighlights, delay);
          }

 
});

function loopHighlights ()
      {
		  //suunta = suunta || 1;
		  index = index + suunta;
          /* Loops index between 0 and the amount of highlights */
		  if( index >= ( highlights.length ) ) {
			  index = 1;
			  $('#nostokaruselli .container').css({ left: '0px' });  
		  } else if ( index < 0 ) {
			 index = highlights.length -2;
			  $('#nostokaruselli .container').css({ left: '-' + ((highlights.length -1) * width) + 'px' }); 
		  }
          

          /* Do the slide animation */
          $('#nostokaruselli .container').animate({ left: '-' + (index * width) + 'px' } , 500);
		  suunta = 1;
		  interval = setTimeout(loopHighlights, delay);
      }


