function piilota(mita){ 
      for(i=0;i<mita.length;i++){
        elem=document.getElementById(mita[i].toString());
        elem.style.visibility = "hidden";
        elem.style.display = "none";
      }
    }
    function nayta(linkit){
        lista = new Array("kunto", "kilpailut", "tieto", "kuvat", "ilmot", "muut");
        piilota(lista);
        linkit.style.visibility = "visible";
        linkit.style.display = "block";
}
function new_freecap()
{
    // loads new freeCap image
    if(document.getElementById)
    {
        // extract image name from image source (i.e. cut off ?randomness)
        thesrc = document.getElementById("freecap").src;
        thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
        // add ?(random) to prevent browser/isp caching
        document.getElementById("freecap").src = thesrc+"?"+Math.round(Math.random()*100000);
    } else {
        alert("Sorry, cannot autoreload freeCap image\nSubmit the form and a new freeCap will be loaded");
    }
}

$(document).ready(function(){

    if ($('a[rel^=lightbox]').length)
    {
        $('a[rel^=lightbox]').each(function(i, item){
            var url = $(item).attr('href');
            $(item).attr('href', url.replace('?sivu=','/'));
        }); 
        $('a[rel^=lightbox]').fancybox({
            'titlePosition' : 'over',
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            //'easingIn'      : 'easeOutBack',
            //'easingOut'     : 'easeInBack',
            'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) 
                              {
                                return '<span id="fancybox-title-over">Kuva ' +  
                                        (currentIndex + 1) + ' / ' + currentArray.length + ' - ' + title
                                       '</span>';
                              }
        });
    }
    
  /*  $('#upload-images').uploadify({
        'uploader'  : '/jquery/uploadify/uploadify.swf',
        'script'    : '/jquery/uploadify/uploadify.php',
        'folder'    : '/uploads',
        'cancelImg' : '/jquery/uploadify/cancel.png',
        'fileDesc'  : 'Kuvatiedostot',
        'fileExt'   : '*.gif;*.jpg;*.png',
        'folder'    : '/gallery/' + $('#folder-name').val(),
        'multi'     : true,
        'auto'      : true
    });
    */
    
    var calTimer;
    
    if ($('#calendar').length)
    {
        $('#calendar').parent().prepend('<div id="tooltip"></div>');
        $('#tooltip').css({
            'position' : 'absolute',
            'max-width' : '200px',
            'border' : '1px solid #ccc',
            'background' : '#ffffff',
            'padding' : '10px',
            'text-align' :'left'
        }).hide();
        $('#calendar a.tip').hover(
            function()
            {
                var event = $(this);
                
                var content = event.attr('title').split('|').join('<br />');
                $('#tooltip').html(content);
                event.attr('title','')
                
                calTimer = window.setTimeout(function()
                {                                                        
                    offset = event.position();
                    $('#tooltip').css({
                        left : offset.left + 100,
                        top  : offset.top + 15
                    }).fadeIn('fast');
                    calTimer = null;
                }, 300);
            },
            function()
            {
                var event = $(this);
                if (calTimer)
                    window.clearTimeout(calTimer);
                else
                    $('#tooltip').hide();
                
                title = $('#tooltip').html().replace('<br />','|');
                event.attr('title', title);                
            }            
        );             
    }
    if ($('a.rastit').length)
        {
            $('a.rastit').each(function(i, item){        
                var link = $(item).attr('href').replace('?sivu=','http://www.kokkolansuunnistajat.fi/');
                var ind = link.indexOf('&');
                $(item).attr('href', link.substr(0, ind) + '?' + link.substr(ind + 1));
            }).css('color','#006699').fancybox({
                'titlePosition' : 'over',
                'transitionIn'	: 'elastic',
                'transitionOut'	: 'elastic'        
            });
        }  
    if ($('span.guide a').length)
    {
        $('span.guide a').each(function(i, item){        
            var link = $(item).attr('href').replace('?sivu=','http://www.kokkolansuunnistajat.fi/');
            var ind = link.indexOf('&');
            $(item).attr('href', link.substr(0, ind) + '?' + link.substr(ind + 1));
        });
        
        $('span.guide a').fancybox({
            'titlePosition' : 'over',
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic'        
        });
    }
        
    if ($('a.fancyPDF').length)
    {        
        $('a.fancyPDF').fancybox({
            'frameWidth' : 940,
            'width'      : 945,            
            'frameHeight': 750,
            'height'     : 755,            
            'overlayShow': true, 
            'hideOnContentClick': false, 
            'type' : 'iframe'
        });
    }
    
    if ($('a.iframe').length)
    {        
        $('a.iframe').fancybox({
            'width': 900,                    
            'type' : 'iframe'
        });
    }
    
    if ($('input.date').length)
    {
        $('input.date').datepicker(
		{
            dateFormat     : 'dd.mm.yy',
            dayNames       : ['Sunnuntai','Maanantai','Tiistai','Keskiviikko','Torstai','Perjantai','Lauantai'],
            dayNamesShort  : ['Su','Ma','Ti','Ke','To','Pe','La'],
            dayNamesMin    : ['Su','Ma','Ti','Ke','To','Pe','La'],
            firstDay       : 1,
            monthNames     : ['Tammikuu','Helmikuu','Maaliskuu','Huhtikuu','Toukokuu','Kesäkuu',
                             'Heinäkuu','Elokuu','Syyskuu','Lokakuu','Marraskuu','Joulukuu'],
            showAnim       : 'fadeIn',
            showOtherMonths: true
		});	
	}		

});