
jQuery(document).ready( function(){
	// open external links in a new window
	jQuery('a').each(function() {
	   var a = new RegExp('/' + window.location.host + '/'); 
           //add in script to stop this happening for javascript links
	   var b = new  RegExp('javascript');
       var c = new  RegExp('mailto');
 	   if( !c.test(this.href)  && !a.test(this.href) && !b.test(this.href)) {


		   jQuery(this).click(function(event) {
			   event.preventDefault();
			   event.stopPropagation();
			   window.open(this.href, '_blank');
		   });
	   }
	});
	
	// clears the input and textarea default values
	// add more values in the conditional statement if you are going to have more default field
	jQuery('input, textarea').focus(function() {
			value = jQuery(this).val();
			if (value == "Name" || value == "Email" || value == "Message") { // conditional statement to check if the default value is one of these
				jQuery(this).attr("value","");
			}
		});
	
	jQuery('input, textarea').blur(function() {
			if(jQuery(this).val() == "") {
				jQuery(this).val(value);
			}
	});

	
	// show tool tips for abbr tags
	jQuery('abbr[title]').qtip({ 
		style: { name: 'light', tip: false, padding: '5px', border: 1 },
		position: {
		  corner: {
			 target: 'topLeft',
			 tooltip: 'bottomLeft'
		  }
		},
		hide: {
			fixed: true
		 }
	});
	
	// controls hover and current state of main navigation							
	jQuery(".nav ul li").each(function(){
		var the_link = jQuery(this).children("a"); 
		var image = jQuery(the_link).children("img");  
		var imgsrc = jQuery(image).attr("src");		
		var current = jQuery(image).attr("class");
		
		if (imgsrc) {		
			// if image is tagged as current page we switch the source to the -on.jpg
			if (current) { 
				var on = imgsrc.replace(/.jpg$/gi,"-on.jpg");  
				jQuery(image).attr("src",on);  
			// if image is not tagged as current page we allow the roll over effect
			} else {
				// add mouseover  
				jQuery(the_link).mouseover(function(){  
					var ro = imgsrc.replace(/.jpg$/gi,"-ro.jpg");  
					jQuery(image).attr("src",ro);  
				});				
				// add mouse out  
				jQuery(the_link).mouseout(function(){  
					jQuery(image).attr("src",imgsrc);  
				});  
			}
		}
	});
	
	// controls current state of left navigation							
	jQuery("#left-column ul li").each(function(){
		var the_link = jQuery(this).children("a"); 
		var current = jQuery(this).attr("class");
		if (current) { 
			jQuery(this).children("a").addClass("current");
		}
	});
	
	//show hidden drop down nav
	jQuery('.nav ul li').hover(
		function() { 
			jQuery('ul', this).addClass('hover'); 
			if (jQuery.browser.opera) { // Opera fix; does not display drop down but will fix for next build
				jQuery('ul', this).hide();
			} else {
				jQuery('ul', this).show(); 
			}
			jQuery('ul .nav-top', this).show(); },
		function() { 
			jQuery('ul', this).css('display','none'); 
			jQuery('ul .nav-top', this).hide(); 
	});
	
	jQuery(".switcher a").click(function() {		
		var style = jQuery(this).attr('rel');
		jQuery("link.font-switch").attr("href",jQuery(this).attr('rel'));
		jQuery.cookie("css",jQuery(this).attr('rel'), {expires: 365, path: '/'});
		jQuery('.switcher .small a').removeClass('on');
		jQuery('.switcher .medium a').removeClass('on');
		jQuery('.switcher .large a').removeClass('on');
		jQuery(this).addClass('on');
		//jQuery('#left-column').css({'height' : 'auto'});		
		var leftHeight = jQuery('#left-column').height();
		jQuery('#left-column').css({'min-height' : leftHeight + 20});		
		jQuery('#main-content').css({'height' : 'auto'});	
		equalHeight(jQuery(".column"));
		return false;
	});
	
	// sets cookie for style chosen
	if(jQuery.cookie("css")) {
		jQuery("link.font-switch").attr("href",jQuery.cookie("css"));
		jQuery('.switcher .small a').removeClass('on');
		jQuery('.switcher .medium a').removeClass('on');
		jQuery('.switcher .large a').removeClass('on');
		if (jQuery.cookie("css") == '/style%20library/en-us/custom/font-size-small.css') {
			jQuery('.switcher .small a').addClass('on');
		} else if (jQuery.cookie("css") == '/style%20library/en-us/custom/font-size-medium.css') {
			jQuery('.switcher .medium a').addClass('on');
		} else if (jQuery.cookie("css") == '/style%20library/en-us/custom/font-size-large.css'){
			jQuery('.switcher .large a').addClass('on');
		} else if (1==1){
			jQuery('.switcher .small a').addClass('on');
		}
		
		equalHeight(jQuery(".column"));
	} else {
		jQuery("link.font-switch").attr("href",'/style%20library/en-us/custom/font-size-small.css');
		jQuery.cookie("css",'/style%20library/en-us/custom/font-size-small.css', {expires: 365, path: '/'});
		equalHeight(jQuery(".column"));
	}
	
	
	//handles rollovers for tabs
	jQuery("#main-content .tabs img").hover(
		function(){
			var iconName = jQuery(this).attr("src");
			var origin = iconName.split("-off.")[0];
			jQuery(this).attr({src: "" + origin + "-on.jpg"});
		}, 
		function(){
			var iconName = jQuery(this).attr("src");
			var origin = iconName.split("-on.")[0];
			jQuery(this).attr({src: "" + origin + "-off.jpg"});
	});	

	// align column heights	
	function equalHeight(group) {
		tallest = 0;
		group.each(function() {
			thisHeight = jQuery(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		//alert(thisHeight);
		tallest = tallest + 20;
		//tallest = tallest*1.1;
		
		if ( tallest < 500)
		{
			tallest = 500;
		}
		group.css({'min-height': tallest});
		
	}
	
	// load the tool tip windows	
	// this is creating the style
	jQuery.fn.qtip.styles.box = { // last part is the name of the style
	   name: 'light',
		width: 384,
		border: 0,
		'margin-left': '4px',
		background: 'none'
	}
	
	// create a script for each box
	// this is box 1, labeled as b1
	jQuery('.content .b1').qtip({
		content: { url: 'content2.html' }, // the HTML page to be loaded inside the tooltip
		style: 'box',
		position: {
		  corner: {
			 target: 'topMiddle',
			 tooltip: 'bottomMiddle'
		  }
		},
		show: 'mouseover',
   		hide: { when: 'mouseout', fixed: true }
	});
	
	jQuery('.content .b2').qtip({
		content: { url: 'content2.html' }, // the HTML page to be loaded inside the tooltip
		style: 'box',
		position: {
		  corner: {
			 target: 'topMiddle',
			 tooltip: 'bottomMiddle'
		  }
		},
		show: 'mouseover',
   		hide: { when: 'mouseout', fixed: true }
	});
	
	jQuery('.content .b3').qtip({
		content: { url: 'content2.html' }, // the HTML page to be loaded inside the tooltip
		style: 'box',
		position: {
		  corner: {
			 target: 'topMiddle',
			 tooltip: 'bottomMiddle'
		  }
		},
		show: 'mouseover',
   		hide: { when: 'mouseout', fixed: true }
	});
	
	equalHeight(jQuery(".column"));

			


});
