﻿function addImageTexts()
{
    try 
    {
        // find all img tags in html
        var imgArr = document.getElementsByTagName("img");
        // loop through
        for (var i=0; i<imgArr.length; i++)  
        {
            // get current image
            var img=imgArr[i];
            // regular expression to test against the class attribute
            var regex = /(\s|^)kuvateksti(\s|$)/;
            // if img contains class attribute and class attribute's value contains kuvateksti
            if ( img.attributes("class") && img.attributes("alt") && regex.test(img.attributes("class").value)) 
            {
                // create a blockquote element to hold the img alt text value   
                var txt = document.createElement("blockquote");     
                // create a span element to hold correct width
                var style="width: " + img.attributes("width").value + "px; display: block;"; 
                txt.innerHTML = "<span style=\"" + style + "\">" + img.attributes("alt").value + "</span>";
                // add the newly created element below the img element
                img.parentNode.insertBefore( txt, img.nextSibling );
            } 
        }
    } catch (err) {}
}

//***********************************************************************************************
// on mouse over efects for frontpage news

function changeBgImage_Releases(ID) 
{
    
    newImage = "url(/Templates/Public/Styles/Orion/images/bg_news_hover_no_borders.gif)";
    document.getElementById(ID).style.backgroundImage = newImage;
    document.getElementById(ID).style.backgroundRepeat = "repeat-x";
    document.getElementById(ID).style.backgroundColor = "#e7f1fc";
}

function removeBgImage(newsID) 
{
    document.getElementById(newsID).style.backgroundImage = "";
    document.getElementById(newsID).style.backgroundColor = "#ffffff"
}


//***********************************************************************************************
//onload behaviour

window.onload = function onLoad() {    
    alternateTableRows()
    addOnMouseover()
}

// this function adds alternating css classes to table rows, if table's class is "calendar" (alternating background colors for classes odd and even are defined in stylesheet )
function alternateTableRows(){
      var elem = "TR";
      if(document.getElementsByTagName){
        var el = document.getElementsByTagName(elem);
          for(var i=0; i<el.length; i++){
             if(el[i].childNodes[0].tagName != "TH" && el[i].parentNode.parentNode.className.indexOf("calendar") != -1){
                el[i].parentNode.parentNode.cellSpacing = 0;    //set cellspacing to 0
                el[i].parentNode.parentNode.cellPadding = 0;    //set cellpadding to 0
                if(i%2 == 1){
                    el[i].className = "odd";   
                } 
                else {
                     el[i].className = "even";
                     
                }
            }
        }
    }    
}

// this function adds onmouseover and onmouseout behaviours to SectionContentHighlight table on Sectionstartpage
function addOnMouseover() {
    var table = document.getElementById("SectionContentHighlight");
    if (table != null) {
        var rows = table.getElementsByTagName("tr");  
        for(i = 0; i < rows.length; i++){   
            rows[i].onmouseover = function(){this.className="highlight_hover";};
            rows[i].onmouseout = function(){this.className="highlight";};
        }
    }   
}

//***********************************************************************************************
