$(function() {
	//Working with the Need Help? Drop down
	$('#needhelpbutton').hover(
		function() {
			$('#needhelp').fadeIn(100);
		});

	$(document).click(function() {
		$('#needhelp').fadeOut(300);
	});

	$("#needhelp input[type=text]").click(function() {
		return false;
	});

	//Handle clearing default value
	$('input[type=text]').one('focus', function(){
		$(this).attr('value', '');
	});

	//handle image rollover swaps
	$('.rollover').hover(function(){
			var name = $(this).attr("src").split(".");
			$(this).attr("src", name[0]+'_over.'+name[1]);
		}, function() {
			$(this).attr("src", $(this).attr("src").replace("_over.","."));
	});

	//handle image rollover swaps
	$('.submit').hover(function() {$(this).addClass('hover');},function() {$(this).removeClass('hover')});

	//handle the programs tab
	var programstabs = $('#programs > ul li');
	programstabs.click(function() {
		$('a', programstabs).removeClass('active');
		$('a', this).addClass('active');
	});

	$('#programs-tab a').click(function(){
		$('#programs ul').css('background-position', '0 0');
		$('#programs .tab-content').hide();
		$('#programs .programs-content').show();
	});

	$('#study-areas-tab a').click(function(){
		$('#programs ul').css('background-position', '0 -40px');
		$('#programs .tab-content').hide();
		$('#programs .study-areas-content').show();
	});

	$('#career-information-tab a').click(function(){
		$('#programs ul').css('background-position', '0 -80px');
		$('#programs .tab-content').hide();
		$('#programs .career-information-content').show();
	});

	//handle lower carousel
	var carouseltabs = $('#carousel-tabs li');
	carouseltabs.click(function() {
		$('a', carouseltabs).removeClass('active');
		$('a', this).addClass('active');
	});

	$('#carousel-most-visited-tab a').click(function(){
		$('#carousel-tabs').css('background-position', '0 0');
		$('#carousel .tab-content').hide();
		$('#carousel .most-visited-content').show();
	});

	$('#carousel-sitemap-tab a').click(function(){
		$('#carousel-tabs').css('background-position', '0 -29px');
		$('#carousel .tab-content').hide();
		$('#carousel .sitemap-content').show();
	});

	$("#carousel-content").carousel({
		dispItems: 5,
		showEmptyItems:false,
		slideEasing: 'easeOutQuart',
		combinedClasses: true,
		animSpeed: 700
	}).find('LI').show();

	$("#slider-content").carousel({
		dispItems: 1,
		pagination: true,
		btnsPosition: false,
		autoSlide: true,
		autoSlideInterval: 4000,
		showEmptyItems:false,
		effect: 'fade',
		combinedClasses: true,
		animSpeed: 1000
	}).find('LI').show();

	//Column Handler
	$("ul.three-column").makeacolumnlists({cols:3,colWidth:0,equalHeight:false,startN:1});

	$('.results TBODY tr:odd').find('td').addClass('odd');

	$('#program_search select').ieSelectWidth({containerClassName:'select-container',overlayClassName:'select-overlay'});

	$('#career-information .submit').css({opacity: 0.5});


	$(".rounded-carousel img").each(function() {
		$(this).wrap('<span class="rounded-img" style="background:url(' + escape($(this).attr('src')) + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />');
		$(this).css({display: 'none'});
	});

});

/**
 * Handle Video Clicks
 */
$(function(){

	$('BODY').append('<div style="display:none" id="video"></div>').append('<a href="#video" id="videoLink" />');
	$('a.videolightbox[href*="youtube.com/"]').click(function(evt) {
		var videoTitle = $(this).attr('title');
		var matches = $(this).attr('href').match(/v=([^&]+)/);
		if (matches) {
			var id = matches[1];
			$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
					onStart:function(){
						$('#video').html('<object width="480" height="397"><param name="movie" value="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"><param name="bgcolor" value="#000000"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" bgcolor="#000000" allowfullscreen="true" width="480" height="397"></embed></object>').css({display: 'block', 'padding-bottom': '20px'});
					},
					onCleanup:function() {
						$('#video').empty();
					},
					onComplete:function(){
						$('#fancybox-title').css({bottom: '-3px', left: '0px'});
					},
					zoomSpeedIn:400,
					zoomSpeedOut:400,
					width:480,
					height:417,
					title: videoTitle,
					transitionIn: 'fade',
					transitionOut: 'fade',
					overlayShow: true,
					overlayColor: '#000',
					overlayOpacity: 0.8,
					hideOnContentClick:false
				}).trigger('click');
			return false;
		}
	});

	$('a.clearvideo[href*="youtube.com/"]').click(function(evt) {
		var matches = $(this).attr('href').match(/v=([^&]+)/);
		var videoTitle = $(this).attr('title');
		if (matches) {
			var id = matches[1];
			$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
					onStart:function(){
						$('#video').html('<object width="480" height="397"><param name="movie" value="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"><param name="bgcolor" value="#000000"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/'+id+'&hl=en&fs=1&rel=0&autoplay=1&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" bgcolor="#000000" allowfullscreen="true" width="480" height="397"></embed></object>').css({display: 'block', 'padding-bottom': '20px'});
					},
					onComplete:function(){
						$('#fancybox-title').css({bottom: '-3px', left: '0px'});
					},
					onCleanup:function() {
						$('#video').empty();
					},
					zoomSpeedIn:400,
					zoomSpeedOut:400,
					width:480,
					height:417,
					title: videoTitle,
					transitionIn: 'elastic',
					transitionOut: 'elastic',
					overlayShow: false,
					centerOnScroll: false,
					hideOnContentClick:false
				}).trigger('click');
			return false;
		}
	});

	$('a.videolightbox').click(function(evt){

		var videoDetails = $(this).metadata({type:'attr', name:'data'});
		videoDetails.url = $(this).attr('href');
		videoDetails.title = $(this).attr('title');

		var flashvars = {
			autostart:'true', repeat:'false',
			width:videoDetails.width,
			height:videoDetails.height,
			file:videoDetails.url
		};

		$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
			onStart:function(){
				$('#video').html('<div id="fancy_video"></div>').css({display: 'block', height: videoDetails.height+20, width: videoDetails.width});
				swfobject.embedSWF("flash/player.swf", "fancy_video", videoDetails.width, videoDetails.height, "9.0.0","flash/expressInstall.swf", flashvars);
			},
			onComplete:function(){
				$('#fancybox-title').css({bottom: '-3px', left: '0px'});
			},
			onCleanup:function() {
				$('#video').empty().hide();
			},
			zoomSpeedIn:400,
			zoomSpeedOut:400,
			width:480,
			height:397,
			transitionIn: 'fade',
			transitionOut: 'fade',
			overlayShow: true,
			title: videoDetails.title,
			overlayColor: '#000',
			overlayOpacity: 0.8,
			hideOnContentClick:false
		}).trigger('click');
		return false;
	});
	$('a.clearvideo').click(function(evt){
		var videoDetails = $(this).metadata({type:'attr', name:'data'});
		videoDetails.url = $(this).attr('href');
		videoDetails.title = $(this).attr('title');
		var flashvars = {
			autostart:'true', repeat:'false',
			width:videoDetails.width,
			height:videoDetails.height,
			file:videoDetails.url
		};

		$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
			onStart:function(){
				$('#video').html('<div id="fancy_video"></div>').css({display: 'block', height: videoDetails.height+20, width: videoDetails.width});
				swfobject.embedSWF("/USQ/FutureStudents/flash/player.swf", "fancy_video", videoDetails.width, videoDetails.height, "9.0.0","/USQ/FutureStudents/flash/expressInstall.swf", flashvars);
			},
			onComplete:function(){
				$('#fancybox-title').css({bottom: '-3px', left: '0px'});
			},
			onCleanup:function() {
				$('#video').empty().hide();
			},
			zoomSpeedIn:400,
			zoomSpeedOut:400,
			width:480,
			height:397,
			transitionIn: 'fade',
			transitionOut: 'fade',
			overlayShow: true,
			title: videoDetails.title,
			overlayColor: '#000',
			overlayOpacity: 0.8,
			hideOnContentClick:false
		}).trigger('click');
		return false;
	});



	// hack for menu
	$('#futurestudentsmenu A').each(function() {
		if ($(this).height() > 20) { // 20 is just number between 16 and 30 to account for slight differences in browsers with font sizing
			if ($(this).height() > 30) {
				$(this).addClass('three-lines');
				$(this).css({height:'44px'}); // set height afterwards!
			} else {
			$(this).addClass('two-lines');
			$(this).css({height:'30px'}); // set height afterwards!
			}
		} else {
			$(this).css({height:'16px'}); // set height afterwards!
		}
	});


});
