﻿// My Scripts

// Resourse Item
function getResourceItem(id, type) {

    // Get WebRoot
    var webRoot = "http://" + window.location.host;
    if (window.location.pathname.split("/")[1].toLowerCase() == "mdsl") {
        webRoot = webRoot + "/mdsl";
    }

    // Get Data
    $$.query.ajax({
        type: "GET",
        data: { ID: id, TYPE: type },
        url: webRoot + "/ResourceItem.ashx",
        dataType: "xml",
        success: function (xml) {
            // Handle the Info
            var useFancyBox = true;
            var type = $$.query(xml).find('type').text();
            var title = $$.query(xml).find('title').text();
            var date = $$.query(xml).find('date').text();
            var content = $$.query.trim($$.query(xml).find('content').text());

            if (type != "") {

                var myHtml = "";

                if (type == "videos" || type == "webinars") {

                    myHtml = "<OBJECT ID='MediaPlayer' WIDTH='592' HEIGHT='390' CLASSID='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95'";
                    myHtml += "STANDBY='Loading Windows Media Player components...' TYPE='application/x-oleobject'>";
                    myHtml += "<PARAM NAME='WindowlessVideo' VALUE='-1'>";
                    myHtml += "<PARAM NAME='FileName' VALUE='" + content + "'> ";
                    myHtml += "<PARAM name='ShowControls' VALUE='true'>";
                    myHtml += "<PARAM name='ShowStatusBar' VALUE='false'>";
                    myHtml += "<PARAM name='ShowDisplay' VALUE='false'>";
                    myHtml += "<PARAM name='autostart' VALUE='true'>";
                    myHtml += "<EMBED TYPE='application/x-mplayer2' SRC='" + content + "' NAME='MediaPlayer'";
                    myHtml += "WIDTH='592' HEIGHT='390' ShowControls='1' ShowStatusBar='1' ShowDisplay='1' autostart='1'></EMBED>";
                    myHtml += "</OBJECT>";

                }
                else if (type == "whitepapers" || type == "collateral") {

                    var myUrl = encodeURIComponent("http://" + window.location.host + content);
                    
                    if ($$.query.browser.msie) {
                        //useFancyBox = false;
                        //myUrl = "http://docs.google.com/viewer?embedded=false&url=" + myUrl;
                        //window.location = myUrl;

                        myHtml += "<div style='height: 130px; width: 300px;'>";
                        myHtml += "<div style='font-weight: bold; font-size: 14px; text-decoration: underlined;'>Please Select an Option:</div>";
                        myHtml += "</br>";
                        myHtml += "<p>- <a id='ieatag' href='http://docs.google.com/viewer?embedded=true&url=" + myUrl + "' target='_Blank'>View Document in New Tab</a></p>";
                        
                        myHtml += "</br>";
                        myHtml += "<p>- <a href='" + content + "'>Download Document</a></p>";
                        myHtml += "</div>";

                    }
                    else {
                        myHtml = "<div>";
                        myHtml += "<iframe src='http://docs.google.com/viewer?embedded=true&url=" + myUrl + "' width='600' height='780' style='border: none;'></iframe>";
                        //myHtml += "<iframe src='http://docs.google.com/viewer?url=http://" + window.location.host + content + "&embedded=true' width='600' height='780' style='border: none;'></iframe>";
                        myHtml += "<p>- <a href='" + content + "'>Download Document</a></p>";
                        myHtml += "</div>";
                    }

                }
                else {
                    myHtml = "<div style='font-weight: bold; color:#800C03; font-size: 14px;'>" + title + "</div>";
                    myHtml += "<div style='font-weight: bold;'>" + date + "</div>";
                    myHtml += "</br>";
                    myHtml += "<div>" + content + "</div>";
                }

                if (useFancyBox)
                    $$.query.fancybox(myHtml);

            }
            // End Handle the Info
        }
    });

}



// Preload Images
(function ($) {
    // Preload Images Plugin
    $.fn.preloadImages = function () {
        this.each(function () {
            $('<img/>')[0].src = this;
        });
    }
})(jQuery);

// RSS CLIENT
//

function getFeed(webroot, index, gfCount) {
    // Load feed
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = webroot + '/Gateway.aspx?F=' + index + '&C=' + gfCount;
    head.appendChild(script);

    // Update icons
//    var table = document.getElementById('feedIcons');
//    var icons = table.getElementsByTagName('img');
//    var i;
//    for (i = 0; i < icons.length; i++) {
//        var icon = icons[i];
//        var suffix = (i == index) ? '-IN' : '';
//        icon.src = webroot + '/Images/' + icon.title + suffix + '.png';

//        if (i == index) {
//            icon.onmouseover = null;
//            icon.onmouseout = null;
//        }
//        else {
//            icon.onmouseover = function () { overFeed(this, webroot); };
//            icon.onmouseout = function () { outFeed(this, webroot); };
//        }
//    }
}

function overFeed(icon, webroot) {
    icon.src = 'Images/' + icon.title + '-RO.png';
}

function outFeed(icon, webroot) {
    icon.src = 'Images/' + icon.title + '.png';
}
function handleFeed(index, content) {

    var id = '';

    if (index == 0) {
        id = 'feedTwitterContent';
    }
    else if (index == 1) {
        id = 'feedLinkedInContent';
    }

    
    var div = document.getElementById(id);
    if (div)
        div.innerHTML = content;
}


// 
function SideNavFontFix() {
    $$.query('.acaHeadText').each(function () {

        var width = $$.query(this).width();
        var fontSize = $$.query(this).css('font-size');

        if (width > 180) {
            SideNavFontReduceFont($$.query(this));
        }
    });

    if (!SideNavFontIsFixed()) {
        SideNavFontFix();
    }
    else {
        SideNavFontTopPosition();
    }
}
function SideNavFontReduceFont(el) {
    var currSize = $$.query(el).css('font-size');
    var finalNum = parseFloat(currSize, 10);
    var stringEnding = currSize.slice(-2);
    if (finalNum > 0) {
        $$.query(el).css('font-size', finalNum - 1)
    }

    return el;
}
function SideNavFontIsFixed() {
    var isFixed = true;

    $$.query('.acaHeadText').each(function () {
        if ($$.query(this).width() > 180) {
            isFixed = false;
        }
    });

    return isFixed;
}
function SideNavFontTopPosition() {

    $$.query('.acaHeadText').each(function () {

        var fontSize = parseFloat($$.query(this).css('font-size'), 10);

        var newTP = 5;
        switch (fontSize) {
            case 0:
                newTP = 11;
                break;
            case 1:
                newTP = 11;
                break;
            case 2:
                newTP = 11;
                break;
            case 3:
                newTP = 11;
                break;
            case 4:
                newTP = 10;
                break;
            case 5:
                newTP = 10;
                break;
            case 6:
                newTP = 9;
                break;
            case 7:
                newTP = 9;
                break;
            case 8:
                newTP = 8;
                break;
            case 9:
                newTP = 7;
                break;
            case 10:
                newTP = 6;
                break;
            default:
                newTP = 5;

        }

        $$.query(this).css('top', newTP + 'px');

    });
}
