$(document).ready(function() {

$("a.tinymce-popup").fancybox({
'width'		: '90%',
'height'	: '90%',
'autoScale'     : false,
'scrolling':'no',
'type'		: 'iframe',
'modal':true
});

$("a.image-gallery").fancybox({
'transitionIn'	: 'elastic',
'transitionOut'	: 'elastic',
'opacity':'true',
'easingIn'      : 'easeOutBack',
'easingOut'     : 'easeInBack',
'titlePosition'	: 'over',
'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Kuva ' +  (currentIndex + 1) + ' / ' + currentArray.length + '<br>'+title+'</span>';
}
});

$("a.video-gallery").fancybox({
'width'		: 624,
'height'	: 440,
'autoScale'     : false,
'scrolling':'no',
'titleShow':false,
'type'		: 'iframe'
});

});

function init_h1(){
	for (var i=0;i<document.getElementById('content').getElementsByTagName('h1').length;i++)
	{
		var oldHTML = document.getElementById('content').getElementsByTagName('h1')[i].innerHTML;
		var newHTML = "<span class=left>" + oldHTML + "<\/span><span class=right></span>";
		document.getElementById('content').getElementsByTagName('h1')[i].innerHTML = newHTML;
	}
}

function cleancut(text, maxlen) {

  // remove img tags
  var re = new RegExp("<\s*\/?\s*img\s*.*?>|<\s*\/?\s*IMG\s*.*?>", "g");
  var res = text.replace(re, "");
  var result = "";
  var words = res.split(" ");
  for (x in words) {
    if ((result.length + words[x].length) <= maxlen) {
      result += words[x] + " ";
    } else {
      break;
    }
  }
 return result;
}

$(document).ready(function(){
$('.racecalendar').vTicker({
   speed: 500,
   pause: 5000,
   showItems: 2,
   animation: 'fade',
   mousePause: false,
   height: 0,
   direction: 'up'
});
});
