// dropdown navigaatio
jQuery(document).ready(function($) {
	HandleNavigationDropDowns();
});

var that = null;

function HandleNavigationDropDowns() {
	$('#mainNavigationDropDown li a').not('#mainNavigationDropDown ul.level1 li a').mouseover(function() { if (that != $(this).closest('li')[0] && that != null) { $(that).removeClass('showsub'); } that = $(this).closest('li')[0]; $(that).addClass('showsub'); });
	$('#contentWrapper').mouseover(function() { $(that).removeClass('showsub'); });
}


$(document).ready(function() {
    //otsikoiden määrä
    var om = $('.frontpage #contentWrapper .channelView .content .block .newsTitle a').size();
    for (var i = 0; i < om; i++) {
        //indeksointi
        $('.frontpage #contentWrapper .channelView .content .block .newsTitle a').eq(i).addClass('item_' + i);
        var teksti = $('.frontpage #contentWrapper .channelView .content .block .newsTitle a').eq(i).text();
        //substring, 34
        $('.frontpage #contentWrapper .channelView .content .block .newsTitle a').eq(i).text(teksti.substring(0, 31) + '...');
    }

    //swap image for hover effect (doesn't work for rootpage)
    $('.customNav a img.hover').hover(
            function() {
                this.src = this.src.replace(/\.gif$/, '_act.gif');
            },
            function() {
                this.src = this.src.replace(/_act\.gif$/, '.gif');
            }
        );


    //Loop link
    var yhtx = $('.dropdownNav .content div.db a').size();
    for (var x = 0; x < yhtx; x++) {
        $('.dropdownNav .content .ddMenu select').append('<option>' +
            $('.dropdownNav .content div.db a').eq(x).text() +
            '</option>')
    }

    //onClick
    $('.dropdownNav input.Button').click(function() {
        $('.dropdownNav .content .cpath').text(document.getElementById("ddownMenu").selectedIndex)
    });

    //redirect function
    $('.dropdownNav .content input.Button').click(function() {
        var ind = $('.dropdownNav .content .cpath').text();
        window.location.href = $('.dropdownNav .content div.db a').eq(ind).attr('href');
        return false;
    });

    //force height for contentLeft
    if ($('.columns2 #contentLeft').height() < $('.columns2 #contentCenter').height()) {
        $('.columns2 #contentLeft').height($('.columns2 #contentCenter').height());
    }
}); 


