/* 
	Tacita Morway
	04.10.09

   ----------------------------------------------------*/

   
function toggleNav() {

	// hide everything that isn't this page
	var currentUrl = window.location + "";

	// if there are any variables in the url, get rid of them first
	if (currentUrl.indexOf('?') != -1) {
		var splitUrl = currentUrl.split("?");
		currentUrl = splitUrl[0];
	}

	// todo: remove the ds3 check
	if (currentUrl.indexOf('designsquad3/') != -1) {
		var parsedUrl = currentUrl.split("/designsquad3/");
	} else {
		var parsedUrl = currentUrl.split("/designsquad/");
	}
	
	// top level category set by developer in HTML on a per/page basis by adding a class to #nav
	var openSection = $('#nav').attr('className');		
	
	// 1) hide all sections 
	// 2) add on click behavior to headers in nav - onlf if it has no children (ie. is not a link itself like for "projects")
	// onclick behavior is: hide any visible sections > reveal clicked section
	$('#primary-nav', this).find('div').hide().end().find('h3:not(:has(*))').click(function() {
		$('div:visible').prev().removeClass('open');
		$(this).addClass('open').next().addClass('open').siblings('div:visible').hide('fast').end().animate({height: 'show', opacity: 'show'}, "slow", "easeOutQuad").end();
	});

	// open and highlight current page section
	$('#nav h3[class=' + openSection + ']').addClass('open').next().addClass('open').show().end().addClass('nav-on').end();

	// highlight current page
	$('#nav a[href$=' + parsedUrl[1] + ']').parent().addClass('nav-li-on');

	// EXCEPTION: the current page was not found in the nav, indicating that the user is viewing a sub page within a section
	// ex. /designsquad/parentseducators/program/episode_descriptions.html
	if (!$('li.nav-li-on > a').text()) {
		// match the path in the url to the appropriate link in the nav  
		var newParsedUrl = parsedUrl[1].split("/");
		var stringToMatch = newParsedUrl[0] + "/" + newParsedUrl[1] + "/";
		$('#nav a[href*=' + stringToMatch + ']').parent().addClass('nav-li-on');
		
	}

}

$(document).ready(toggleNav);




 //////////////////////////////////////////////////////// Daniel Bulli
	function openWin(URL,type,w,h) {
	
	var status = 'no';
	var reSize = 'no';
	var scroll = 'no';
	var toolbar = 'no';
	var location = 'no';
	var menubar = 'no';
	var directories = 'no';
	var ewindow;
	
	
	
	if (type == "vid") {
		if (!w) {
			w = 570;
		}
		if (!h) {
			h= 510;
		}
		reSize = 'no';		
	} 	

	else if (type == "aud") {
		if (!w) {
			w = 570;
		}
		if (!h) {
			h= 350;
		}
		reSize = 'no';		
	} 	
	
	else if (type == "pv") {
		if (!w) {
			w = 550;
		}
		if (!h) {
			h= 415;
		}
		reSize = 'no';		
		scroll = 'no';		
	} 	

	else if (type == "int") {
		if (!w) {
			w = 680;
		}
		if (!h) {
			h= 500;
		}
		reSize = 'no';		
		scroll = 'no';		
	} 	
	
	else {
		if (!w) {
			w = 350;
		}
		if (!h) {
			h= 360;
		}
		reSize = 'yes';		
	} 	
	
	var windowFeatures = 'width='+w+',height='+h+
									',toolbar='+toolbar+',status='+status+
									',scrollbars='+scroll+',resizable='+reSize+
									',menubar='+menubar+
									',location='+location+
									',directories='+directories+''
									
	ewindow = window.open(URL,type,windowFeatures);   
	ewindow.focus();
}

