/*RUN ON LOAD*/
$(document).ready(function() {
	/*External Links*/
	$('a[rel="external"]').attr('target','_blank');
	
	/*Main Navigation Bar*/
	$('#nav li.animate a')
		.css({backgroundPosition: "80px 0"})
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"(-135px 0)"}, 
				{duration:500}
			);
		})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"(80px 0)"},
				{duration:500, complete:function(){
					$(this).css({backgroundPosition: "80px 0"});
				}}
			);
		});

	/*Page-Specific Functions*/
	var path = document.location.pathname.split('/');
	if(path[1] == 'home.php') {
		$("div#networks").smoothDivScroll({
			scrollingSpeed: 7,
			autoScroll: "always",
			autoScrollDirection: "endlessloop",
			pauseAutoScroll: "mouseover"
		});
		$('#home-images').cycle({
			fx: 'fade',
			sync: true,
			delay: 200,
			timeout: 5500
		});
	} else if(path[1] == 'about') {
		$('#about li.ani a')
			.css({backgroundPosition: "0px 0"})
			.mouseover(function(){
				$(this).stop().animate(
					{backgroundPosition:"(-200px 0)"}, 
					{duration:500}
				);
			})
			.mouseout(function(){
				$(this).stop().animate(
					{backgroundPosition:"(0px 0)"},
					{duration:500, complete:function(){
						$(this).css({backgroundPosition: "0px 0"});
					}}
				);
			});
		if(path[2] == 'news-press') {
			$("#news-article").jScrollPane({ });
		}
	} else if(path[1] == 'facilities') {
		$('#facilities-images').cycle({
			fx: 'fade',
			sync: true,
			delay: 200,
			timeout: 5500
		});
	} else if(path[1] == 'productions') {
		$("#productions-list").jScrollPane({ });
	}
});

/* --- Show Season nav on rollover */

function theSeasons(status) {
	/*for (var i = 1; i < 3; i++) {
		var theLink = document.getElementById('nav-season-' + i);
		var theHref = theLink.getElementsByTagName("A");
		if ((theHref[1].id != 'on') && (theHref[2].id != 'on')) {*/
			document.getElementById('navbar-seasons').style.display = status;
		/*} else {
			alert(theHref[1].id + ' and ' + theHref[2].id);
		}
	}*/
}

/* --- Show Episode subnav on click */

function showEpisodes(season) {
	var theNav = document.getElementById('nav-episodes');
	var theNavButton = theNav.getElementsByTagName("A");
	theNavButton[0].id = 'current';
	for (var i = 1; i < 3; i++) {
		var theLink = document.getElementById('nav-season-' + i);
		var theHref = theLink.getElementsByTagName("A");
		//alert(theHref[0].id);
		var theDiv = document.getElementById('episodes-s' + i);
		if (i == season) {
			theDiv.style.display = '';
			theHref[0].id = 'on';
		} else {
			theDiv.style.display = 'none';
			theHref[0].id = '';
		}
		alert('the id is ' + theLink.childNodes(0).id);
	}
}

/* --- Show Season Nav & Episode Listings on click */

function showItAll() {
	theSeasons('');
	showEpisodes(1);
}
