Cufon.replace('h1,h2', { fontFamily: 'proximaCond' });

var html5 = ['header', 'footer', 'aside', 'hgroup', 'nav', 'section', 'article', 'figure']; for (key in html5) { document.createElement(html5[key]) };

var maxRetries = 10;
var retry = 0;
var hasYL = false;
var qs = location.href;
var browserPrefix = '';

function getInstallId() {
    try {
        if (typeof (yontooAPI) == "undefined") {
            try {
                if (window.ActiveXObject) {
                    yontooAPI = new ActiveXObject("YontooIEClient.Api");
                }
            }
            catch (ex) {
            }
        }
        if (typeof (yontooAPI) != "undefined") {
            var id = yontooAPI.getInstallId();
            return id;
        } else if (typeof (getInstalledClientId) !== "undefined") { //chrome
            return getInstalledClientId();
        } else {
            var idElement = findObj("YontooInstallID");
            if (idElement != undefined && idElement != null) {
                return idElement.innerHTML;
            } else {
                return "";
            }
        }
    }
    catch (ex) {
        //console.log(ex);
    }
    return "";
}
function setupDownloadEnable() {
    var installId = getInstallId();
    if (installId === "" || installId === null || installId === undefined) {
        if (retry < maxRetries) {
            retry++;
            setTimeout(setupDownloadEnable, 100);
        } else {
            addTease('download');
            hasYL = true;
        }
    } else {

        checkEnabled(installId);
    }
}
function checkEnabled(guid) {
    var url = 'http://www.buzzdock.com/handlers/EnabledApps.ashx?appid=buzzdock&guid=' + guid + '&date=' + new Date().getTime();

    $.ajax({ url: url,
        dataType: 'json',
        success: function (data) {
            if (data['buzzdock']) {
                addTease('enabled');
            } else {
                addTease('disabled');
            }

        }
    });
}
function createBtn(type) {
    var btn = document.createElement('a');
    btn.id = 'freedownload_btn';
    btn.style.height = '36px';


    switch (type) {
        case 'enabled':
            btn.title = 'Buzzdock Enabled';
            btn.style.background = 'url(../images/BuzzdockEnabled_btn.png) no-repeat';
            btn.style.cursor = 'default';

            break;
        case 'disabled':
            btn.title = 'Enable Buzzdock';
            btn.style.background = 'url(../images/EnableBuzzdock_btn.png) no-repeat';
            btn.onclick = enableBD;
            $(btn).hover(function () { $(this).css({ backgroundPosition: '0 -39px' }) }, function () { $(this).css({ backgroundPosition: '0 0' }) });
            break;
        case 'download':
        default:
            btn.title = 'Download Buzzdock';
            if (BrowserDetect.OS == 'Windows') {
                if (BrowserDetect.browser == 'Explorer') {
                    btn.href = 'http://www.buzzdock.com/Pages/Download_Explorer.aspx';
                } else if (BrowserDetect.browser == 'Chrome') {
                    btn.href = 'http://www.buzzdock.com/Pages/Download_Chrome.aspx';
                } else if (BrowserDetect.browser == 'Firefox') {
                    btn.href = 'http://www.buzzdock.com/Pages/Download_Firefox.aspx';
                } else {
                    btn.href = 'http://www.buzzdock.com/Pages/Downloads.aspx';
                }
            } else {
                btn.href = 'http://www.buzzdock.com/Pages/Downloads.aspx';
            }
            break;
    }
    return btn;
}
function createMsg(type) {
    var txt = document.createElement('div');
    txt.id = 'sc';
    txt.style.position = 'absolute';
    txt.style.top = '15px';
    txt.style.left = '520px';
    txt.style.color = '#6d6e70';
    txt.style.fontStyle = 'italic';
    txt.style.fontSize = '18px';
    txt.style.fontWeight = 'bolder';

    switch (type) {
        case 'enabled':
            txt.innerHTML = '';

            break;
        case 'disabled':
            txt.innerHTML = 'Supercharge Your Search!';

            break;
        case 'download':
        default:
            txt.innerHTML = 'Supercharge Your Search!';
            break;
    }
    return txt;
}
function addTease(type) {
    $('#sc, #freedownload_btn').remove();
    // Don't show teaser for /Downloads.aspx, /Search.aspx, /Disable
    if (qs.search(/Downloads.aspx/i) == -1 && qs.search(/Search.aspx/i) == -1 && qs.search(/Disable/i) == -1) {
    
        var top = document.getElementById('top');

        var dlBtn = createBtn(type);
        var dlMsg = createMsg(type);

            top.appendChild(dlBtn);
            top.appendChild(dlMsg);

            $('#sc').animate({ left: 550 }, 0);
    
        if (type == 'download') {
            if (document.getElementById('bdDlTeaseSearch')) {
                $('#bdDlTeaseSearch').animate({ height: 35 }, 0);
            }

            if (document.getElementById('bdDlTeaseHome')) {
                $('#search_box').animate({ height: 151 }, 0);
                $('#bdDlTeaseHome').animate({ height: 65 }, 'fast');
            }
        }
    }
}
function enableBD() {
    var url = 'http://www.yontoo.com/enableapps.aspx?clientId=' + getInstallId() + '&appId=buzzdock&enable=true';
    var enableFrame = document.createElement('iframe');
    enableFrame.src = url;
    enableFrame.style.width = '1px';
    enableFrame.style.height = '1px';
    document.body.appendChild(enableFrame);
    showEnabled();
    _gaq.push(['_trackEvent', 'enableClicked', 'clicked']);
}
function showEnabled() {
    btn = createBtn('enabled');
    $('#freedownload_btn').replaceWith(createBtn('enabled'));
    $('#sc').fadeOut('fast');
    _gaq.push(['_trackEvent', 'enabledDisplayed', 'clicked']);
}

