
/* navigation */
var mainNav = null;
var mainNavHeights = null;
var currOpen = null;
var saddrText = 'Enter starting address';
//var navTop = 40;
var navHt = 15;
var navOpenSpd = 250;
var navCloseSpd = 100;

function registerNavs(){
	for( var i in mainNav ) registerNav( mainNav[i] );
}

function registerNav( which ){
	var thisNav = $('#nav_'+which);
	thisNav.hoverIntent( 
		function(){
			if( currOpen != which )
				$( '#subnav_'+which ).animate( { top: '-' + mainNavHeights[which] + 'px', height: mainNavHeights[which] + 'px' }, navOpenSpd, null, fixOverflow(which,'visible') );
		},
		function(){
			if( currOpen != which )
				$( '#subnav_'+which ).animate( { top: '0px', height: '15px' }, navCloseSpd, null, fixOverflow(which,'hidden') );
		}
	)
}

function fixOverflow( which, visible ){
	$('#subnav_'+which).css( "overflow", visible );
}

function openNav( which ){
    if (which == '' || mainNavHeights[which] == null) return;
	subNav = $('#subnav_'+which);
	subNav.css( "top","-" + mainNavHeights[which] + "px" );
	subNav.css( "height", mainNavHeights[which] + "px" );
	fixOverflow( which, "visible" )
}

/* landing page images, tiles */

function registerMainImg(){
	$('#mainImg').hoverIntent(
		function(){
			$('#mainImgTxt').fadeIn();
		},
		function(){
			$('#mainImgTxt').fadeOut();
		}
	);
}

function registerTiles() {
    //old tiles:
	var tileBase = '/images/tiles/';
	$('img.tile').hover(
		function(){
			this.src = tileBase + this.id + '_OVER.gif';
		},
		function(){
			this.src = tileBase + this.id + '_ON.gif';
		}
	);
	//new tiles:
	$('div.promoTile').each(function() {
	    $(this).mouseover(function() {
	        $(this).find('table').show();
	        $(this).find('img').hide();
	    }).mouseout(function() {
	        $(this).find('table').hide();
	        $(this).find('img').show();
	    });
	    $(this).click(function() {
	        location.href = $(this).find('a').attr('href');
	    });
	});
}

function watchVideo(){
    var width = 480;
    var height = 360;
    var controlHeight = 38;
    window.open('/video/default.aspx','videoWin','width='+width+',height='+ (height+controlHeight) +',scrollbars=no');
    return false;
}

/* google map */

function dirInput( dirLink ){
	$('#dirLink').html( '<input type="text" value="' + saddrText + '" id="saddr" name="saddr" class="txt"> <input type="submit" value=" Go " class="btn">' );
	$('#saddr').select();
	return false;
}

function validateAddr(){
	if( $('#saddr').val() == saddrText || $('#saddr').val() == '' ){
		alert('Enter a starting address to continue.');
		return false;
	}
	return true;
}

function showLocInfo( which ){
	setCookie("showLoc",which)
	
	var dir = '<span id="dirLink"><a href="#" onclick="return dirInput(this.parentNode)">Get Directions</a></span>';
	$('#daddr').val(locs_daddr[which]);
	map.closeInfoWindow();
	map.panTo( locs[which] );
	map.openInfoWindowHtml( locs[which], '<p>'+locs_info[which]+'</p>'+dir );
	$('#mapinfoDefault').hide();
	$('#bodyDefault').hide();
	$('div.locinfo').hide();
	map.removeOverlay( markers['TyeeCampus'] );
	map.removeOverlay( markers['AdministrativeOffice'] );
	if( which == 'TyeeCampus' ){
		var tyeeMarker = new GMarker(locs[which],locs_icons[which]);
		map.addOverlay( tyeeMarker );
		markers['TyeeCampus'] = tyeeMarker;
		$('#feesInsTyee').fadeIn();
		$('#feesIns').hide();
	}
	else if( which == 'AdministrativeOffice' ){
		var adminMarker = new GMarker(locs[which],locs_icons[which]);
		map.addOverlay( adminMarker );
		markers['AdministrativeOffice'] = adminMarker;
		$('#feesInsTyee').hide();
		$('#feesIns').fadeIn();
	}
	else{
		$('#feesInsTyee').hide();
		$('#feesIns').fadeIn();
	}
	$('#returnLink').fadeIn();
	$('#mapinfo_'+which).fadeIn();
	return false;
}

var markers = new Array();
function createMarker( which ){
	var marker = new GMarker(locs[which],locs_icons[which]);
	if( which == 'TyeeCampus' ) mgr.addMarker( marker, 13 );
	else if( which == 'AdministrativeOffice' ) mgr.addMarker( marker, 10 );
	else map.addOverlay( marker );
	GEvent.addListener( marker, "click", function(){showLocInfo(which)} );
	markers[ which ] = marker;
}

function initMap(){
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.enableScrollWheelZoom();
		map.addControl(new GSmallMapControl());
		map.setCenter(loc_default, map_default_zoom);
		mgr = new MarkerManager(map);
		for( var i in locs) createMarker( i );
		mgr.refresh()
	}
	if( getCookie("showLoc") != "" ){
		showLocInfo( getCookie("showLoc") );
	}
}

function resetMap(){
	setCookie("showLoc","");
	$('#returnLink').fadeOut();
	$('div.locinfo').fadeOut();
	$('.bodyExtra').hide();
	$('#mapinfoDefault').fadeIn();
	$('#bodyDefault').fadeIn();
	map.closeInfoWindow();
	map.setCenter(loc_default, map_default_zoom);
	map.removeOverlay( markers['TyeeCampus'] );
	map.removeOverlay( markers['AdministrativeOffice'] );
	
	return false;
}

/* utilities */
function closeWin(){
	if( window.opener == undefined )
		location.href='../'; //alert('same win, go up one level');
	else
		window.close();
	return false;
}


$(document).ready(
	function(){
		//
	}
)


function getCookie(c_name){
	if (document.cookie.length>0) {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1){ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

/* css browser selector */
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
