﻿
//FAQ toggle
var FaqToggleClass = function() {
    var o = this;
    this.sToggleCssClass = 'active';
    
    this.init = function() {
        $('dt a').click(function(){ o.toggleFaq(this); return false;});

        if (document.location.hash != '') {
            o.toggleFaq($('#'+document.location.hash.substring(1))[0]);
            document.location.href = document.location;
        }
    }
    
    this.toggleFaq = function(link) {
        $(link).parent().parent().toggleClass(o.sToggleCssClass);
    }
}

//Bird's Nest Tooltip
var ToolTipClass = function() {
    var o = this;
    this.toolTipText;
    this.toolTipId = 'tooltip';
    this.div = function() { return document.createElement('DIV'); }
    
    this.init = function(link) {
        var lnk = $(link);
        this.toolTipText = lnk.attr('title');
        lnk.removeAttr('title');
        lnk.alt = ''; // also remove alt attribute to prevent default tooltip in IE
        lnk.append($(new this.div()).attr('id', this.toolTipId).append(this.toolTipText));
        
        lnk.mouseover(function(){ o.toggle(this); });
        lnk.mouseout(function(){ o.toggle(this); });
        lnk.click(function(){ return false; });
    }

    this.toggle = function(link) {
        $(link).find('#'+this.toolTipId).toggle();
    }
}

var ProductFinderClass = function() {
    var o = this;

    this.init = function() {
        $('.product-finder .product-button a, .product-finder .product-list .btn-close').click(function() { o.toggleProductFinder(); return false; });
    }
    
    this.toggleProductFinder = function() {
        scj.omniture.trackLink({channel: 'product', linkName: 'product_quick_finder', linkType: 'o'});
        $('.product-list').toggle();
        $('.touts-wrapper .tout').toggleClass('vis-hidden');
    }
}

var ProductsToggleClass = function() {
    var o = this;
    this.sToggleCssClass = 'collapse';
    
    this.init = function() {
        $('div.toggler').click(function(){ o.toggleProducts(this); return false; });
    }
    
    this.toggleProducts = function(toggler) {
        $(toggler).parent().toggleClass(o.sToggleCssClass);
    }
}

var ProductsTabsClass = function() {
    var o = this;
    this.sActiveClass = 'active'
    this.sTabSelector = '.product-page .tabs-wrapper div a';
    this.sContentSelector = '.product-page .product-info .tab-content .panel'
    this.sTabContentSelector = '.product-page .product-info .tab-content .';
    this.sDemoFlashPlayerSelector = '.product-page .product-info .tab-content #DemoSwf';
    this.sPauseVideo = 'stop video';
    
    this.init = function() {
        $(o.sTabSelector).click(function(){ o.toggleTab(this); return false; });
    }
    
    this.toggleTab = function(link) {
        var lnk = $(link);
        
        if (!lnk.hasClass(o.sActiveClass)) {
            $(o.sTabSelector).parent().removeClass(o.sActiveClass);
            lnk.parent().addClass(o.sActiveClass);
            
            $(o.sContentSelector).removeClass(o.sActiveClass);
            $(o.sTabContentSelector + lnk.parent().attr('id')).addClass(o.sActiveClass);
            
            if ($(o.sDemoFlashPlayerSelector)[0] && typeof $(o.sDemoFlashPlayerSelector)[0].sendCallToFlash != 'undefined') {
                $(o.sDemoFlashPlayerSelector)[0].sendCallToFlash(o.sPauseVideo);
            }
        }
    }
}

var GetMarthaModalClass = function() {
    var o = this;
    this.sModalId = '#martha-modal';
    this.sModalTrigger = '.tout.martha-windows-video';
    this.sDemoFlashPlayerSelector = '.product-page .product-info .tab-content #DemoSwf';
    
    this.init = function() {
        $(o.sModalTrigger).click(function(){ o.getModal(); });
    }
    
    this.getModal = function() {
        $.ajax({
            url: '/async/async.ashx',
            type: 'POST',
            data: 'getControl=MarthaWindowsDemoOverlay',
            error: function(){}, //Don't do anything
            success: function(response){
                if(isNaN(parseInt(response))) { $('body').append(response); o.attachEvents(); } //Html = success
            }
        });
    }
    
    this.attachEvents = function() {
        $(o.sModalId).jqm({ overlay:90, onHide:o.closeModal }).jqmShow();
        if ($(o.sDemoFlashPlayerSelector)[0] && typeof $(o.sDemoFlashPlayerSelector)[0].sendCallToFlash != 'undefined') {
            $(o.sDemoFlashPlayerSelector)[0].sendCallToFlash('stop video');
        }
    }
    
    this.closeModal = function(hash) {
        hash.o.remove();
        hash.w.empty();
        hash.w.remove();
    }
}