$(document).ready(function () {

    setupDownloadEnable();

    /* Preload background images on the index page */
    var randomImages = ['bg_img01', 'bg_img02', 'bg_img03', 'bg_img04', 'bg_img05', 'bg_img06', 'bg_img07', 'bg_img08', 'bg_img09', 'bg_img10'];
    var rndNum = Math.floor(Math.random() * randomImages.length);
    $("#img_bg").css({ background: "url(./images/" + randomImages[rndNum] + ".jpg) no-repeat" });

    /* Set the page ID attribute to body and disable current footer links */
    var pageId = location.pathname.split('/')[1];
    (pageId == '') ? $('body').attr('id', 'index') : $('body').attr('id', pageId);

   

    /* Add supported browser and supported websites to the sidebar of the About us and Help pages */
    $('#supportedSites').load('/inc/supportedWebsites.htm');
    $('#supportedBrowsers').load('/inc/supportedBrowsers.htm');

    /* Add the shared footer to #footer element, remove the current items anchor, and remove the border-right css style 
    * for browsers that don't support the :last-child pseudo selector */
    $('#footer').load('/inc/footer.htm', function () {
        $('a[href="/' + pageId + '"] span').unwrap('span');
        $('#footer_nav li:last-child').css('border', 'none');
    });

    /* If there is togglable content, set the controllers */
    if ($('.trigger').size() != 0) {

        $('.toggle_container').hide();
        $('.trigger').click(function (e) {
            e.preventDefault();
            $(this).next('.toggle_container').slideToggle();
        });
    }
    /* Allow the Buzzdock to be disabled from the Disable page */
    $('#disableBuzzdockButton').click(function () {
        $('#disableWrapper iframe').remove();
        $('#disableWrapper').append('<iframe src="http://www.yontoo.com/enableApps.aspx?appId=Buzzdock&enable=false&clientId=' + getInstallId() + '"></iframe>').children('iframe').hide();
        if ($('#disableWrapper').children('iframe').size() > 0) {
            $('#disableWrapper').html('<div class="message"><span>Buzzdock has been disabled.</span></div><p>At Buzzdock we strive to produce meaningful applications that enhance a users experience on the web and we value your input. Please take a moment to offer your <a href="../contact.aspx?disabled=yes">feedback</a> on our latest version of Buzzdock application and let us know how we can make it better.</p><p>Thanks for you help and thank you for trying the Buzzdock!');
        } else {
            $('#disableWrapper').html('<div class="message"><p>There was a problem completing you request. Please notify our site admin via the <a href="../contact.aspx?disabled=yes">Contact Us</a> form. Thanks you, and sorry for the inconvenience.</p></div>');
        }
    });
});
