﻿// Feedback
var uvOptions = {};
          (function() {
            var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
            uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/BHDwTGwG7VxQihKB3zyzXw.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
          })();
   
        (function($) {
            var cache = [];
            // Arguments are image paths relative to the current page.
            $.preLoadImages = function() {
                var args_len = arguments.length;
                for (var i = args_len; i--; ) {
                    var cacheImage = document.createElement('img');
                    cacheImage.src = arguments[i];
                    cache.push(cacheImage);
                }
            }
        })(jQuery)

        jQuery.preLoadImages("/themes/Tomkin/Content/Images/header-background.jpg",
        "/themes/Tomkin/Content/Images/tomkin.png",
        "/themes/Tomkin/content/images/sprite-master-page.png",
        "/themes/Tomkin/content/images/sprite-horizontal.gif",
        "/themes/Tomkin/content/images/sprite-vertical.gif",
        "/themes/Tomkin/Content/Images/sprite-home-page.gif",
        "/themes/Tomkin/content/images/sprite-common.png",
        "/themes/Tomkin/content/images/menu-arrow.jpg",
        "/themes/Tomkin/content/images/left-navigation-top.jpg",
        "/themes/Tomkin/content/images/left-navigation-bottom.jpg"
       );

// Menu
jQuery(document).ready(function() {
    $('#main-menu > ul > li > ol').each(function() {
        var olid = '#' + this.id;
        jQuery(olid).columnizeList({ cols: 4, constrainWidth: 0 });
    });
    if (getInternetExplorerVersion() == 7) {
        FixLeftPositionOfDropMenuForIE7();
    }
    else {
        FixLeftPositionOfDropMenu();
    }
    //set active class for market group links
    SetMarketGroupLinks();
});
function FixLeftPositionOfDropMenu() {
    var menu_left = $('#main-menu').offset().left;
    $('#main-menu > ul > li').each(function() {
        var menu_li_id = '#' + this.id;
        var li_left = $(menu_li_id).offset().left;
        $(menu_li_id + ">ul").offset({ left: menu_left - li_left + 1 });
    });
}

function FixLeftPositionOfDropMenuForIE7() {
    var menu_left = $('#main-menu').offset().left+1;
    $('#main-menu > ul > li').each(function() {
        var menu_li_id = '#' + this.id;
        var li_left = $(menu_li_id).offset().left;
        //$(menu_li_id + ">ul").offset({ left: li_left });
        $(menu_li_id + ">ul").offset({ left: menu_left });
    });
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
        
// Market Group
function SetMarketGroup(marketGroup) {
    var ispersistentcookie = $.cookie("ispersistentcookie");
    if (ispersistentcookie != null && ispersistentcookie.length && ispersistentcookie == 'true') {
        //persistent cookie
        $.cookie("marketgroup", marketGroup, { expires: 300, path: '/' }); //set or update cookie
    }
    else {
        //non persistent cookie
        $.cookie("marketgroup", marketGroup, { path: '/' }); //set or update cookie
    }
    location.reload(true);
}

function SetMarketGroupLinks() {
    var marketGroup = $.cookie("marketgroup");
    //Need to check null for IE and safari
    if (marketGroup == null || (marketGroup.length && marketGroup == 'industry')) {
        $('#MarketGroupTheHome').removeClass('active');
        $('#MarketGroupIndustry').addClass('active');
    }
    else {
        $('#MarketGroupTheHome').addClass('active');
        $('#MarketGroupIndustry').removeClass('active');
    }
    Cufon.set('fontFamily', 'WhitneySemiBold').refresh('#product-market-group');
}

// Subscribe to newsletter 
function SubscriptionFocus(Subscription) {
    if (Subscription.value == 'Type Email Address') {
        Subscription.value = '';
        $('.email-subscription > .textbox').addClass('subscription-black');
    }
}

function SubscriptionBlur(Subscription) {
    if (Subscription.value == '') {
        Subscription.value = 'Type Email Address';
        $('.email-subscription > .textbox').removeClass('subscription-black');
    }
}


//Narrow search box
function SetSearchType(searchtype) {
    $("#searchType").val(searchtype);
}

function keywordsearchboxfocus(keywordsearchbox) {
    if (keywordsearchbox.value == 'Keyword')
        keywordsearchbox.value = '';
}

function keywordsearchboxblur(keywordsearchbox) {
    if (keywordsearchbox.value == '')
        keywordsearchbox.value = 'Keyword';
}

//Narrow result toggle
$("#narrow-result-corner > #search-accordion > h3:not(.disable)").live('click', function() {
    $(this).next('div:first').toggle();
    $(this).toggleClass("active");
    $(this).toggleClass("inactive");
    Cufon.set('fontFamily', 'WhitneyMedium').refresh('#search-accordion h3.inactive')
    //Cufon.set('fontFamily', 'WhitneyMedium').refresh('#search-accordion h3.inactive', { hover: { fontWeight: 350} })
    Cufon.set('fontFamily', 'WhitneySemiBold').refresh('#search-accordion h3.active')
    //Cufon.set('fontFamily', 'WhitneyBook').refresh('#search-accordion h3', { fontWeight: 325 });
});

$("#keyword-search > div.button > span > input:button").live('click', function() {
    $("#keyword-search > div > input:text").each(function() {
        $(this).val('');
    });
    $(this).parents('form').submit();
});

$("#search-accordion > div:not('#keyword-search') > div.button > span > input:button").live('click', function() {
    $(this).parents('.button').siblings().find('input:checkbox').each(function() {
        $(this).removeAttr('checked');
    });
    $(this).parents('form').submit();
});

$("#narrow-result-corner > div.button-all > span > input:button").live('click', function() {
    $("#keyword-search > div > input:text").each(function() {
        $(this).val('');
    });
    $("#search-accordion >.checkbox-div > div > input:checkbox").each(function() {
        $(this).removeAttr('checked');
    });
    $(this).parents('form').submit();
});

//Narrow search button hover
function initializenarrowresultbuttons() {
    $(".button > span > .reset").hover(function() {
        $(this).parents(".button").addClass("reset-hover");
    }, function() { $(this).parents(".button").removeClass("reset-hover"); }
    );

    $(".button > span > .submit").hover(function() {
        $(this).parents(".button").addClass("submit-hover");
    }, function() { $(this).parents(".button").removeClass("submit-hover"); }
    );

    $("#keyword-search > .keyword-search-div > .keyword-search-button > .exclude").click(function() {
        $(this).parent().removeClass("include");
        $(this).parent().addClass("exclude");
        $(this).parent().prev(":hidden").val("false");
    }
    );

    $("#keyword-search > .keyword-search-div > .keyword-search-button > .include").click(function() {
        $(this).parent().removeClass("exclude");
        $(this).parent().addClass("include");
        $(this).parent().prev(":hidden").val("true");
    }
    );
}

function searchboxfocus(searchbox) {
    if (searchbox.value == 'Search')
        searchbox.value = '';
}

function searchboxblur(searchbox) {
    if (searchbox.value == '')
        searchbox.value = 'Search';
}        

// Facebook
(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));

