////////////////////////////////Some set up
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

var wheelnumber = 5;
var mouseX = null;
var mouseY = null;


$(document).ready(function (){

// Clear for input fields throughout the page
function focusclear(x) {
if(x.value == x.defaultValue) {
		x.value = "";
	}
};

$(".inputclear").focus(function() {
	focusclear(this);
});

//Homepage information overlay

$("#information-button").click (function () {
	$("#information-overlay").fadeIn("slow");
});
$("#close-information").click (function () {
	$("#information-overlay").fadeOut();
});




	

//drawer toggle for /tools/tools.php -finn
	$("#e_versions ul li ul").hide();
	$("a.drawer").removeAttr('href');
	$("#e_versions ul li a.drawer").click(function(){
	  $(this).next("ul").slideToggle("slow")
	  $(this).toggleClass("active");
	});
//end drawer toggle for /tools/tools.php
	
	
// tabs on /tools/tools.php - finn

var pageHash = window.location.hash;

/*if(!pageHash){
	$("#pt_tabs li:first a").addClass("active");
	$("#all_tab_content [id$=_box]:not(:first)").hide();
}else{
	$(pageHash).addClass("active");
	$("#all_tab_content [id$=_box]").hide();
	$("#all_tab_content "+pageHash+"_box").show();
}

		//$("#pt_tabs li a").removeAttr('href');
		  //$("#pt_tabs li a").mouseover(function(){
			//  $(this).css('cursor', 'pointer');
		//  });
	$("#pt_tabs li a").click(function(e){
		e.preventDefault();
	
		var activeTab = $(this).attr("id");
		$("#pt_tabs li a").removeClass("active");
		$(this).addClass("active");
		$("#all_tab_content [id$=_box]").hide();
	 	$("#all_tab_content #"+activeTab+"_box").show();
	});
	$("a.tab_menu").click(function(){
		var activeTab = $(this).attr("rel");
		
		$("#pt_tabs li a").removeClass("active");
		$("#pt_tabs li a#"+activeTab).addClass("active");
		$("#all_tab_content [id$=_box]").hide();
	 	$("#all_tab_content #"+activeTab+"_box").show();
	});
*/
	$("[id$=_box] [id^=pt_]").removeAttr('href');
      $("[id$=_box] [id^=pt_]").mouseover(function(){
	      $(this).css('cursor', 'pointer');
      });

	$("div.pt_detail").hide();
	$("[id^=pt_]").click(function(){
	  $(this).toggleClass("active");
	  $(this).siblings("div.expand_view_printer").children(".expand_collapse").toggleClass("active");
	  $(this).siblings("div.pt_detail").slideToggle("slow");
	});
	
	$("div.expand_view_printer a.expand_collapse").removeAttr('href');
      $("div.expand_view_printer a.expand_collapse").mouseover(function(){
	      $(this).css('cursor', 'pointer');
      });
      
      
	$("div.expand_view_printer a.expand_collapse").click(function(){
	  $(this).toggleClass("active");
	  $(this).parent().siblings("[id^=pt_]").toggleClass("active");
	  $(this).parent().siblings("div.pt_detail").slideToggle("slow");
	});

// end tabs on /tools/tools.php - finn

// expand and collapse for lessons
	
	$("#page-wrap .dropdown_bar").click(function(){
		if($(this).hasClass("dropdown_active")) {
			$(this).removeClass("dropdown_active");
		} else {
			$(this).addClass("dropdown_active");
		}
		$arrowDirection = $(this).children("img").attr("src");
		if ($arrowDirection == "/images/right_arw.png") {
			$(this).children("img").attr("src","/images/down_arw.png")
		} else {
			$(this).children("img").attr("src","/images/right_arw.png");
		}	
		$(this).next(".content_wrapper").slideToggle("slow");
	});


// expand_collapse /welcome/whats-new.php - finn


	$("a.expand_collapse").removeAttr('href');
      $("a.expand_collapse").mouseover(function(){
	      $(this).css('cursor', 'pointer');
      });
	
	//$("#whats_new_box ul li a:first-child").removeAttr('href');
      $("#whats_new_box ul li span.wn-title").mouseover(function(){
	      $(this).css({'cursor':'pointer'});
      });

	$("div.wn_detail").hide();
	$("#whats_new_box ul li span.wn-title").click(function(){
	  $(this).toggleClass("active");
	  $(this).siblings("div.learn_button").children(".expand_collapse").toggleClass("active");
	  $(this).siblings("div.wn_detail").slideToggle("slow");
	});
	
	$("a.expand_collapse").click(function(){
	  $(this).toggleClass("active");
	  $(this).parent().siblings("span.wn-title").toggleClass("active");
	  $(this).parent().siblings("div.wn_detail").slideToggle("slow");
	});

// end expand_collapse /welcome/whats-new.php - finn

//uses jquery.textareaCounter.plugin.js for dashboard twitter box

			var txtoptions = {
				'maxCharacterSize': 140,
				'textFontSize': '10px',
				'textColor': '#666',
				'textAlign': 'right',
				'warningColor': '#f00',  
				'warningNumber': 10,
				'isCharacterCount': true,
				'isWordCount': false,
				'displayFormat': '#left Characters Left'
			};
			
				$("textarea#twitter_status").textareaCount(txtoptions);

//end dashboard twitter box


	
setInterval('updateTime()', 1000 );
	
/////////////////////////////Mouse overs for Mega Drop Downs
	
		$('.nav-welcome').mouseover(function(){
			$('#welcome-megadrop').show();
		});
		$('.nav-welcome').mouseout(function(){
			$('#welcome-megadrop').hide();
		});
		$('#welcome-megadrop').mouseover(function(){
			$('#welcome-megadrop').show();
			$('.nav-welcome').addClass ('welcome-hover');
		});
		$('#welcome-megadrop').mouseout(function(){
			$('#welcome-megadrop').hide();
			$('.nav-welcome').removeClass ('welcome-hover');
		});
		/////////////Gameplan
		$('.nav-six-steps').mouseover(function(){
			$('#six-steps-megadrop').show();
		});
		$('.nav-six-steps').mouseout(function(){
			$('#six-steps-megadrop').hide();
		});
		$('#six-steps-megadrop').mouseover(function(){
			$('#six-steps-megadrop').show();
			$('.nav-sixsteps').addClass('six-steps-hover');
		});
		$('#six-steps-megadrop').mouseout(function(){
			$('#six-steps-megadrop').hide();
			$('.nav-six-steps').removeClass('six-steps-hover');
		});
		/////////////Playbook
		$('.nav-playbook').mouseover(function(){
			$('#playbook-megadrop').show();
		});
		$('.nav-playbook').mouseout(function(){
			$('#playbook-megadrop').hide();
		});
		$('#playbook-megadrop').mouseover(function(){
			$('#playbook-megadrop').show();
			$('.nav-playbook').addClass('playbook-hover');
		});
		$('#playbook-megadrop').mouseout(function(){
			$('#playbook-megadrop').hide();
			$('.nav-playbook').removeClass('playbook-hover');
		});		
		////////////Tools & Resources
		$('.nav-tools').mouseover(function(){
			$('#tools-megadrop').show();
		});
		$('.nav-tools').mouseout(function(){
			$('#tools-megadrop').hide();
		});
		$('#tools-megadrop').mouseover(function(){
			$('#tools-megadrop').show();
			$('.nav-tools').addClass('tools-hover');
		});
		$('#tools-megadrop').mouseout(function(){
			$('#tools-megadrop').hide();
			$('.nav-tools').removeClass('tools-hover');
		});
		////////////Training CAmp
		$('.nav-training-camp').mouseover(function(){
			$('#training-camp-megadrop').show();
		});
		$('.nav-training-camp').mouseout(function(){
			$('#training-camp-megadrop').hide();
		});
		$('#training-camp-megadrop').mouseover(function(){
			$('#training-camp-megadrop').show();
			$('.nav-training-camp').addClass('training-camp-hover');
		});
		$('#training-camp-megadrop').mouseout(function(){
			$('#training-camp-megadrop').hide();
			$('.nav-training-camp').removeClass('training-camp-hover');
		});
		////////////Community
		$('.nav-community').mouseover(function(){
			$('#community-megadrop').show();
		});
		$('.nav-community').mouseout(function(){
			$('#community-megadrop').hide();
		});
		$('#community-megadrop').mouseover(function(){
			$('#community-megadrop').show();
			$('.nav-community').addClass('community-hover');
		});
		$('#community-megadrop').mouseout(function(){
			$('#community-megadrop').hide();
			$('.nav-community').removeClass('community-hover');
		});

			

///////////////////////////// FAQ's Drop Downs
$(".faqs-links ul:not(:first)").hide();
$(".faqs-list div:not(:first)").hide();

	$(".faqs-links div").click(function(){
		var activeAnswer = $(this).attr("id");
	  	$(this).next("ul").slideToggle("slow")
	  	.siblings("ul:visible").slideUp("slow");
		
		$(".faqs-list div").hide();
	 	$(".faqs-list .faq-"+activeAnswer).show();
	  
	});



/////////////////////////////Gameplan page Wheel Actions

	$('#wheeldiv').mousemove(function(e){
     	mouseX = e.pageX;
    	mouseY = e.pageY + 15;
    	$('#tooltip').css({'left' : mouseX, 'top' : mouseY});
    });
    $('#wheeldiv').mouseout(function(e){
    	$('#tooltip').css({'display' : 'none'});
    });
    
    
    
    //spread the word accordian on dashboard
    /*
    
#spread-word .content ul li div#invite_box,
#spread-word .content ul li div#twitter_box,
#spread-word .content ul li div#facebook_box

$(".faqs-list div:not(:first)").hide();

	$(".faqs-links div").click(function(){
		var activeAnswer = $(this).attr("class");
	  	$(this).next("ul").slideToggle("slow")
	  	.siblings("ul:visible").slideUp("slow");
		
		$(".faqs-list div").hide();
	 	$(".faqs-list .faq-"+activeAnswer).show();
	  
	});



    */
$("#spread-word .content ul li div").hide();

$("#spread-word .content ul li a:first-child").click(function(e){
		e.preventDefault();
	
	  	$(this).next("div").slideToggle("slow");
});


// Newsletter navigation

// Extend string to pull get variables
String.prototype.get = function(p){
    return (match = this.match(new RegExp("[?|&]?" + p + "=([^&]*)"))) ? match[1] : false;
}

// make sure user on the newsletter page
var re = new RegExp("^\/newsletter\/");
if(re.exec(window.location.pathname)){
	if(window.location.search.get('audience')){
		// pull get variable audience
		var audience = window.location.search.get('audience');
		// set tab - default to all set @ newsletter.css if lacking javascript
		if(audience != 'all'){
			$("ul.tabnav li#all").removeClass('active');
			$("ul.tabnav li#" + audience).addClass('active');
			// set content
			$(".audience-wrapper.all").hide();
			$(".audience-wrapper." + audience).show();
		}
	}
}


}); //end document.ready

////////////////////////////////Clock for systembar

function updateTime () {
	var currentTime = new Date ( );
	var currentHours = currentTime.getHours ( );
	var currentMinutes = currentTime.getMinutes ( );
	currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
	var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
	currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
	currentHours = ( currentHours == 0 ) ? 12 : currentHours;
	var currentTimeString = currentHours + ":" + currentMinutes + " " + timeOfDay;
	document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}


(function () {
       var mac=/mac/.test(navigator.userAgent);
       if (!!window.print) {
               window.print = function () { alert(window.print.message); }
               window.print.message =
                       'To print this page press '+(mac?'Command':'Control')+'-P. For best results, make sure your browser is set to print background images.'
       }
       window.printpage=window.print;
})();

