/*------------------------------------------
	jQuery:
		DOM ready events
--------------------------------------------*/
$(document).ready(function() {
  $("#block-menu-menu-audience-navigation .menu a").wraptext("For", "for-span");
  
  $('[title*=For]').each(function(){
  	var str = $(this).attr('title');
  	var regex = /\<span\>For\<\/span\>/g;
  	$(this).attr('title',str.replace(regex,'For'));
  });
  
  $('[title*=One]').each(function(){
  	var str = $(this).attr('title');
  	var regex = /\<em\>One\<\/em\>/g;
  	$(this).attr('title',str.replace(regex,'One'));
  });
  
	// apply overlabel to search form
	$("#search label").labelOver('over');
	
	// open external links in new windows
	// - requires class="externalLink"
	$("a.externalLink").click(function() {
		window.open(this.href);
		return false;
	})
	
	
	
	// add zebra striping table row class
	$("table.zebra tbody tr:odd").addClass("stripe");
	
	// fix background image flickr on links in IE6
	try { document.execCommand("BackgroundImageCache", false, true); }
	catch(err) {}
	
	// login menu show/hide
	$('#block-menu-menu-logins').hover(
	   function(){
	      $('ul.menu', this).css('display', 'block');  	      
	      $('#block-menu-menu-logins h2').css('background', 'none #a1a1a1')
	                                     .css('color', '#fff');
	      $('#block-menu-menu-logins').css('background-color', '#a1a1a1');
              $('#examone-location-search-form select').hide();
              //alert('hover logins');
	   },
         function(){
            $('ul.menu', this).css('display', 'none');              
            $('#block-menu-menu-logins h2').css('background', 'url(/sites/all/themes/examone/images/login_arrow.jpg) #f5f5f5 no-repeat 130px 5px').css('color', '#000');
            $('#block-menu-menu-logins').css('background-color', '#f5f5f5');
            $('#examone-location-search-form select').show();
            //alert('off of logins');
         }
	);	
	
	/* fix rollover for Login in IE 6 and 7 */
	if ($.browser.msie && $.browser.version <= 7 )
	{
	   $('.block-nice_menus').hover(
	      function(){
	         $('#block-menu-menu-logins').css('position', 'static');
	      },
	      function(){
	         $('#block-menu-menu-logins').css('position', 'relative');
	      }
	   );
	}  	
	
	/* clear out value of form submit buttons */
	$("#webform-client-form-103 input.form-submit").val('');
	$(".block-examone_location_search input.form-submit").val('');
	$(".webform-client-form #edit-next").val('');
	$(".webform-client-form #edit-previous").val('');
	$(".webform-client-form #edit-submit").val('');
	
	$("#edit-zipcode").val('ZIP Code');
	
	$("#edit-zipcode").focus(function(){
	  $(this).val('');
	});
	
	/* remove third level navigation in top navigation to fix IE6 */
	$('ul.bg-ds ul.bg-ds').unbind();
	$('ul.bg-ds ul.bg-ds').remove();
});

/*------------------------------------------
	jQuery:
		Window load Events
--------------------------------------------*/
$(window).load(function() {});


/*------------------------------------------
	jQuery Plugins
--------------------------------------------*/
//	Label Over by Remy Sharp : Apply label over input
jQuery.fn.labelOver = function(overClass) {
	return this.each(function() {
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			this.hide = function() {
				label.css({ textIndent: -10000 })
			}
			this.show = function() {
				if (input.val() == '') label.css({ textIndent: 0 })
			}
			// handlers
			input.focus(this.hide);
			input.blur(this.show);
			label.addClass(overClass).click(function(){ input.focus() });
			if (input.val() != '') this.hide(); 
		}
	});
}

//	vJustify by Michael Futreal: Justify Element Heights
jQuery.fn.vjustify=function() {
	var maxHeight=0;
	this.each(function() {
		if (this.offsetHeight>maxHeight) { maxHeight=this.offsetHeight; }
	});
	this.each(function() {
		$(this).height(maxHeight + "px");
		if (this.offsetHeight>maxHeight) {
			$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
		}
    });
};


/*------------------------------------------
	Without jQuery:
		Attach events when DOM is ready
--------------------------------------------*/
//addEvent(window, 'load', initLinks);
//addEvent(window, 'load', initBgImgFix);

/*------------------------------------------
	Utility Functions
--------------------------------------------*/
/*
function addEvent(obj, evType, fn) { 
	if (obj.addEventListener) { 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent) { 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
}

function initLinks() {
	if (document.getElementById && document.getElementsByTagName) {
		var links = document.getElementsByTagName('a');
		for (var a = 0; a < links.length; a++) {
			
			// open external links in new window
			// - requires class="externalLink"
			if (links[a].className == 'externalLink') {
				links[a].onclick = function() {
					window.open(this.href);
					return false;
				}
			}
		}
	}
}

// fix the IE6 background image flickr on links
function initBgImgFix() {
	try { document.execCommand("BackgroundImageCache", false, true); }
	catch(err) {}
}
*/