﻿j$ = jQuery.noConflict();

// INIT LINKS TO EXTERNAL SOURCE
j$(document).ready(function() {
var links = j$("a");
j$.each(links, function(i, val) {
    url = val.toString().toLowerCase();
    if (String(j$(val).attr('href')).substr(0, 4) == 'http' || url.indexOf("/widex-com") > -1) {
        j$(this).attr('href', 'javascript:openExternalLink(\'' + url + '\');');
        j$(this).attr('target', '');
        }
    });
});

// ## OPEN EXTERNAL LINK
function openExternalLink(url) {
    var cur = j$("#notifier .content div");
    var cur0 = j$("#notifier .content");
    
    if (url.indexOf("130.227.121.175/flashcampaign") >= 0 || url.indexOf("campaign.widex.com") >= 0) {
        j$(cur).find("a.button").attr('href', "javascript:poponClick('" + url + "'); hideNotification();").html('OK');
    }
    else if (url.indexOf("chiwi.widex.com") >= 0) {
    j$(cur).find("a.button").attr('href', "javascript:popupFullScreen('" + url + "'); hideNotification();").html('OK');
    }
    else {
        j$(cur).find("a.button").attr('href', url).html('OK');
        j$(cur).find("a.button").attr("onclick", "hideNotification();");
        j$(cur).find("a.button").attr('target', '_blank');
    }
    
    showNotification(true);
}

function showNotification(closeable) {
    j$("#notifier").show();
    j$("#notifier .content .close").css("display", (closeable ? 'block' : 'none'));
    updatePosition();
}

function hideNotification() {
    j$("#notifier").hide();
    //j$("#notifier .content div a.button").attr('href', '#');
}

function updatePosition() {
    var margin = (j$("#notifier .content").height() / 2) * -1;
    j$("#notifier .content").css('margin-top', margin + 'px');

    // IF TEXT CONTENT IS BIGGER THAN CLIENT HEIGHT, CHANGE IT
    if (j$("#notifier .content").height() >= j$("html").height()) {
        j$("#notifier").css("position", "absolute").css("height", j$("#notifier .content").height() + 40);
    } else {
    j$("#notifier").css("position", "absolute").css("height", "100%");
    }
}

