
(function ($) {

/* ==|== Plugins ==== */

/*
jQuery Waypoints - v1.1.2
Copyright (c) 2011 Caleb Troughton
Dual licensed under the MIT license and GPL license.
https://github.com/imakewebthings/jquery-waypoints/blob/master/MIT-license.txt
https://github.com/imakewebthings/jquery-waypoints/blob/master/GPL-license.txt
*/
(function($,k,m,i,d){var e=$(i),g="waypoint.reached",b=function(o,n){o.element.trigger(g,n);if(o.options.triggerOnce){o.element[k]("destroy")}},h=function(p,o){var n=o.waypoints.length-1;while(n>=0&&o.waypoints[n].element[0]!==p[0]){n-=1}return n},f=[],l=function(n){$.extend(this,{element:$(n),oldScroll:-99999,waypoints:[],didScroll:false,didResize:false,doScroll:$.proxy(function(){var q=this.element.scrollTop(),p=q>this.oldScroll,s=this,r=$.grep(this.waypoints,function(u,t){return p?(u.offset>s.oldScroll&&u.offset<=q):(u.offset<=s.oldScroll&&u.offset>q)}),o=r.length;if(!this.oldScroll||!q){$[m]("refresh")}this.oldScroll=q;if(!o){return}if(!p){r.reverse()}$.each(r,function(u,t){if(t.options.continuous||u===o-1){b(t,[p?"down":"up"])}})},this)});$(n).scroll($.proxy(function(){if(!this.didScroll){this.didScroll=true;i.setTimeout($.proxy(function(){this.doScroll();this.didScroll=false},this),$[m].settings.scrollThrottle)}},this)).resize($.proxy(function(){if(!this.didResize){this.didResize=true;i.setTimeout($.proxy(function(){$[m]("refresh");this.didResize=false},this),$[m].settings.resizeThrottle)}},this));e.load($.proxy(function(){this.doScroll()},this))},j=function(n){var o=null;$.each(f,function(p,q){if(q.element[0]===n){o=q;return false}});return o},c={init:function(o,n){this.each(function(){var u=$.fn[k].defaults.context,q,t=$(this);if(n&&n.context){u=n.context}if(!$.isWindow(u)){u=t.closest(u)[0]}q=j(u);if(!q){q=new l(u);f.push(q)}var p=h(t,q),s=p<0?$.fn[k].defaults:q.waypoints[p].options,r=$.extend({},s,n);r.offset=r.offset==="bottom-in-view"?function(){var v=$.isWindow(u)?$[m]("viewportHeight"):$(u).height();return v-$(this).outerHeight()}:r.offset;if(p<0){q.waypoints.push({element:t,offset:null,options:r})}else{q.waypoints[p].options=r}if(o){t.bind(g,o)}});$[m]("refresh");return this},remove:function(){return this.each(function(o,p){var n=$(p);$.each(f,function(r,s){var q=h(n,s);if(q>=0){s.waypoints.splice(q,1)}})})},destroy:function(){return this.unbind(g)[k]("remove")}},a={refresh:function(){$.each(f,function(r,s){var q=$.isWindow(s.element[0]),n=q?0:s.element.offset().top,p=q?$[m]("viewportHeight"):s.element.height(),o=q?0:s.element.scrollTop();$.each(s.waypoints,function(u,x){if(!x){return}var t=x.options.offset,w=x.offset;if(typeof x.options.offset==="function"){t=x.options.offset.apply(x.element)}else{if(typeof x.options.offset==="string"){var v=parseFloat(x.options.offset);t=x.options.offset.indexOf("%")?Math.ceil(p*(v/100)):v}}x.offset=x.element.offset().top-n+o-t;if(x.options.onlyOnScroll){return}if(w!==null&&s.oldScroll>w&&s.oldScroll<=x.offset){b(x,["up"])}else{if(w!==null&&s.oldScroll<w&&s.oldScroll>=x.offset){b(x,["down"])}}});s.waypoints.sort(function(u,t){return u.offset-t.offset})})},viewportHeight:function(){return(i.innerHeight?i.innerHeight:e.height())},aggregate:function(){var n=$();$.each(f,function(o,p){$.each(p.waypoints,function(q,r){n=n.add(r.element)})});return n}};$.fn[k]=function(n){if(c[n]){return c[n].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof n==="function"||!n){return c.init.apply(this,arguments)}else{if(typeof n==="object"){return c.init.apply(this,[null,n])}else{$.error("Method "+n+" does not exist on jQuery "+k)}}}};$.fn[k].defaults={continuous:true,offset:0,triggerOnce:false,context:i};$[m]=function(n){if(a[n]){return a[n].apply(this)}else{return a.aggregate()}};$[m].settings={resizeThrottle:200,scrollThrottle:100};e.load(function(){$[m]("refresh")})})(jQuery,"waypoint","waypoints",this);

/*
  Formalize - version 1.1

  Note: This file depends on the jQuery library.
*/

// Module pattern:
// http://yuiblog.com/blog/2007/06/12/module-pattern
var FORMALIZE=function(a,b,c){var d="placeholder"in c.createElement("input"),e="autofocus"in c.createElement("input"),f=!!a.browser.msie&&parseInt(a.browser.version,10)===6,g=!!a.browser.msie&&parseInt(a.browser.version,10)===7;return{go:function(){for(var a in FORMALIZE.init)FORMALIZE.init[a]()},init:{full_input_size:function(){g&&a("textarea, input.input_full").length&&a("textarea, input.input_full").wrap('<span class="input_full_wrap"></span>')},ie6_skin_inputs:function(){if(f&&a("input, select, textarea").length){var b=/button|submit|reset/,c=/date|datetime|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/;a("input").each(function(){var d=a(this);this.getAttribute("type").match(b)?(d.addClass("ie6_button"),this.disabled&&d.addClass("ie6_button_disabled")):this.getAttribute("type").match(c)&&(d.addClass("ie6_input"),this.disabled&&d.addClass("ie6_input_disabled"))}),a("textarea, select").each(function(){this.disabled&&a(this).addClass("ie6_input_disabled")})}},autofocus:function(){e||!a(":input[autofocus]").length||a(":input[autofocus]:visible:first").focus()},placeholder:function(){!d&&!!a(":input[placeholder]").length&&(FORMALIZE.misc.add_placeholder(),a(":input[placeholder]").each(function(){var b=a(this),c=b.attr("placeholder");b.focus(function(){b.val()===c&&b.val("").removeClass("placeholder_text")}).blur(function(){FORMALIZE.misc.add_placeholder()}),b.closest("form").submit(function(){b.val()===c&&b.val("").removeClass("placeholder_text")}).bind("reset",function(){setTimeout(FORMALIZE.misc.add_placeholder,50)})}))}},misc:{add_placeholder:function(){d||!a(":input[placeholder]").length||a(":input[placeholder]").each(function(){var b=a(this),c=b.attr("placeholder");(!b.val()||b.val()===c)&&b.val(c).addClass("placeholder_text")})}}}}(jQuery,this,this.document);jQuery(document).ready(function(){FORMALIZE.go()})


/* ==|== Scripts ==== */
	
	/* Extending jQuery */
	jQuery.fn.exists = function(){return jQuery(this).length>0;}
	
	function getarrval(arr) {
		return arr[Math.floor(Math.random() * arr.length)];
	}
	
	/* Waypoints */
	function initWaypoints() {
		
		/* Adding Styles to wrappers */
		$('#breadcrumbwrap').css('position','absolute');
		
		$.waypoints.settings.scrollThrottle = 30;
		
		var winh = $(window).height();
		var doch = $(document).height();
		
		/* If the document height isn't greater than twice the window height we don't need scroll nav */
		if( doch > winh*2 ) { 
		
			var navwrap = $('#breadcrumbwrap');
			var ioffset = 200; /* waypoint offset - we use this in other calcs */
		
		    $('#breadcrumbnav').waypoint(
				function(event, direction) {
			        $(navwrap).toggleClass('sticky', direction === "down");
			        event.stopPropagation();
			    }, { 
					offset: ioffset
				}
			);
			
			/* Fade sidebar when it gets to the footer element */
			$('#wrapper').waypoint(
				function(event, direction) {
					
					if (direction === 'down') {
						/* var navtop = $(navwrap).offset(); */  
						/* WRONG - this is calculated differently depending on scroll speed!
						Use following method: */
						
						var navtop = ($("#footer").offset().top)-(navwrap.height())-285; /* 71 adjusts for paragraph styling */
						
						$(navwrap).addClass("matched").css({ "position": "absolute !important", "top": navtop });
					}
					else {
						$(navwrap).removeClass("matched").removeAttr('style');
					}
					event.stopPropagation();
			    }, {
			        offset: function() {
						var offh = ($('#wrapper').height()-($('#breadcrumbnav').height()+ioffset))*-1;
						return offh;
					}
			    }
			);
		}
	};
	
	function DrupalToolbarSlider(partypoopermode) {
		
		var toolbardrupal7 = "#toolbar";
		
		var greetings = [
			"Hola Amigo", 
			"Wassup Bra", 
			"Yo, yo, yo G", 
			"Pardon me sir",
			"Arrggggg Matey",
			"Bonjour Mon Ami",
			"Sup home-slice",
			"Hey stud"
			];
		
		var sgreeting = getarrval(greetings);
		
		$(toolbardrupal7).hide();
		
		if ($('body').is('.logged-in')) {
			
			if (partypoopermode == 0) {
				$('<div class="drupalnotification">' 
				  + sgreeting 
				  + ', you\'re logged in. <em><small>Press ~ to view the toolbar.</small></em></div>')
				.prependTo("body");
			}
			else {
				$('<div class="drupalnotification">You\'re logged in. <em><small>Press ~ to view the toolbar.</small></em></div>')
				.prependTo("body");
			}
			
		}
		
		$(document).keydown(function(event) {
			if (event.keyCode == '192') {
				$(toolbardrupal7).slideToggle("fast", function() {
					$(".drupalnotification").fadeToggle();
				});
				$("body").toggleClass("toolbar-closed");
			}
		});
		
	};
	
	function AppendPersonGreeting(partypoopermode) {
		
		if (partypoopermode == 0) {
		
			var arrphrases = [
				"say hello to",
				"please meet",
				"get to know",
				"let us introduce"
				];
			
			var randphrase = getarrval(arrphrases);
			
			if ($('.page-afpeople-staff').exists()) {
				var container = $('.page-afpeople-staff h1#page-title')
				container.css({lineHeight: '22px'});
				container.wrapInner('<strong />');
				container.prepend('<span class="randphrase">' + randphrase + '</span><br/>');
			}
			
			if ($('.page-afpeople-member').exists()) {
				var container = $('.page-afpeople-member h1#page-title')
				container.css({lineHeight: '22px'});
				container.wrapInner('<strong />');
				container.prepend('<span class="randphrase">' + randphrase + '</span><br/>');
			}
			
		}
	};
	
	function RemoveMenuHrefs() {
		$('a.menu-minipanel').attr('href','#');
		$('#footer ul.menu>li.expanded>a').attr('href','#');
		
		$('#secondarysidebar #breadcrumbnav ul.menu li').unbind();
		$('#secondarysidebar #breadcrumbnav ul.menu li a').unbind();
	};
	
	function ShowPassword() {
		
	/* We can't change input types once the DOM loads,
	so we recreate and toggle the form input */
		
	  $("#show-pass").click(function(){
	    if( $("#show-pass:checked").length > 0 ){
	      var pswd = $("#password").val();
	      $("#password").attr("id","password2");
	      $("#password2").after( $("<input size='26' value='' tabindex='2' name='password' maxlength='50' type='text' id='password'>") );
	      $("#password2").remove();
	      $("#password").val( pswd );
	    }
	    else{ // vice versa
	      var pswd = $("#password").val();
	      $("#password").attr("id","password2");
	      $("#password2").after( $("<input size='26' value='' tabindex='2' name='password' maxlength='50' type='password' id='password'>") );
	      $("#password2").remove();
	      $("#password").val( pswd );
	    }
	  });
	}
	
	function openMe() {
		win = window.open("https://secure.netlinksolution.com/login1.jsp?url=secure.netlinksolution.com", "Login", "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width=500,height=180")        
		win.creator = self;
	}

	
	/* Initialize */
	
	$(document).ready(function(){
		
		/* Wrapping the markup Drupal gives us for the sidebar breadcrumbs */
		$('#block-menu-block-1').wrap("<div id='breadcrumbwrap' class='clearfix'></div>");
		$('#breadcrumbwrap ul.menu:first').wrap("<div id='breadcrumbnav' class='clearfix'></div>");
		
		/* initWaypoints(); */
		DrupalToolbarSlider(1); /* argument is for 'Party-pooper mode' 1 for on, 0 for off */
		AppendPersonGreeting(1); /* argument is for 'Party-pooper mode' 1 for on, 0 for off */
		
		RemoveMenuHrefs();
		ShowPassword(); 
		
    });

})(jQuery);;

