﻿/* ===================================================================================================================*/
/* billywig player */
var openPlayerID = "";
var isCarrouselPlayer = ""

function openPlayer(id) {

    // remember me
    openPlayerID = id;

    // hide all slides
    $("#slides").hide();
    // show player
    $("#play_" + id).show();
}

function openCarrouselPlayer(id) {

    // remember me
    openPlayerID = id;
    isCarrouselPlayer = 1;

    // hide all slides
    $("#slides").hide();
    
    // show player
    $("#play_" + id).show();
}

function closePlayer() {

    // hide player
    $("#play_" + openPlayerID).hide();

    // show slides
    $("#slides").show();

    // reset player
    isCarrouselPlayer = "";
    openPlayerID = "";
}

/* ===================================================================================================================*/
/* mediacarrousel */
function showSlide(slide) {
    if (isCarrouselPlayer == "") {
        // show correct slide
        $("#slides div.slide").hide();
        $("#slides div.slide" + slide).show();

        // select button
        $("#buttons li").removeAttr("id");
        $("#buttons .jcarousel-item-" + slide).attr("id", "button_selected");
    }
}

function slideToSelectedButton(page) {
    if (carrouselPage > page) {
        $(".jcarousel-prev").click();
    }
    else if (carrouselPage < page) {
        $(".jcarousel-next").click();
    }
    if (carrouselPage != page) {
        setTimeout(function() { slideToSelectedButton(page); }, 425);
    }
}

/* ===================================================================================================================*/
/* Mailto function */
function insertMailToTag(domainName, userName) {
    var emailId;
    var atSign = "&#64;"

    emailId = userName;
    emailId = "" + emailId + atSign;
    emailId = emailId + domainName;

    document.write("<a href='mail" + "to:" + emailId + "'>" + emailId + "</a>");
}

/* ===================================================================================================================*/
/* NAVIGATION */
function showSubnav(nr) {
    if (typeof (hideSubnavTimeout) != "undefined") {
        clearTimeout(hideSubnavTimeout);
    }

    // hide all subnavs
    $('.subnav').hide();

    // reset all nav hovers
    var navitems = $("DIV.navigation DIV.item").children('A.nav');
    for (var i = 0; i < navitems.length; i++) {
        hideNavHover($(navitems[i]).attr("itm"));
    }

    // show subnav of this item
    document.getElementById('pnlSubNav' + nr).style.display = '';
    showNavHover(nr);
}
function hideSubnav(nr) {
    hideSubnavTimeout = setTimeout(function() { document.getElementById('pnlSubNav' + nr).style.display = 'none'; hideNavHover(nr); }, 500);
}

function showNavHover(nr) {
    // show active navimage
    $('.iNavAct' + nr).show();
    $('.iNav' + nr).hide();
}
function hideNavHover(nr) {
    // reset navimage
    if ($('.iNav' + nr).attr("default") == "1") {
        $('.iNavAct' + nr).hide();
        $('.iNav' + nr).show();
    }
}

/* ===================================================================================================================*/
/* popup */
function showPopup(title, group, teaser, url, image) {
    // fill popup
    document.getElementById('puTitle').innerHTML = title;
    document.getElementById('puTitle').href = url;
    document.getElementById('puGroup').innerHTML = group;
    document.getElementById('puGroup').href = url;
    document.getElementById('puTeaser').innerHTML = teaser;
    document.getElementById('puImage').src = image;
    document.getElementById('puImage').alt = title;
    document.getElementById('puLink').href = url;
    document.getElementById('puImgLink').href = url;

    // show popup
    document.getElementById('popup').style.display = '';
}

function closePopup() {
    // hide popup
    document.getElementById('popup').style.display = 'none';
}

/* click with enter 
==================================================*/
function doClick(buttonName, e) { var key; if (window.event) { key = window.event.keyCode; } else { key = e.which; } if (key == 13) { var btn = document.getElementById(buttonName); if (btn != null) { newBtnName = buttonName.replace(/_/g, "$"); if (DES_BtnClick(buttonName)) { __doPostBack(newBtnName, e) } event.keyCode = 0 } } } function doButtonClick(buttonName, e) { var key; if (window.event) { key = window.event.keyCode; } else { key = e.which; } if (key == 13) { var btn = document.getElementById(buttonName); if (btn != null) { event.keyCode = 0 } } }

/* jquery.imagescroller add-on functions
==================================================*/
function stopScroller() {
    if (document.getElementById('container')) { $("div#container").stop(true); }
}
function startScroller() {
    if (document.getElementById('container')) {
        var duration = $(".wrapper").length * 4000;
        var speed = (parseInt($("div#container").width()) + parseInt($("div#viewer").width())) / duration;
        var dir = ($("div#container").hasClass("ltr")) ? "ltr" : "rtl";
        var totalDistance = parseInt($("div#container").width()) + parseInt($("div#viewer").width());
        var distanceLeft = ($("div#container").hasClass("ltr")) ? totalDistance - (parseInt($("div#container").css("left")) + parseInt($("div#container").width())) : totalDistance - (parseInt($("div#viewer").width()) - (parseInt($("div#container").css("left"))));
        var newDuration = distanceLeft / speed; 
        $("div#container").animator($("div#container"), newDuration, dir, speed, duration, 0); 
    }
}

/* correct height left column home
==================================================*/
function correctHomeCellHeight() {
    var rightHeight = document.getElementById('tdRight').offsetHeight;
    var leftHeightRest = rightHeight - 321;
    document.getElementById('tdLeftRest').style.height = leftHeightRest + "px";
}

/* resizing background
==================================================*/
function resizeImage() {
    var window_height = parseInt($(window).height());
    var window_width = parseInt($(window).width());

    var image_width = parseInt($('#bgr_site').attr('width'));
    var image_height = parseInt($('#bgr_site').attr('height'));

    var height_ratio = window_height / image_height
    var width_ratio = window_width / image_width


    if (height_ratio > width_ratio) {
        var new_height = Math.ceil(height_ratio * image_height);
        var new_width = Math.ceil(height_ratio * image_width);

    } else {
        var new_height = Math.ceil(width_ratio * image_height);
        var new_width = Math.ceil(width_ratio * image_width)
    }

    $('#bgr_site').attr('width', new_width);
}

$(document).ready(function() {
    resizeImage();
    $(window).bind('resize', resizeImage);
});
