﻿jQuery(document).ready(function($) {

    // IF JAVASCRIPT ENABLED
    $('body').addClass('js');

    // PRIMARY MENU DROPDOWNS
    $('#primary-nav li li').has('ul').addClass('hassubmenu');

    //bug to address empty subnavs in IE (v8 or less)
    //names in code below will need to change if link labels are ever modified
    if ($.browser.msie && $.browser.version.substr(0, 1) < 9) {
        $('li.hassubmenu li.hassubmenu').mouseenter(function() {
            $('li.hassubmenu li.hassubmenu ul').css({ 'visibility': 'hidden' });
            $(this).find("ul").css({ 'visibility': 'visible' });
        });
        $('.whatisbrainshark,.benefitsnuses,.productsnfeatures,.services,.ideasblog').mouseenter(function() {
            $('li.hassubmenu li.hassubmenu ul').css({ 'visibility': 'hidden' });
        });
       
    }
    //end IE patch	

    // HOVER/SELECTOR FOR IE6
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $('#primary-nav li').mouseover(function() {
            $(this).addClass('hover');
        });

        $('#primary-nav li').mouseout(function() {
            $(this).removeClass('hover');
        });

        var secondarynavExtraHeight = (560 - $('#secondary-nav').height());
        $('#secondary-nav').css('margin-bottom', secondarynavExtraHeight);
    };

    // SECONDARY MENU ROOLOVER FIXES	
    $('#secondary-nav ul li a.selected').parents('li').addClass('addborder');
    $('#secondary-nav ul li').has('ul').addClass('withsubmenu');

    // CLEAR SEARCH BOX INPUT
    $('#searchinput')
		.val('Search')
		.focus(function() {
		    if ($(this).val() == 'Search') {
		        $(this).val('');
		    }
		})
		.blur(function() {
		    if ($(this).val() == '') {
		        $(this).val('Search');
		    }
		});

    // FOOTER PRIMARY MOVES/TABS
    $('#footer-primary').prependTo('#footer');

    $('<p><a id="footer-read-more-show">Read More &raquo;</a></p>').insertBefore('#footer-read-more-content');
    $('<p><a id="footer-read-more-hide">Collapse &#94;</a></p>').appendTo('#footer-read-more-content');

    $('.footer-tab-control').idTabs();
    $('#footer-read-more-content').hide();
    $('#footer-read-more-show').click(function() {
        $('#footer-read-more-content').toggle();
    });
    $('#footer-read-more-hide').click(function() {
        $('#footer-read-more-content').hide();
    });

    // HOMEPAGE HERO
    $('<div id="home-callout-nav"><a class="prev">prev</a><a class="next">next</a></div>').insertAfter('#home-callout');

    $('#home-callout').jCarouselLite({
        btnNext: '#home-callout-nav .next',
        btnPrev: '#home-callout-nav .prev',
        visible: 4,
        circular: false,
        auto: 3000,
        speed: 600,
        pause: false,
        easing: 'linear'
    });

    $('#home-callout-nav .next').click(function() {
        $('#home-callout').trigger('pauseCarousel');
    });

    $('#home-callout-nav .prev').click(function() {
        $('#home-callout').trigger('pauseCarousel');
    });

    // HOMEPAGE TWITTER
    $('<div id="home-twitter-nav"><a class="prev">prev</a><a class="next">next</a></div>').insertAfter('#home-twitter');

    $('#home-twitter').jCarouselLite({
        btnNext: '#home-twitter-nav .next',
        btnPrev: '#home-twitter-nav .prev',
        vertical: true,
        visible: 1,
        auto: 5000
    });

    // PRI/SEC HEIGHTS & W/N LINE
    if ($('#primary-content').height() < $('#secondary-content').height()) {
        $('#primary-content').addClass('primary-content-nline');
        $('#secondary-content').addClass('secondary-content-wline');
    };

    // TOOLTIPS ENTERPRISE
    $('<span class="tt-icon-ent"><img src="/media/img/icon_ent_small_dark.png" /></span>').appendTo('.tooltip-ent');

    $('<span class="tt-popup-ent"><span class="text">This feature is<br /> available in our<br /> Enterprise Editions.</span><span class="link"><a href="#">See all Features</a></span></span>').appendTo('.tt-icon-ent');

    $('.tt-icon-ent').mouseover(function() { $('.tt-popup-ent', this).addClass('tt-popup-show'); });
    $('.tt-icon-ent').mouseout(function() { $('.tt-popup-ent', this).removeClass('tt-popup-show'); });

    // TOOLTIPS INDIVIDUALS
    $('<span class="tt-icon-ind"><img src="/media/img/icon_ind_small_dark.png" /></span>').appendTo('.tooltip-ind');

    $('<span class="tt-popup-ind"><span class="text">This feature is available<br /> in our Solutions for<br /> Individuals.</span><span class="link"><a href="#">See all Features</a></span></span>').appendTo('.tt-icon-ind');

    $('.tt-icon-ind').mouseover(function() { $('.tt-popup-ind', this).addClass('tt-popup-show'); });
    $('.tt-icon-ind').mouseout(function() { $('.tt-popup-ind', this).removeClass('tt-popup-show'); });

    // ICON ONLY IND & ENT
    $('<span class="tt-icon-ind"><img src="/media/img/icon_ind_small_light.png" title="Individuals Editions" /></span>').appendTo('.icon-ind-nopop');
    $('<span class="tt-icon-ent"><img src="/media/img/icon_ent_small_light.png" title="Enterprise Editions" /></span>').appendTo('.icon-ent-nopop');

    // CALLOUT SHOW/HIDE
    $('<em class="toggle_expand_default"></em>').appendTo('.callout-show-hide h3 span');
    $('.callout-show-hide h3').click(function() {
        $('.toggle_expand_default', this).toggleClass('toggle_collapse_active');
        $(this).siblings('.content').toggle();
    });

    // CALLOUT ARCHIVE SHOW/HIDE
    $('<em class="toggle_collapse_default"></em>').appendTo('.callout-content-archive h3 span');
    $('.callout-content-archive .content').hide();
    $('.callout-content-archive h3').click(function() {
        $('.toggle_collapse_default', this).toggleClass('toggle_expand_active');
        $(this).siblings('.content').toggle();
    });

    // MYBSK CAMPARISON
    $('<em class="toggle_collapse_default"></em>').appendTo('.tb-features-content h2:not(:first) span');
    $('.tb-features-content table:not(:first)').hide();
    $('.tb-features-content h2:not(:first)').click(function() {
        $('.toggle_collapse_default', this).toggleClass('toggle_expand_active');
        $(this).next('table').toggle();
    });

    $('<em class="toggle_expand_default"></em>').appendTo('.tb-features-content h2:first span');
    $('.tb-features-content h2:first').click(function() {
        $('.toggle_expand_default', this).toggleClass('toggle_collapse_active');
        $(this).next('table').toggle();
    });

    // BSK COMPARISON (ENT SPECIAL)
    $('#tb-features-content-ent em.toggle_collapse_default').remove();
    $('#tb-features-content-ent table:not(:first)').show();
    $('<em class="toggle_expand_default"></em>').appendTo('#tb-features-content-ent h2:not(:first) span');
    $('#tb-features-content-ent h2:not(:first)').click(function() {
        $('.toggle_expand_default', this).toggleClass('toggle_collapse_active');
    });

    // NEWS ARTICLE
    $('<em class="toggle_collapse_default"></em>').appendTo('.news-article h2:not(:first) span');
    $('.news-article table:not(:first)').hide();
    $('.news-article h2:not(:first)').click(function() {
        $('.toggle_collapse_default', this).toggleClass('toggle_expand_active');
        $(this).next('table').toggle();
    });

    $('<em class="toggle_expand_default"></em>').appendTo('.news-article h2:first span');
    $('.news-article h2:first').click(function() {
        $('.toggle_expand_default', this).toggleClass('toggle_collapse_active');
        $(this).next('table').toggle();
    });

    // TOOLTIPS BLOG IDEA BSK USER
    $('<span class="tt-icon-bskuser"><img src="/media/img/icon_idea_bskuser.png" /></span>').prependTo('.toolip-bskuser');

    $('<span class="tt-popup-bskuser"><span class="text">This idea was submitted by<br /> a Brainshark user.</span><span class="link"><a href="#">See more of Your Ideas</a></span></span>').appendTo('.tt-icon-bskuser');

    $('.tt-icon-bskuser').mouseover(function() { $('.tt-popup-bskuser', this).addClass('tt-popup-show'); });
    $('.tt-icon-bskuser').mouseout(function() { $('.tt-popup-bskuser', this).removeClass('tt-popup-show'); });

    // TOOLTIPS BLOG IDEA BSK SELF
    $('<span class="tt-icon-bskself"><img src="/media/img/icon_idea_bskself.png" /></span>').prependTo('.toolip-bskself');

    $('<span class="tt-popup-bskself"><span class="text">This idea was submitted by<br /> Brainshark.</span><span class="link"><a href="#">See more of Our Ideas</a></span></span>').appendTo('.tt-icon-bskself');

    $('.tt-icon-bskself').mouseover(function() { $('.tt-popup-bskself', this).addClass('tt-popup-show'); });
    $('.tt-icon-bskself').mouseout(function() { $('.tt-popup-bskself', this).removeClass('tt-popup-show'); });

    //MOBILE DEVICES DETECTION
    var deviceIpad = "ipad";
    var deviceIphone = "iphone";
    var deviceIpod = "ipod";
    var deviceAndroid = "android";
    var engineWebKit = "webkit";
    var uagent = "";
    var isMobileIpad = false;
    var isIphone = false;
    var isAndroidPhone = false;

    if (navigator && navigator.userAgent)
        uagent = navigator.userAgent.toLowerCase();

    if (uagent.search(deviceIpad) > -1 && uagent.search(engineWebKit) > -1)
        isMobileIpad = true;

    if (uagent.search(deviceIphone) > -1 && !isMobileIpad && uagent.search(deviceIpod) < 1) {
        isIphone = true;
    }

    if (uagent.search(deviceAndroid) > -1)
        isAndroidPhone = true;

    if (isMobileIpad) {
        //replace links with app store link
        $('a[class="iPadLink"]').each(function() {
            $(this).attr("href", "http://itunes.apple.com/us/app/slideshark-powerpoint-presentations/id471369684?ls=1&mt=8");
        });
    }

    if (isIphone || isAndroidPhone) {
        //replace video links for mobile devices
        $('a[class="lightwindow"]').each(function() {
            $(this).removeClass("lightwindow");
        });
    }

    $('.callout-contnet-scroll').tinyscrollbar({ sizethumb: 16 });
});

//Functionality below for video search template
var current_faq, current_tab;

var $js = jQuery.noConflict();
$js(document).ready(function() {

    //a.faq_header
    $js(".faq_header").click(function(e) {
        temp_id = $js(this).attr("id");
        e.preventDefault();
        $js(this).blur();

        $js(".faq_open").removeClass().addClass("faq_header");

        if (current_faq != "") {
            $js("#" + current_faq).slideUp();
        }
        if (current_faq != (temp_id + "_content")) {
            current_faq = temp_id + "_content";
            $js(this).removeClass().addClass("faq_open");

            $js("#" + current_faq).slideDown();
        } else {
            current_faq = "";
        }
    });

    $js(".tab_header").click(function(e) {
        temp_id = $js(this).attr("id");
        e.preventDefault();
        $js(this).blur();

        $js(".tab_open").removeClass().addClass("tab_header");

        if (current_tab != "") {
            $js("#" + current_tab).slideUp();
        }

        if (current_tab != (temp_id + "_content")) {
            current_tab = temp_id + "_content";
            $js(this).removeClass().addClass("tab_open");

            $js("#" + current_tab).slideDown();
        } else {
            current_tab = "";
        }
    });
});
