//Date Script
var now = new Date();
    var days = new Array(
      'Sunday','Monday','Tuesday',
      'Wednesday','Thursday','Friday','Saturday');
    var months = new Array(
      'January','February','March','April','May',
      'June','July','August','September','October',
      'November','December');
    var date = ((now.getDate()<10) ? "" : "")+ now.getDate();
    function fourdigits(number)	{
      return (number < 1000) ? number + 1900 : number;}
    today =  days[now.getDay()] + ", " +
       months[now.getMonth()] + " " +
       date;
//document.write(today);
/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/**
* Thank you to Soh Tanaka for this excellent tutorial and example
* 
http://www.sohtanaka.com/web-design/mega-drop-downs-w-css-jquery/
*/
$(document).ready(function() {
	

	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 400, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 400, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
	
	var mytextsizer=new fluidtextresizer({
		controlsdiv: "accessibilityToolbar", // id of special div containing your resize controls. Enter "" if not defined "content", 
		targets: ["#content p", "#content li", ".newsItem ul", ".article_grid_4 p", "#secondary li", ], //target elements to resize text within: ["selector1", "selector2", ".path a" etc]
		levels: 2, //number of levels users can magnify (or shrink) text
		persist: "session", //enter "session" or "none"
		animate: 200 //200 animation duration of text resize. Enter 0 to disable -- javascript:mytextsizer.setFontLevel(0)
	});
	
// Share Script by Kevin Bunt
	var url = window.location.href;
    var host =  window.location.hostname;
    var title = $('title').text();
    title = escape(title); //clean up unusual characters
	var facebook = 'http://www.facebook.com/sharer.php?u='+url;
    var twitter = 'http://twitter.com/home?status='+title+'%20'+url;
	var delicious  = 'http://del.icio.us/post?url='+url+'&amp;title='+title;
	var stumbleupon = 'http://stumbleupon.com/submit?url='+url+'&amp;title='+title;
	var digg = 'http://digg.com/submit?phase=2&url='+url+'&amp;title='+title;
	var reddit  = 'http://reddit.com/submit?url='+url+'&amp;title='+title;
	//var linkedin  = 'http://www.linkedin.com/shareArticle?mini=true&url='+url+'&amp;title='+title+'&amp;source='+host;
 	//var google = 'http://www.google.com/reader/link?url='+url+'&amp;title='+title+'&amp;srcURL='+host;
	//var yahoo = 'http://www.yahoo.com/reader/link?url='+url+'&amp;title='+title+'&amp;srcURL='+host;   
	var tbar = '<ul>';
    tbar += '<li><a href="'+facebook+'" class="ico-facebook" title="Share this page on Facebook">Facebook</a></li>';
    tbar += '<li><a href="'+twitter+'" class="ico-twitter" title="Share on Twitter">Twitter</a></li>';
	tbar += '</ul><ul>';
	tbar += '<li><a href="'+delicious+'" class="ico-delicious" title="Bookmark this page on Del.icio.us">Del.icio.us</a></li>';
	//tbar += '<li><a href="'+digg+'" class="ico-digg" title="Digg this page">Digg</a</li>';
	tbar += '<li><a href="'+stumbleupon+'" class="ico-stumbleupon" title="Share on Stumbleupon">Stumbleupon</a></li>';
	tbar += '</ul><ul>';
    tbar += '<li><a href="'+reddit+'" class="ico-reddit" title="Share on Reddit">Reddit</a></li>';
    tbar += '</ul>';
    $('#footer .social').append(tbar);
// Share Tool
	$("#sharetool1").tooltip({ effect: 'fade', position:'top right', relative: true, offset: [15, 10], delay:100});
	var tbar1 = '<p>';
    tbar1 += '<a href="'+facebook+'" class="ico-facebook" title="Share this page on Facebook"></a>&nbsp;&nbsp;';
    tbar1 += '<a href="'+twitter+'" class="ico-twitter" title="Tweet this page"></a>&nbsp;&nbsp;';
	tbar1 += '<a href="'+delicious+'" class="ico-delicious" title="Bookmark this page on Del.icio.us"></a>&nbsp;&nbsp;';
	tbar1 += '<a href="'+stumbleupon+'" class="ico-stumbleupon" title="Share on Stumbleupon"></a>&nbsp;&nbsp;';
	//tbar1 += '<a href="'+digg+'" class="ico-digg" title="Digg this page"></a>&nbsp;&nbsp;';
    tbar1 += '<a href="'+reddit+'" class="ico-reddit" title="Share on Reddit"></a>&nbsp;&nbsp;';
    tbar1 += '</p>';
    $('#social .share').append(tbar1);

// Toggle Script by Kevin Bunt
	$(".hide").hide();
	$("a.toggle").click(function(event){
		var text = $(this).parents(".article").find(".hide")
		if (text.is(':hidden')) {
			text.slideDown("fast");
		} else {
			text.slideUp('200');
		}
		return false;
	}); // /Toggle Script
	
	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
});
