/* =============================================================================
   =SLIDESHOW
   ========================================================================== */

$(document).ready(function(){
	$('#slideshow').bxSlider({
		mode:'fade',
		speed:1500,
		pause:5000,
		auto:true,
		controls:false,
		pager:true
	});
});

$(document).ready(function(){
	$("#video").click(function() {
		$.fancybox({
			'padding'       : 0,
			'autoScale'     : false,
			'transitionIn'  : 'none',
			'transitionOut' : 'none',
			'title'         : this.title,
			'width'         : 640,
			'height'        : 385,
			'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'          : 'swf',
			'swf'           : {
			'wmode'             : 'transparent',
			'allowfullscreen'   : 'true'
			}
		});

		return false;
	});
});

/* =============================================================================
   =NAV
   ========================================================================== */

$(document).ready(function(){

	//On Hover Over
	function megaHoverOver(){
		$(this).find(".nav-sub").stop().fadeTo('slow', 1).show(); //Find sub and fade it in
		(function($) {
			//Function to calculate total width of all ul's
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() { //for each ul...
					rowWidth += $(this).width(); //Add each ul's width together
				});
			};
		})(jQuery);

		$(this).calcSubWidth();  //Call function to calculate width of all ul's
		$(this).find(".nav-sub").css({'width' : rowWidth}); //Set Width
	}

	//On Hover Out
	function megaHoverOut(){
	  $(this).find(".nav-sub").stop().fadeTo('slow', 0, function() { //Fade to 0 opactiy
		  $(this).hide();  //after fading, hide it
	  });
	}

	//Set custom configurations
	var config = {
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
		 interval: 0, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 0, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$(".nav-sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	$("#sc > nav > ul > li").hoverIntent(config); //Trigger Hover intent with custom configurations
});
