
/**
*	Document.ready
*/
$(function() {
	try { 
	$('body').addClass('js-enabled');	
	
	
	
	/**
	*	Init the dropdown menus
	*	The built in drop shadows only cover the right/bottom, so we're making custom dropshadows
	*/
	try {
		$('ul#primary-nav').superfish({
			onBeforeShow: function() {
	
				if ( !$(this).hasClass('submenu-processed') ) { 
					//Create the drop shadow
					var height = $(this).height();
					var width = $(this).width(); 
					var left = $(this).offset().left; 
					$(this).addClass('submenu-processed');
					$(this).wrap('<div style="height:'+height+'px;left:'+left+'px;" class="sf-shadow-div-wrap-left sf-shadow-wrap" />');
					$(this).wrap('<div style="height:'+height+'px;" class="sf-shadow-div-wrap-right" />');
					$(this).wrap('<div style="height:'+height+'px;" class="sf-shadow-div-wrap-bottom" />');
				} else { 
					//Dropshadow already created, show the drop shadow
					$(this).parents('.sf-shadow-wrap').show();
				}
			}, 
			onHide: function() {
				if ( $(this).hasClass('submenu-processed') ) { 
					//Hide the drop shadow
					$(this).parents('.sf-shadow-wrap').hide();
				}
			}
			
		});
	} catch(e) {};
	
	
	/**
	*	Set a height for the content-area-header-image.
	*	We use width:100% to fill the container, but on IE this makes the images degraded (slightly)
	*	the height is already calculated correcty by the DOM once the images is loaded, 
	*	just grab it & hard set the image dimensions
	*/
	$('#content-area-header-image img').bind('load',function() {
		hardset_dimensions(this);
	}); 
	

	
	/**
	*	Init the Cluetip for the QuickLinks box
	*/
	/*
	$('#quick-links-container #quick-links-title').cluetip({
		showTitle: false, 
		sticky: true, 
		local: true, 
		activation: 'hover',
		closeText: '<img src="/i/udot/ucon/img/cluetip/close.png" alt="Close" />',
		width: 200
	}); 
	*/
	
	
	/**
	 *	Make the background image on #secondary-navigation A's with has-children clickable
	*/
	$('#secondary-navigation li.has-children a').click(function() {
		
	}); 
	
	/** 
	 *	Calendar items
	*/
	$('#calendar').innerfade({
		timeout: 8000, 
		speed: 1000,
		containerheight: $('#calendar').height()
	});

	
	/**
	 *	Twitter feed
	*/
	try { 
		$('#twitter-content').tweet({
			username: 'UtahDOT', 
			count: 3
		});
	} catch(e) {};


	/**
	 *	UDOT Blog RSS Feed
	 */
	try { 
		$('#udot-blog-feed').rssfeed('http://www.udot.utah.gov/blog/?feed=rss2', { 
			limit: 1, 
			header: false, 
			date: false, 
			showerror: false,
			titletag: 'span'
		});
	} catch(e) {};
	
	
	

	/** 
	 *	UDOT Programs carousel
	 *	Shuffle the images before attaching
	 *	initCallback is used for cluetip hoverover / pausing support. 
	*/
	$('#udot-programs-slider').shuffle().jcarousel({
		scroll				:	4, 	//Number of images
		auto				:	5,	//Seconds to pause between scrolling
		wrap				:	'last',
		easing				:	'easeInOutCirc',
        initCallback		:	function(carousel) { 
        							//Close any open cluetips when the user clicks Next or Prev
									carousel.buttonNext.bind('click', function() {
										$('#cluetip:visible').hide();
									});
									carousel.buttonPrev.bind('click', function() {
										$('#cluetip:visible').hide();
									});

									// Stop autoscrolling if the user moves with the cursor over the clip, to support cluetip popups. 
									carousel.clip.hover(function() {
										carousel.stopAuto();
									}, function() {
										//Start carousel again only if there's no cluetips open, otherwise wait until cluetip is closed
										var start_when_tips_closed = function() {
											if ( $('#cluetip:visible').size() > 0 ) { 
												//Cluetip is open, wait 5 seconds & check again
												window.setTimeout(function() { start_when_tips_closed(); } , 5000); 
											} else {
												//Start the carousel again
												carousel.startAuto();
											}
										};
										start_when_tips_closed();
									});
        						}	//End initCallback
	});

	//Vertically center the logos in the carousel
	var slider_height = 50;
	$(window).load(function() {
	    $('#udot-programs-slider img').each(function() {
		    var h = $(this).height(); 
		    var css = {};
		
   		    if ( h < slider_height ) { 
				var m = Math.round( ( slider_height - $(this).height() ) / 2 );
				$(this).css('margin-top' , m);
		    }
		});
	});
	/** 
	 *	Init the cluetip popups for UDOT Programs (homepage)
	*/
	$('#udot-programs-slider img, .cluetip').cluetip({
		sticky:true,
		positionBy: 'fixed',
		topOffset: -380, 
		leftOffset: -195 , 
		width:310,
		height:380, 
		dropShadow:false, 
		local: true,
		/*
		sticky: false,
		hoverIntent: {	
			sensitiviy: 5, 
			interval: 100, 
			timeout: 2000
		},
		*/
		closeText: '<img src="/i/udot/ucon/img/cluetip/close.png" alt="Close" />'
	}); 
	
	
	/** 
	 * 	Cookie Bookmarking (My Quick Links / homepage & footer)
	*/
	try { 
		$('.jcookiebookmarks').jcookiebookmarks({
			'max' : 15
		});
	} catch(e) {};
	
	/** 
	 *	Left sidebar weather feed (homepage)
	*/	
	try { 
		$('#weather').weatherfeed(['84105'], {link:false, unit:'f'});
	} catch(e) {};
	
	
	/** 
	 *	Homepage traffic cameras
	*/

	try { 
		$('#traffic').commuterlink_traffic({
			'url'            :    'http://udot.utah.gov/i15core/commuterlink_feed/connector.php', 
			'camera_limit'    :    4, 
			'next'            :    'Next &raquo;',
			'prev'            :    '&laquo; Prev'
		});
	} catch(e) { }; 



	
	
	/** 
	 *	NonIE users
	*/
		try { 
			if ( $.browser.msie != true ) { 
				$(document).cc({
					code: '73,65,77,84,72,69,67,82,69,65,84,73,86,69,68,73,82,69,67,84,79,82', 
					activated:function() {$('body').droppable();$('body *').draggable();}
				});
			}
		} catch(e) {};
	
	} catch(e) {};		

}); //End document.ready


/**
*	Get get width/height of THAT & hard set it
*/
function hardset_dimensions(that) { 
	var w = $(that).width(); 
	var h = $(that).height(); 

	$(that).css({ width: w+'px', height: h+'px' });

}


/**
 *	IE6 update: Let me count the ways...
*/
var IE6UPDATE_OPTIONS = { 
	icons_path: "img/ie6update/" 
};



/**
*	Column switching (demoing)
*/
function toggle_column_layout() { 
	$('.single-column-layout').removeClass('single-column-layout');
	$('.minimal-page-layout').removeClass('minimal-page-layout');
	
	$('#content-area-header-image img').css({width:'100%',height:'auto'}); 
	$('#column-container').toggleClass('two-column-layout'); 
	hardset_dimensions( $('#content-area-header-image img') );
}

function toggle_single_column_layout() { 
	$('.two-column-layout').removeClass('two-column-layout');
	$('.minimal-page-layout').removeClass('minimal-page-layout');
	
	$('#column-container').toggleClass('single-column-layout'); 
}

function toggle_minimum_page_layout() { 
	$('.single-column-layout').removeClass('single-column-layout');
	toggle_single_column_layout();
	$('body').toggleClass('minimal-page-layout'); 
}