function getQueryString(key, default_) {

    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

$(document).ready(function () {

    $("a[href^='http']").each(function () {
        if (this.href.indexOf(location.hostname) == -1 && this.href.indexOf("Windex.com") == -1) {
            $(this).attr('target', '_blank');
        }
    });

    $('img').each(function () {
        $(this).attr({
            title: $(this).attr('alt')
        });
    });

    $('.currentYear').html((new Date()).getFullYear());

    var urlName = window.location.pathname;
    urlName = urlName.toLowerCase();

    $('top_navigation ul li a').removeClass('current');
    $('top_navigation ul li a span').removeClass('current');

    if (urlName.indexOf("/products/") > 0) {
        if (urlName.indexOf("/products/pages/default.aspx") > 0) {
            $('#body').addClass('product-home');
            $('li.products a').addClass('current');
            $('li.products a span').addClass('current');
        }
        else if (urlName.indexOf("/products/pages/how-it-works.aspx") > 0) {
            $("body").addClass("outdoor");
            $('li.outdoor-shine a').addClass('current');
            $('li.outdoor-shine a span').addClass('current');
        }
        else {
            $('#body').addClass('product-page');
            $('li.products a').addClass('current');
            $('li.products a span').addClass('current');
        }

        if (urlName.indexOf("/products/pages/outdoor-all-in-one.aspx") > 0) {
            $('.tabs-wrapper div#demo').addClass("active");
            $('.tab-content div.demo').addClass("active");
            $('.product-page .product-info .tabs-wrapper div').css("width", "132px");
            $('.product-page .product-info .tabs-wrapper div a').css("width", "132px");
        }
        else {
            $('.tabs-wrapper div:first').addClass("active");
            $('.tab-content div:first').addClass("active");
        }

    }
    else if (urlName.indexOf("/solution-finder/") > 0) {

        if (urlName.indexOf("/solution-finder/pages/default.aspx") > 0) {
            $('#body').addClass('solution-home');
        }
        else {
            $('#body').addClass('solution-page');
        }
        $('li.solution-finder a').addClass('current');
        $('li.solution-finder a span').addClass('current');
    }
    else if (urlName.indexOf("/media/") > 0) {

        $('#body').addClass('staf-home');
        $('li.windex-tv a').addClass('current');
        $('li.windex-tv a span').addClass('current');

        var ToolTip = new ToolTipClass();
        ToolTip.init($('.frbc-bt-wrapper .title-bar .page-tools .bird a'));

    }
    else if (urlName.indexOf("sitemap.aspx") > 0) {
        $('#body').addClass('sitemap');
    }
    else if (urlName.indexOf("faq.aspx") > 0) {
        $('#body').addClass('faq');
        $('li.faq a').addClass('current');
        $('li.faq a span').addClass('current');
    }
    else if (urlName.indexOf("whats-new.aspx") > 0) {
        $('#body').addClass('whats-new').addClass('offers-page');
        $('li.whats-new a').addClass('current');
        $('li.whats-new a span').addClass('current');
    }
    else if (urlName.indexOf("/pages/default.aspx") > 0) {
        $('#body').addClass('home');
    }


    //    $('#tooltip').hide();

    //    $('.frbc-bt-wrapper .title-bar .page-tools .bird').live("mouseover mouseout", function (event) {
    //        if (event.type == "mouseover") {
    //            // do something on mouseover           
    //            $('.frbc-bt-wrapper .title-bar .page-tools .bird a #tooltip').css("display", "block");
    //        } else {
    //            // do something on mouseout           
    //            $('.frbc-bt-wrapper .title-bar .page-tools .bird a #tooltip').css("display", "none");
    //        }
    //    });

});
