﻿$(document).ready(function() {

    
    // Add pdf icons to pdf links
    $(".attachments a").addClass("download"); //default icon, might be overridden later    
    $(".attachments a[href$='.pdf']").addClass("pdf");
    $(".attachments a[href$='.mp3'], .attachments a[href$='.wav']").addClass("audio");
    $(".attachments a[href$='.doc'], .attachments a[href$='.rtf'], .attachments a[href$='.docx']").addClass("word");
    $(".attachments a[href$='.xls'], .attachments a[href$='.xlsx'], .attachments a[href$='.csv']").addClass("excel");
    $(".attachments a[href$='.jpg'], .attachments a[href$='.png'], .attachments a[href$='.gif'], .attachments a[href$='.tif'], .attachments a[href$='.tiff'], .attachments a[href$='.bmp']").addClass("picture");
    $(".attachments a[href$='.avi'], .attachments a[href$='.flv'], .attachments a[href$='.wmv'], .attachments a[href$='.mov'], .attachments a[href$='.divx'], .attachments a[href$='.mpeg']").addClass("video");
    $(".attachments a[href$='.zip'], .attachments a[href$='.rar']").addClass("zip");


    /*
    // Add email icons to email links
    $("a[href^='mailto:']").addClass("email");

    //Add external link icon to external links - 
    $('a').filter(function() {
    //Compare the anchor tag's host name with location's host name
    return this.hostname && this.hostname !== location.hostname;
    }).addClass("external");
    */

    //You might also want to set the _target attribute to blank
    /*
    $('a').filter(function() {
    //Compare the anchor tag's host name with location's host name
    return this.hostname && this.hostname !== location.hostname;
    }).addClass("external").attr("target", "_blank");
    */

    $("#forside .cmsContent0 a ").mouseover(function (ev) {

        forsideHover(ev.target);
    }).mouseout(function (ev) {
        forsideHover(ev.target);
    });
});
function fillTextBox(place) {
    switch(place){
        case 'name':
            $(".delName").val($(".newName").val());
            if ($(".invoName").length) {
                $(".invoName").val($(".newName").val());
            }
            break;
        case 'surname':
            $(".delSurname").val($(".newSurname").val());
            if ($(".invoSurname").length) {
                $(".invoSurname").val($(".newSurname").val());
            }
            break;
        default:
            break;
        }
}
function forsideHover(el) {
    if (el.tagName.toLowerCase() != "img") {
        el = $(el).nextAll("img");
    } else {
        el = $(el);
    }
    var src = el.attr("src");
    if (src == null) {
        return;
    }
    if (src.indexOf("_hover") == -1) {
        //er ikke hover
        var indexOfDot = src.lastIndexOf(".");
        var filename = src.substring(0, indexOfDot);
        src = filename + "_hover" + src.substring(indexOfDot);
    } else {
        //er hover, gjør om til normal
        src = src.replace("_hover", "");
    }
    el.attr("src", src);
}
 
