//Maintain open state of menu after end user has made a selection
//This snippet came from http://www.i-marco.nl/weblog/jquery-accordion-menu-redux2/

function initMenus() {
	$('ul.smenu ul').hide();
	$.each($('ul.smenu'), function(){
		var cookie = $.cookie(this.id);
		if(cookie === null || String(cookie).length < 1) {
			$('#' + this.id + '.expandfirst ul:first').show();
		}
		else {
			$('#' + this.id + ' .' + cookie).next().show();
		}
	});
	$('ul.smenu li a').click(function() {
		var checkElement = $(this).next();
		var parent = this.parentNode.parentNode.id;
	
		if($('#' + parent).hasClass('noaccordion')) {
			if((String(parent).length > 0) && (String(this.className).length > 0)) {
				if($(this).next().is(':visible')) {
					$.cookie(parent, null,{path:'/'});
				}
				else {
					$.cookie(parent, this.className,{path:'/'});
				}
				$(this).next().slideToggle('normal');
			}
		}
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			if($('#' + parent).hasClass('collapsible')) {
				$('#' + parent + ' ul:visible').slideUp('normal');
			}
			return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#' + parent + ' ul:visible').slideUp('normal');
			if((String(parent).length > 0) && (String(this.className).length > 0)) {
				$.cookie(parent, this.className,{path:'/'});
			}
			checkElement.slideDown('normal');
			return false;
		}
	});
}

$(document).ready(function() {
	// replace the sfHover function above in jQuery
	$("#nav-sitelist").find("li").mouseover(function () {
		$(this).addClass("sfhover");
	}).mouseout(function() {
		$(this).removeClass("sfhover");
	});
	
	// add .last for browsers that don't support last-child selector
	$("#nav-secondary ul li ul li:last-child").addClass('last');

	// Expanding only the active menu, which is determined by the class name
	//$("#smenuTop1").find("+ ul").slideToggle("medium");

	//$('.smenu').hide();

	initMenus(); // left navigation accordion


	$('#newsitem02').hide();
	$('#newsitem03').hide();
	$('#newsitem04').hide();
	
		
	$('#newslink03').hover(
		function() {
			$('.newsitem').hide();
			$('#newsitem03').show();
		},
		function() {
			$('#newsitem03').show();	
		}
	);
	
	$('#newslink02').hover(
		function() {
			$('.newsitem').hide();
			$('#newsitem02').show();
		},
		function() {
			$('#newsitem02').show();	
		}
	);
	
	$('#newslink01').hover(
		function() {
			$('.newsitem').hide();
			$('#newsitem01').show();
		},
		function() {
			$('#newsitem01').show();	
		}
	);

	/* Generic Tabs trigger */
	$('.tabs').each(function(){
		var id = $(this).attr('id'); // .tabs wrapper must also have a unique ID for cookie
		$(this).tabs({
			cookie: {
				expires: 1,
				name: id + '-tabs'
			}
		});
	});
	$(".tabs .ui-tabs-nav li:last").addClass('last');
	
	/* Autofill Search field */
	$('#search #q2').autofill({
		value: 'Search Terry website',
		defaultTextColor: '#555',
		activeTextColor: '#333'
	}).attr('autocomplete','off');
	
	$('#UGABrandingBar #qsearch').autofill({
		value: 'Search UGA website',
		defaultTextColor: '#C5C5C5',
		activeTextColor: '#fff'
	});
	
	//	 //Toggling the selected menu's class and expand or collapse the menu
	//	$("#udm > li > a").click(function() {
	//		$(this).toggleClass("expanded").toggleClass("collapsed").find("+ ul").slideToggle("medium");
	//		return false;
	//	});
	//
	//
});

