﻿/*
 * Copyright (C) digitalbucket.net, LLC. All Rights Reserved
 * 
 * For more details please vist http://www.digitalbucket.net
 *
 */

$(function () {

    // home page feature navigator through tabs
	var tabContainers = $('div.tabs div.tabsContenet > div');
	$('div.tabs ul.tabsNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).fadeIn();
		$('div.tabs ul.tabsNavigation li').removeClass('selected');
		$(this).parent().addClass('selected');
		return false;
	}).filter(':first').click();
	
	// testimonials control automatic navigation
    var testemIndex = 0;
    var testemList = $('div.testimonials li');	
    $('div.testimonials > a').click(function() {
        if($(this).hasClass('testimNext'))
            testemIndex = (testemIndex < testemList.length - 1) ? testemIndex + 1 : 0;
        else
            testemIndex = (testemIndex < 1) ? testemList.length - 1 : testemIndex - 1;
        testemList.hide().filter(':eq(' + testemIndex + ')').fadeIn();
        return false;
    });	
    
    // tooltips used in pricing page
    $('.bubble-tip').each(function() {
        var time = 250;
        var hideDelay = 500;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.bubble-tip-trigger', this);
        var info = $('.bubble-tip-popup', this);
        
        info.css('display', 'block');
    
        var popup = $('<div class="bubble-tip-wrapper"><div class="bubble-tip-handle"></div></div>');
        popup.insertBefore(info);
        popup.prepend(info);
        
        var left = -(popup.width() / 2) + (trigger.width() / 2);
        var bottom = (trigger.height() / 2);
        var distance = bottom;
        
        popup.css({
            display: 'none',
            opacity: 0
        });
        
        $([trigger.get(0), popup.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                popup.css({
                    bottom: bottom,
                    left: left,
                    display: 'block'
                }).animate({
                    bottom: '+=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                popup.animate({
                    bottom: '+=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    popup.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });               
    });
});