﻿function checkWraper(IE, isWD, LI) {
    //alert(IE + "," + isWD + "," + LI);
    if (IE) {
        if (window.external.verifyApp) {
            if (LI)
                document.location = "/action/doAppLogin.aspx?" + window.external.getDownloadKey();
            if (isWD)
                document.location = "/action/doAppDL.aspx";
        }
        else if (!isWD)
            document.location = "/action/doWDL.aspx";
    }
    else {
        if (!isWD) 
        {
            document.location = "/action/doWDLOther.aspx";
        }
    }
}
function testDLK() {
    document.location = "/action/doAppLogin.aspx?" + window.external.getDownloadKey();
}


function isHighslideOpen() { //Chris
    return hs.getExpander();
}


function doClick(buttonName, e) {
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13) {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null) { //If we find the button click it
            switch (btn.tagName) {
                case 'INPUT':
                    btn.click();
                    break;
                case 'A':
                    window.location = btn.href;
                    break;
            }
            event.keyCode = 0;
        }
    }
}


function digXajaxFunLink(f, params, successCallback) {
    var paramStr = $.param(params);
    $.ajax({
        url: '/ajax/ajaxFun.aspx',
        type: 'POST',
        data: 'f=' + f + (paramStr.length > 0 ? '&' + paramStr : ''),
        dataType: 'json',
        success: function (data) {
            if (data.message != null && data.message != undefined && data.message.length > 0)
                alert(data.message);
            successCallback(data.results);
        },
        error: function (data, errorStr) {
            alert('There was an error comunicating with the server, please try again later or contact us if you need assistance.');
        }
    });
}

function digXextendThumbActivate() {
    $('.digXextendThumb').each(function () {
        var curThumb = $(this)
        curThumb.data("over",false);
        curThumb.mouseover(function () {
            $(this).data("over", true).data("timer", setTimeout("digXextendThumb('"+this.id+"')",100));
        });
        curThumb.mouseout(function () {
            $(this).data("over", false);
            clearTimeout(curThumb.data("timer"));
        });
    });
}
function digXextendThumb(thumbID) {
    var curThumb = $('#' + thumbID);
    if (!curThumb.data("over"))
        return;
    var extendedThumb = $('#' + thumbID + "_EXTENDED");
    if (extendedThumb.length == 0) {
        extendedThumb = $('<div>', {
            'id':thumbID + '_EXTENDED',
            'class': 'digXextendThumbExtended',
            'style': 'display:none;position:absolute;'
        });
        extendedThumb.offset(curThumb.offset());
        extendedThumb.height(curThumb.height()).width(curThumb.width());
        var extendedThumbHover = $('<div>', {
            'class': 'digXextendThumbExtendedHover'
        });
        extendedThumbHover.mouseout(function () {
            digXextendThumbRemove($(this).parent()[0].id.replace('_EXTENDED', ''));
        });
        extendedThumbHover.click(function () {
            var link = $('#' + $(this).parent()[0].id.replace('_EXTENDED', '')).parent();
            if (link[0].onclick != undefined)
                link.click();
            else
                window.location = link[0].href;
        });
        extendedThumbImage = $("<img>", { 
            'src':curThumb.attr('src').replace(/[a-zA-Z]+Thumb/,'MThumb'),
            'class': 'digXextendThumbExtendedImg'
        });
        extendedThumb.append(extendedThumbImage, extendedThumbHover);
        $('body').append(extendedThumb);
    }
    $('.digXextendThumbExtended:visible').each(function () {
        digXextendThumbRemove(this.id.replace('_EXTENDED', ''))
    });
    extendedThumb.show().find('.digXextendThumbExtendedImg').animate({ 'width': "200px", 'height': "200px" }, 200);
}
function digXextendThumbRemove(thumbID) {
    var extendedThumb = $('#' + thumbID + "_EXTENDED");
    if (extendedThumb.length == 0)
        return
    extendedThumb.hide().find('.digXextendThumbExtendedImg').stop().css({ 'width': "100%", 'height': "100%" });
}
$(function () {
    digXextendThumbActivate();
});

