function radiohelmi() {
	var radiohelmi = window.open('http://www.radionova.fi/nettiradio/helmi/','_blank','left=50,top=50,width=930,height=710,toolbar=0,resizable=0');
//	var radiohelmi = window.open('http://www.radionova.fi/grey/inc/radioPlayer.php?radio=7','_blank','left=200,top=200,width=700,height=340,toolbar=0,resizable=0');
	radiohelmi.focus();
}

function swapheader(dir) {
	if (jQuery.browser.msie) {
		// Version with instant replacement. In use because of IE bug in fading.
		if (!changing && dir!='') {
			changing = true;
			if (dir == 'next') {
				newHeaderIndex = (currentHeaderIndex < headerContents.length - 1) ? currentHeaderIndex + 1 : 0;
			}
			else {
				newHeaderIndex = (currentHeaderIndex > 0) ? currentHeaderIndex - 1 : (headerContents.length - 1);
			}
			jQuery("#header_"+(currentHeaderIndex+1)).hide();
			jQuery("#header-navigation").removeClass();
			jQuery("#header-navigation").addClass("coloring_" + (newHeaderIndex + 1));
			jQuery("#current-view").css("margin-left", (newHeaderIndex * 12)+"px");
			
			jQuery("#header_"+(newHeaderIndex+1)).show();
			currentHeaderIndex = newHeaderIndex; changing = false;
		}
	} else {
		// Version with nice fades
		if (!changing && dir!='') {
			changing = true;
			if (dir == 'next') {
				newHeaderIndex = (currentHeaderIndex < headerContents.length - 1) ? currentHeaderIndex + 1 : 0;
			}
			else {
				newHeaderIndex = (currentHeaderIndex > 0) ? currentHeaderIndex - 1 : (headerContents.length - 1);
			}
			jQuery("#header_"+(currentHeaderIndex+1)).fadeOut(crossFadeSpeed, function() {
				jQuery("#header-navigation").removeClass();
				jQuery("#header-navigation").addClass("coloring_" + (newHeaderIndex + 1));
				jQuery("#current-view").css("margin-left", (newHeaderIndex * 12)+"px");
			});
			
			jQuery("#header_"+(newHeaderIndex+1)).fadeIn(crossFadeSpeed, function() {currentHeaderIndex = newHeaderIndex; changing = false;});
		}
	}
}

(function(jQuery) {

	jQuery.fn.randomize = function(childElem) {
		return this.each(function() {
      var $this = jQuery(this);
      var elems = $this.children(childElem);

      elems.sort(function() { return (Math.round(Math.random())-0.5); });  

      $this.remove(childElem);  

      for(var i=0; i < elems.length; i++)
        $this.append(elems[i]);      

		});    
	}
})(jQuery);

function isLoggedIn() {
	
}


// Cookie script from http://techpatterns.com/downloads/javascript_cookies.php
function Get_Helmi_Cookie( check_name ) {
  // first we'll split this cookie up into name/value pairs
  // note: document.cookie only returns name=value, not the other components
  var a_all_cookies = document.cookie.split( ';' );
  var a_temp_cookie = '';
  var cookie_name = '';
  var cookie_value = '';
  var b_cookie_found = false; // set boolean t/f default f

  for ( i = 0; i < a_all_cookies.length; i++ )
  {
    // now we'll split apart each name=value pair
    a_temp_cookie = a_all_cookies[i].split( '=' );


    // and trim left/right whitespace while we're at it
    cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

    // if the extracted name matches passed check_name
    if ( cookie_name == check_name )
    {
      b_cookie_found = true;
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if ( a_temp_cookie.length > 1 )
      {
	cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
      }
      // note that in cases where cookie is initialized but no value, null is returned
      return cookie_value;
      break;
    }
    a_temp_cookie = null;
    cookie_name = '';
  }
  if ( !b_cookie_found )
  {
    return null;
  }
}

function kerrokaverille() {
	var url = location.href;
  var kerropopup = window.open('http://www.mtv3.fi/helmi/kerro.shtml?'+url+'','kerropopup','width=250,height=160,resizable=no,location=no,menubar=no,toolbar=no,titlebar=no,personalbar=no,personalbar=no,directories=no,fullscreen=no');
  kerropopup.focus();
}

function tulosta(article) {
  var jaapopup = window.open(article,'kerropopup','width=700,height=500,resizable=yes,location=no,menubar=no,toolbar=no,titlebar=no,personalbar=no,personalbar=no,directories=no,fullscreen=no,scrollbars');
  jaapopup.focus();
}

function jaa_facebook() {
	var url = location.href;
  var jaapopup = window.open('http://www.facebook.com/sharer.php?u='+url,'kerropopup','width=700,height=500,resizable=no,location=no,menubar=no,toolbar=no,titlebar=no,personalbar=no,personalbar=no,directories=no,fullscreen=no');
  jaapopup.focus();
}

function jaa_facebook_url( url ) {
  var jaapopup = window.open('http://www.facebook.com/sharer.php?u='+url,'kerropopup','width=700,height=500,resizable=no,location=no,menubar=no,toolbar=no,titlebar=no,personalbar=no,personalbar=no,directories=no,fullscreen=no');
  jaapopup.focus();
}

function jaa_twitter() {
	var url = location.href;
	var title = document.title;
        var jaapopup = window.open('http://twitter.com/share?url='+url);
  jaapopup.focus();
}

function jaa_delicious() {
	var jaapopup = window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); 
	jaapopup.focus();
}

jQuery(document).ready(function($) {

	$(".artikkelinapit .nappi_jaa a").click(function() { 
		if ( $(".artikkelinapit .nappi_jaa").hasClass("over") ) {
			$(".artikkelinapit .nappi_jaa").removeClass("over");
		} else {
			$(".artikkelinapit .nappi_jaa").addClass("over");
		}
		return false;
	});
	
	$(".artikkelinapit .nappi_jaa ul li a").click(function() { 
		$(".artikkelinapit li").removeClass("over");
		return false;
	});

});
