/* 
Author:Alex Persegona
Version:1.0
Date:4-28-2011


/*----------------- Main Menu -----------------*/

$(function() {
    
var trg = $('#nav_1155594 li:has(ul)');
trg.hover(
      function(){ // Mouse Over
          $(this).addClass('selected');
          
      },
      function(){ // Mouse Out
          $(this).removeClass('selected');
      }
);
});

/*----------------- ROLL-OVER --------------------*/
/**
 *  ROLL-OVER - jquery.popupt
 *  (c) 2008 Semooh (http://semooh.jp/)
 *
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 **/
(function($){
	$.fn.extend({
		imghover: function(opt){
			return this.each(function() {
        opt = $.extend({
            prefix: '',
            suffix: '_o',
            src: '',
            btnOnly: true,
            fade: false,
            fadeSpeed: 500
          }, opt || {});

        var node = $(this);
				if(!node.is('img')&&!node.is(':image')){
          var sel = 'img,:image';
          if (opt.btnOnly) sel = 'a '+sel;
          node.find(sel).imghover(opt);
          return;
        }

        var orgImg = node.attr('src');

        var hoverImg;
        if(opt.src){
          hoverImg = opt.src;
        }else{
          hoverImg = orgImg;
          if(opt.prefix){
            var pos = hoverImg.lastIndexOf('/');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos-1)+opt.prefix+hoverImg.substr(pos-1);
            }else{
              hoverImg = opt.prefix+hoverImg;
            }
          }
          if(opt.suffix){
            var pos = hoverImg.lastIndexOf('.');
            if(pos>0){
              hoverImg = hoverImg.substr(0,pos)+opt.suffix+hoverImg.substr(pos);
            }else{
              hoverImg = hoverImg+opt.suffix;
            }
          }
        }

        if(opt.fade){
          var offset = node.offset();
          var hover = node.clone(true);
          hover.attr('src', hoverImg);
          hover.css({
            position: 'absolute',
            left: offset.left,
            top: offset.top,
            zIndex: 1000
          }).hide().insertAfter(node);
          node.mouseover(
            function(){
              var offset=node.offset();
              hover.css({left: offset.left, top: offset.top});
              hover.fadeIn(opt.fadeSpeed);
              node.fadeOut(opt.fadeSpeed,function(){node.show()});
            }
          );
          hover.mouseout(
            function(){
              node.fadeIn(opt.fadeSpeed);
              hover.fadeOut(opt.fadeSpeed);
            }
          );
        }else{
          node.hover(
            function(){node.attr('src', hoverImg)},
            function(){node.attr('src', orgImg)}
          );
        }
			});
		}
	});
})(jQuery);

/*-----------------  Coda Style Tool Tip   --------------------*/

$(function () {
  $('.bubbleInfo').each(function () {
    // options
    var distance = 40;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: -130,
          left: -33,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});

// =================================================
// = Remove 'Web App Item' from search results     =
// =================================================


jQuery(document).ready(function() {
$('#search-1763 li')
        .andSelf()
        .contents()
        .filter(function(){
            return this.nodeType === 3;
        })
        .filter(function(){
            // Only match when contains '| Web App Item' anywhere in the text
            return this.nodeValue.indexOf('| Web App Item') != -1; 
			
        })
        .each(function(){
            $(this).remove();
        });

});

// ========================
// = Calendar Alert Links =
// ========================

jQuery(document).ready(function() {       
                 
  
  $('table.module-calendar a.event').each(function(index) {
      
   var href = $(this).attr('href');
   $(this).parent().parent().parent().children('span').wrapInner("<a href='" + href + "'></a>");
      });                          
 });

// ===========================
// = Shorten links in footer =
// ===========================

jQuery(document).ready(function() 
{
 $('.blogsitesummary a').each(function()
 {
    var x = $(this);
	if( x.text().length > 37 ) 
	{
		x.text(x.text().substring(0,40)+"...");
	} 
	else
	{ 
	   x.text(x.text().substring(0,40));
	}
 });
});

// ============================
// = Remove Profile Sections  =
// ============================
 jQuery(document).ready(function($) {     
 
   $('.profile_section p').each(function(index) {
     if($(this).text().length < 5)  {
          
			console.log($(this).innerHtml());
			 $(this).parent().remove();  
      }       
 
   });
}); 

// ==========================
// = TEST SHOPPING REDIRECT =
// ==========================    

 
 jQuery(document).ready(function($) {    
     $('#catshopclear img').click(function(e) {
      //window.setTimeout('location.reload()', 10);
              
        window.location.replace("/membership/products.html");  
     });	   

	           
if($('a.cartLink').text()== 'Shopping cart is empty. Continue Shopping.') {   
        window.location.replace("/membership/products.html");  
     };
 });



// =========================
// = Get current page name =
// ========================= 

jQuery(document).ready(function($) {  
		
	var url = window.location.pathname;
	var url = url.substring(url.lastIndexOf('/') + 1);
    url = url.toLowerCase()                               
         
	
	if (url === "membership-faq.html"){
		     
		$('body').addClass('hide_faq_buttons');
		
	}

});
  