$(document).ready(function(){

/***********************************************************
                       Banner Videos
***********************************************************/

$('#M1 #slideshow1').flash({
	src: '/flash/iamterry/homeIAmTerry1.0.swf',
	width: 750,
	height: 260,
	wmode: "transparent"
},{ update: false });
	
$('#M1 #deans_welcome').flash({
	src: '/_assets/swf/video_dean_home.swf',
	width: 640,
	height: 410,
	wmode: "transparent"
},{ update: false });

$('#M4 #alumni_banner').flash({
	src: '/_assets/swf/bnr_alumni.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #entrepreneurship_banner').flash({
	src: '/_assets/swf/bnr_entrepreneurship.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #atlanta_banner').flash({
	src: '/atlanta/flash/atlantaHome.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #hireterry_banner').flash({
	src: '/_assets/swf/bnr_hireterry.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
/*$('#M2 #economics_banner').flash({
	src: '/_assets/swf/bnr_economics.swf',
	width: 767,
	height: 110,
	wmode: "transparent"
},{ update: false });*/
	
$('#M4 #gala_banner').flash({
	src: '/_assets/swf/bnr_gala.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #ib_banner').flash({
	src: '/_assets/swf/bnr_ib.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #leadership_banner').flash({
	src: '/_assets/swf/bnr_leadership.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M11 #mbaprog_banner').flash({
	src: '/_assets/swf/bnr_mba_fulltime.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #musicbusiness_banner').flash({
	src: '/_assets/swf/bnr_musicbusiness.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #phd_banner').flash({
	src: '/_assets/swf/bnr_phd.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #selig_banner').flash({
	src: '/_assets/swf/bnr_selig.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });
	
$('#M4 #undergraduate_banner').flash({
	src: '/_assets/swf/bnr_undergraduate.swf',
	width: 767,
	height: 259,
	wmode: "transparent"
},{ update: false });

/***********************************************************
                      Major Decision Videos
***********************************************************/

$('#M5 #video_accounting').flash({
	src: '/_assets/swf/video_majors_ben.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_finance').flash({
	src: '/_assets/swf/video_majors_annette.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_dean').flash({
	src: '/_assets/swf/video_majors_dean.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_diversity').flash({
	src: '/_assets/swf/video_majors_randy.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_economics').flash({
	src: '/_assets/swf/video_majors_chris.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_ib').flash({
	src: '/_assets/swf/video_majors_myra.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });


$('#M5 #video_management').flash({
	src: '/_assets/swf/video_majors_allen.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_marketing').flash({
	src: '/_assets/swf/video_majors_peggy.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_mis').flash({
	src: '/_assets/swf/video_majors_rick.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_realestate').flash({
	src: '/_assets/swf/video_majors_henry.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_rmi').flash({
	src: '/_assets/swf/video_majors_robert.swf',
	width: 320,
	height: 285,
	wmode: "transparent"
},{ update: false });


/***********************************************************
                       I Am Terry Videos
***********************************************************/


$('#M5 #video_iamterry_akinkuowo').flash({
	src: '/_assets/swf/video_akinkuowo.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_amacher').flash({
	src: '/_assets/swf/video_amacher.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_barksdale').flash({
	src: '/_assets/swf/video_barksdale.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_bartlett').flash({
	src: '/_assets/swf/video_bartlett.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_bauer').flash({
	src: '/_assets/swf/video_bauer.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_beggerly').flash({
	src: '/_assets/swf/video_beggerly.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_boudreau').flash({
	src: '/_assets/swf/video_boudreau.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_callaway').flash({
	src: '/_assets/swf/video_callaway.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_davis').flash({
	src: '/_assets/swf/video_davis.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_devore').flash({
	src: '/_assets/swf/video_devore.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_dillard').flash({
	src: '/_assets/swf/video_dillard.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_frazier').flash({
	src: '/_assets/swf/video_frazier.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_glover').flash({
	src: '/_assets/swf/video_glover.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_graham').flash({
	src: '/_assets/swf/video_graham.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_jacobo').flash({
	src: '/_assets/swf/video_jacobo.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_jakstadt').flash({
	src: '/_assets/swf/video_jakstadt.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_jarrell').flash({
	src: '/_assets/swf/video_jarrell.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_omeara').flash({
	src: '/_assets/swf/video_omeara.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_otu').flash({
	src: '/_assets/swf/video_otu.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_pruiett').flash({
	src: '/_assets/swf/video_pruiett.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_reddy').flash({
	src: '/_assets/swf/video_reddy.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_skinner').flash({
	src: '/_assets/swf/video_skinner.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_sumichrast').flash({
	src: '/_assets/swf/video_sumichrast.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_thompson').flash({
	src: '/_assets/swf/video_thompson.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_thrower').flash({
	src: '/_assets/swf/video_thrower.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_veliyath').flash({
	src: '/_assets/swf/video_veliyath.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_white').flash({
	src: '/_assets/swf/video_white.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #video_iamterry_yoshimura').flash({
	src: '/_assets/swf/video_yoshimura.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });


/***********************************************************
                       Music Business Videos
***********************************************************/

$('#M5 #mbus_promo').flash({
	src: '/musicbusiness/flash/mbus_promo.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });

$('#M5 #mbus_showcase').flash({
	src: '/musicbusiness/flash/mbus_showcase.swf',
	width: 500,
	height: 330,
	wmode: "transparent"
},{ update: false });


/***********************************************************
                       Full-Time MBA Videos
***********************************************************/

$('#M13 #mba_realestate_banner').flash({
	src: '/_assets/swf/video_barnett.swf',
	width: 767,
	height: 431,
	wmode: "transparent"
},{ update: false });

$('#M13 #mba_recruiting_banner').flash({
	src: '/_assets/swf/video_hammann.swf',
	width: 767,
	height: 431,
	wmode: "transparent"
},{ update: false });

$('#M13 #mba_operations_banner').flash({
	src: '/_assets/swf/video_jackson.swf',
	width: 767,
	height: 431,
	wmode: "transparent"
},{ update: false });

$('#M11 #mba_directors_welcome').flash({
	src: '/_assets/swf/video_daniels.swf',
	width: 640,
	height: 410,
	wmode: "transparent"
},{ update: false });


/***********************************************************
                       Other Flash Videos
***********************************************************/

$('#M5 #video_smif').flash({
	src: '/_assets/swf/video_smif.swf',
	width: 500,
	height: 281,
	wmode: "transparent"
},{ update: false });

/* $('#M5 #anim_convocation').flash({
	src: '/_assets/swf/anim_convocation.swf',
	width: 230,
	height: 300,
	wmode: "transparent"
},{ update: false }); */

/***********************************************************
                     Extend Google Analytics
***********************************************************/

// Track tab selections
if ($(".tabs").length != 0) {
	$(".tabs").bind("tabsselect",function(event,ui) {
		protocol = window.location.protocol;
		host = window.location.host;
		tab_anchor = new String(ui.tab.href).replace(protocol + '//' + host, '');
		_gaq.push(['_trackPageview', tab_anchor]);
		//console.log(tab_anchor);
	});
}

var filetypes = /\.(zip|gzip|exe|pdf|doc*|xls*|ppt*|mp3|mp4|mov|avi|vcf)$/i;

$('a').each(function(){
	if ($(this).attr('href') !== undefined) {
		var href = $(this).attr('href');
	
		if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
			$(this).click(function() {
				var extLink = href.replace(/^https?\:\/\//i, '');
				_gaq.push(['_trackEvent','External', 'Click', extLink]);
			});
		}
		else if (href.match(/^mailto\:/i)){
			$(this).click(function() {
				var mailLink = href.replace(/^mailto\:/i, '');
				_gaq.push(['_trackEvent', 'Email', 'Click', mailLink]);
			});
		}
		else if (href.match(filetypes)){
			$(this).click(function() {
				var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
				var filePath = href.replace(/^https?\:\/\/(www.)terry\.uga\.edu\//i, '');
				_gaq.push(['_trackEvent', 'Download', 'Click - ' + extension, filePath]);
			});
		}
	} else {
	}
});

$('#nav-site a').each(function(){
	var href = $(this).attr('href');
	$(this).click(function() {
		var pagePath = href.replace(/^https?\:\/\//i, '');
		_gaq.push(['_trackEvent', 'Navigation - Main', 'Click', pagePath])
	});
});

$('#site-info a').each(function(){
	var href = $(this).attr('href');
	$(this).click(function() {
		var pagePath = href.replace(/^https?\:\/\//i, '');
		_gaq.push(['_trackEvent', 'Footer', 'Click', pagePath])
	});
});

$('#nav-secondary a').each(function(){
	var href = $(this).attr('href');
	if (href != "#"){
		$(this).click(function() {
			var pagePath = href.replace(/^https?\:\/\//i, '');
			_gaq.push(['_trackEvent', 'Navigation - Secondary', 'Click', pagePath])
		});
	}
});

$('#ugabar a').each(function(){
	var href = $(this).attr('href');
	$(this).click(function() {
		var pagePath = href.replace(/^https?\:\/\//i, '');
		_gaq.push(['_trackEvent', 'UGA Branding Bar', 'Click', pagePath])
	});
});

}); /* Close tag for the function */
