﻿var header = {
    init: function () {
        this.run();
    },
    run: function () {
        // Logo Hover
        $('#logo, .copyright h3').hover(
            function () {
                $(this).stop().animate({ 'opacity': '.5' }, 200);
            },
            function () {
                $(this).stop().animate({ 'opacity': '1' }, 200);
            }
        );
    }
};
var search = {
    searchBox: Object,
    label: Object,
    init: function () {
        this.searchBox = $('#search-box');
        this.label = $('#search label');
        this.run();
    },
    run: function () {

        // Global Check
        if (this.searchBox.attr('value') !== '') {
            search.label.css({ opacity: '0' });
        }
        
        // Search Functions
        this.searchBox.focus(function () {
            if ($(this).attr('value') === '' || $(this).attr('value') === 'Enter Keyword(s)') {
                search.label.animate({ opacity: '.2' }, 200);
            }
        });
        this.searchBox.blur(function () {
            if ($(this).attr('value') === '') {
                search.label.animate({ opacity: '1' }, 200);
            } else {
                search.label.animate({ opacity: '0' }, 0);
            }
        });
        this.searchBox.keydown(function () {
            search.label.css({ opacity: '0' });
        });

        // Label Functions
        this.label.live('click', function () {
            if (search.searchBox.attr('value') === '') {
                $(this).css({ opacity: '.2' });
                search.searchBox.focus();
            } else {
                $(this).css({ opacity: '0' });
                search.searchBox.focus();
            }
        });

        // IE 6 + 7 Overrides
        if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
            this.label.hide();
            this.searchBox.attr('value', 'Enter Keyword(s)');
            this.searchBox.focus(function () {
                if ($(this).attr('value') === 'Enter Keyword(s)') {
                    $(this).attr('value', '');
                }
            });
            this.searchBox.blur(function () {
                if ($(this).attr('value') === '') {
                    $(this).attr('value', 'Enter Keyword(s)');
                }
            });
        }
    }
};
var dropdowns = {
    sub: Object,
    listItems: Object,
    lastItem: Object,
    init: function () {
        this.sub = $('.sub');
        this.listItems = $('#nav li');
        this.lastItem = $('#nav li li:last-child');
        this.run();
    },
    run: function () {
        this.sub.hide();
        this.listItems.hover(
            function () {
                $(this).children('.sub').slideDown('fast');
            }, function () {
                $(this).children('.sub').hide();
            });
        this.sub.hover(
            function () {
                $(this).siblings('a').addClass('nav-selected');
            },
            function () {
                $(this).siblings('a').removeClass('nav-selected');
            });

        this.lastItem.css({ 'border': 'none' });
    }
};
var sharetips = {
    link: Object,
    print: Object,
    init: function () {
        this.link = $('a.tip');
        this.print = $('.sprint');
        this.run();
    },
    run: function () {
        // Tooltips
        this.link.mouseover(function () {
            var tooltext = $(this).attr('title');
            $(this).attr('title', '');

            $(this).append('<div class="tooltip">' + tooltext + '<img class="tip-arrow" src="/Content/images/css/tip-arrow.gif" /></div>');
            $('.tooltip').css({ 'display': 'block', 'opacity': '0' });
            $('.tooltip').animate({ marginTop: '-10px', opacity: 1 }, 300);

        }).mouseout(function () {
            $(this).attr('title', $('.tooltip').text());
            $('div.tooltip').children('img.tip-arrow').remove();
            $(this).children('div.tooltip').remove();

        });

        // Print
        this.print.click(function () { window.print(); });
    }
};
var tabs = {
    init: function () {
        $(".tab-content").hide();
        $(".tabs li:first").addClass("active").show();
        $(".tab-content:first").show();

        $(".tabs li").click(function () {
            if ($(this).hasClass('active')) {
                return false;
            } else {
                $(".tabs li").removeClass("active");
                $(this).addClass("active");
                $(".tab-content").hide();
                var activeTab = $(this).find("a").attr("href");
                $(activeTab).fadeIn(1000);
                return false;
            }
        });
        $('#tab1 li').hover(
        function () {
            $(this).addClass('hover');
            $(this).children('a').addClass('hover');
        },
        function () {
            $(this).removeClass('hover');
            $(this).children('a').removeClass('hover');
        });
    }
};
var contact = {
    init: function () {
        $('.view-map').show().css({ 'opacity': '0' });
        $('.view-map').hover(function () { $(this).stop().animate({ 'opacity': '.4' }, 400); }, function () { $(this).stop().animate({ 'opacity': '0' }, 400); });
        $('.view-map').live('click', function () { $(this).css({ 'opacity': '0' }); });
    }
};
var sitemap = {
    init: function () {
        $('.sitemap li').addClass('first');
        $('.sitemap li ul li').removeClass('first');
    }
};
var whitepapers = {
    init: function () {
        $('.whitepaper:odd').addClass('last');
        $('.whitepaper').hover(
            function () {
                $(this).addClass('whitepaper-hover');
            },
            function () {
                $(this).removeClass('whitepaper-hover');
            });
        $('.whitepaper').click(function () {
            window.location = $(this).find("a").attr("href"); return false;
        });
    }
};
function initialize() {
    header.init();
    search.init();
    dropdowns.init();
    sharetips.init();
    tabs.init();
    contact.init();
    sitemap.init();
    whitepapers.init();
};
$(function () {
    $('html').removeClass('nojs').addClass('js');
    initialize();
});
