
//Site specific
$(function() {
	

	//Expanding/collapsing
	$('.expandor').expandor(); 
	
	//Progress photo gallery
	$('#photobox .photo-link, .fancybox').fancybox();
	
	
	//Iframe required content
	$('.fancybox-iframe').fancybox({
		type: 'iframe', 
		width: 640, 
		height: 360
	}); 
	
	
	
	
	/*******************************************
		Homepage
	*******************************************/
	
	//Commuterlink Cameras image pulsing
	$('#camera-container .camera').imagepulser({
			width: 320, 
			height: 240, 
			padding_top: 18, 
			padding_left: 25 
	});
	
	// CommuterLink Cameras carousel functions
	

	$('#camera-container').jcarousel({}); 
	
	
	//Auto update the commuterlink cameras every few minutes
	$('#camera-container .camera').refreshimage(); 

	
	
	/**
	 *	VMS Sign Fading
	 *	Delay VMS fading until all images have loaded
	 *	Replace IE check - this happens on FF4 too...
	*/
	//if ( $.browser.msie == true ) { 	
		var vms_signs_to_load = $('#vms-sign-content img').size();  
		$('#vms-sign-content img').each(function() {
			var img = new Image(); 
			img.onload = function() {
				vms_signs_to_load--;
				init_vms_sign(); 
			}
			img.src = $(this).attr('src'); 
		}); 
	//} else {
		//Everyone else is sane
	//	attach_innerfade_vms(); 
		
	//}

	/** 
	*	Wait for IE to load, then wait longer after it claims it's done
	*/
	function init_vms_sign() {	
		if ( vms_signs_to_load > 0 ) {
			//Wait for other signs to load
			return false; 
		}
		window.setTimeout(function() { 
			attach_innerfade_vms(); 
		}, 1000);

	}

	function attach_innerfade_vms() { 
		$('#vms-sign-content').innerfade({
			speed: 'slow', 
			timeout: 8000,
			containerheight: 188,
			beforeChange: function() {
	
			}, 
			afterChange: function() {
				var i = $.innerfade.selectedIndex; 
				$('#vms-items-container .vms-item-selected').removeClass('vms-item-selected');
				$('#vms-items-container .vms-item:eq(' + i + ')').addClass('vms-item-selected');
			}
		}); 
		//VMS Select the requested sign when grey box checked
		$('#vms-items-container .vms-item').click(function() {
			$.innerfade.select( $(this).index() );
		}); 
		//VMS Next arrow
		$('#vms-sign-next').click(function() {
			$.innerfade.navigateNext();
		}); 
		//VMS Previous arrow
		$('#vms-sign-prev').click(function() {
			$.innerfade.navigatePrev();
		}); 	
	}


	
	
	/* Contact lightbox on homepage */
	$('.stay-informed-lightbox').fancybox({
		width: 640, 
		height: 540, 
		padding: 3,		
		autoDimensions: false,
		centerOnScroll: true, 
		titleShow: false,
		onStart: function() {
			$('#stay-informed-lightbox').show();
		}, 
		onCleanup: function() {
			$('#stay-informed-lightbox').hide();
		}
	});
	/*******************************************
		End Homepage
	*******************************************/
	
	
});  //End document.ready


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




/**
*	UDOT Document.ready
*/
$(function() {
	$('body').addClass('js-enabled');	
	
	
	/**
	*	Init the dropdown menus
	*	The built in drop shadows only cover the right/bottom, so we're making custom dropshadows
	*/
	$('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();
			}
		}
		
	});
	
	
	/**
	* 	Trigger the child anchro when parent LI is clicked *
	*/
	$('ul#primary-nav li').click(function(e) {
		if ( $('a',this).size() == 1) { 
			window.location = $('a', this).attr('href');
		}
	}); 
	
	
	/**
	*	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="img/cluetip/close.png" alt="Close" />',
		width: 200
	}); 
	
	

}); //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' });

}


/**
*	Column switching
*/
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'); 
}
