﻿function CufonReplace() {
	Cufon.replace('.dinot');
}

function CufonRefresh() {
	Cufon.refresh('.dinot');
}

//AddThis
var addthis_config = { "data_track_clickback": true };

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

$(document).ready(function () {

    $menuItem = $('#menu ul li');

    //MenuItem enter/leave.
    $menuItem.mouseenter(function () {
        $(this).find('.dinot').css('color', '#FFFFFF');
        Cufon.replace($(this).find('.dinot'));
    });

    $menuItem.mouseleave(function () {
        $(this).find('.dinot').css('color', '#00274D');
        Cufon.replace($(this).find('.dinot'));
    });

    $("#pnlAccordion").accordion({ header: '.accordionHeaderContainer',
        icons: { 'header': 'collapsed', 'headerSelected': 'expanded' },
        autoHeight: false
    });

    $('#subPageQuickLinksContainer a').click(function () {
        if ($('#isHomepage').attr('value') == "false") {
            $(this).attr('href', '#' + $(this).index('#subPageQuickLinksContainer a cufontext'));
            $("#pnlAccordion").accordion("activate", $(this).index('#subPageQuickLinksContainer a'));
        }
    });

    //Cycle
    var currentItem = 0;

    $('#brandBoxItems').cycle({
        pager: '#brandBoxPager',
        pagerEvent: 'mouseover',
        pauseOnPagerHover: true,
        pagerAnchorBuilder: function (idx, slide) {
            var img = $(slide).find('img')[0];
            var length = img.src.length;
            var ext = img.src.substring(length - 4);
            return '<div class="brandBoxPagerItem"><img src=' + img.src.substring(0, length - 4) + '_Thumb' + ext + ' class="brandBoxThumb" /><a style="font-size:10px;" href="' + slide.href + '" >' + img.alt + '</a></div>';
        }
    });

    if ($('#isHomepage').attr('value') == 'true') {
        $('#lblContent').css('height', '150px');

        var brandbox = gup('id');
        if (brandbox) {
            $('#lblContent div').hide();
            $($('#lblContent div')[brandbox]).show();
        }

        $('#brandBoxPager > .brandBoxPagerItem').click(function () {
            $('#brandBoxPager a')[0].href = '';
            var pagerItemIndex = $(this).index('#brandBoxPager > .brandBoxPagerItem');
            $('#lblContent div').hide();
            $($('#lblContent div')[pagerItemIndex + 1]).show();
        });
    }
    else {
        $('#brandBoxPager a').click(function () {
            var pagerItemIndex = $(this).index('#brandBoxPager a');
            //window.location = $(this)[0].href + '?id=' + pagerItemIndex;
            window.location = '/Ifective.aspx?id=' + pagerItemIndex;
        });
    }

    //Get the arrow and menuItems
    $arrow = $('#menuArrow');
    var currentMenuItemClass = $('#hiddenPageID')[0].value;
    $currentMenuItem = $('.menuItem.' + currentMenuItemClass);

    $currentMenuItem.addClass('menuItemSelected menuItemClicked');

    CufonReplace();

    //set the arrow location.
    $arrow.css({ left: ($currentMenuItem.offset().left + ($currentMenuItem.width() / 2) - 11) + 'px' });
});

//Switches the text in the summary panel of the accordion control on mouseover.
function switchSubPageSummary(panelID, summaryID, summary, pageID, readMoreID) {
	var panel = $("#" + panelID);
	var lblSummary = $("#" + summaryID);
	lblSummary[0].innerHTML = summary;

	var readMoreButton = $("#" + readMoreID);
    var url = $(panel).find("a").attr("href");
    $(readMoreButton).attr("href", url);

	$('.subSubPageLinkContainer').removeClass('subSubPageLinkSelected');
	panel.addClass('subSubPageLinkSelected');
}

function clearTextBox(textBox) {
    textBox.value = "";
}

function openCitrix() 
{
    window.open("https://broker.gotoassist.com/h/citrixassist?Portal=citrixassist&Target=ds%2FqueryPost.flow&" +
	    "Template=ds%2FphoneModeRedemption.tmpl&JavaScript=true&Form=csaSmartBox&Name_Full=" + document.getElementById("Remote support_txtName").value +
	    "&CompanyName=" + document.getElementById("Remote support_txtCompanyName").value + "&Question=" + document.getElementById("Remote support_txtQuestion").value);
}
