// Values for manipulating the motion-tween effect on the subnavigation menu.
var speed = 20;
var navlock = null;
var subheight = 0;
var maxheight = 33;

// Determines the pixel off-set of sub-navigation link items.
function findpadding ( section ) {
   switch ( section ) {
      case 'about' :
         return 100;
      break;

      case 'news' :
         return 100;
      break;
	  
	  case 'document' :
         return 400;
      break;
	  
	  case 'clases' :
         return 123;
      break;
	  
	  case 'galeria' :
         return 125;
      break;
	  
	  case 'revista' :
         return 320;
      break;
	  
	  case 'exalumnes' :
         return 605;
      break;
   }
}

// Swap out navigation items on moust-out (mouse-over effects are handled by the display function).
/*function swap ( section, action ) {
   var linkimage = new Image();
   navitem = document.getElementById ( section + 'nav' );

   if ( navitem.className.indexOf ( 'currentsection' ) != 0 ) {
      if ( action == 'out' ) {
         linkimage.src = '/images/' + section + '.gif';
      }

      else {
         linkimage.src = '/images/' + section + '.gif';
      }

      navitem.src = linkimage.src;
   }
}*/

function unswapall () {
   var navigation = new Array ( 'about', 'news','document','clases','galeria','revista','exalumnes' );
   var i = 0;
   while ( navigation[i] ) {
      //swap ( navigation[i], 'out' );
      i++;
   }
}

// Handles the actual motion effects on the sub-navigation.
function collapse ( action ) {
   subnav = document.getElementById ( 'subnavigation' );
   if ( action == 'show' ) {
      if ( ( subheight != maxheight ) && ( navlock != 'h' ) ) {
         navlock = 's';
         subnav.style.display = 'block';
         subnav.style.height = 0;
      }

      if ( navlock == 's' ) {
         if ( subheight < maxheight ) {
            subheight = subheight + 3;
            subnav.style.height = subheight + 'px';
            setTimeout ( "collapse ( 'show' )", speed );
         }

         else {
            subheight = maxheight;
            subnav.style.height = subheight + 'px';
            navlock = null;
         }
      }
   }

   else {
      if ( ( subheight != 0 ) && ( navlock != 's' ) ) {
         navlock = 'h';
         hideall ();
      }

      if ( navlock == 'h' ) {
         if ( subheight > 0 ) {
            subheight = subheight - 3;
            subnav.style.height = subheight + 'px';
            setTimeout ( "collapse ( 'hide' )", speed );
         }

         else {
            unswapall ();
            subheight = 0;
            subnav.style.height = subheight + 'px';
            subnav.style.display = 'none';
            navlock = null;
         }
      }
   }
}

// Ensures that the navigation does not collapse while being used.
function textlock () {
   if ( ( navlock != 's' ) && ( navlock != 'h' ) ) {
      navlock = 's';
   }
}

// Unlock the sub-navigation when it is no longer needed.
function textunlock () {
   navlock = null;
}

// Content must be cleared from the sub-navigation before effects can be used.
function hideall () {
   var navigation = new Array ( 'about', 'news','document','clases','galeria','revista','exalumnes' );
   var i = 0;
   while ( navigation[i] ) {
      navitem = document.getElementById ( navigation[i] );
      navitem.style.display = 'none';
      i++;
   }
}

// Timer that determines the duration before the sub-navigation collapses.
function hide () {
   setTimeout ( "collapse ( 'hide' )", 2000 );
}

// Function called when using the global navigation.  Creates the hover-over image as well as initiating the collapse function.
function display ( section ) {
   unswapall ();
   //swap ( section, 'over' );

   hideall ();
   navitem = document.getElementById ( section );
   padding = findpadding ( section );
   navitem.style.paddingLeft = padding-100 + 'px';
   navitem.style.display = 'block';

   subnav = document.getElementById ( 'subnavigation' );
   if ( subheight != maxheight ) {
      collapse ( 'show' );
   }

   else {
      textlock ();
   }
}

// The following are only used on the Programs page.

// Swaps out the video image on rollover.
function vidrollover ( type ) {
   if ( document.images ) {
      var linkimage = new Image();
      if ( type == 'in' ) {
         linkimage.src = '/images/hoverfilm.gif';
      } else {
         linkimage.src = '/images/film.gif';
      }

      vidimage = document.getElementById ( 'vidimage' );
      vidimage.src = linkimage.src;
   }
}

// Produces the overlay effect when videos are presented.
function playvid () {
   video = document.getElementById ( 'video' ).style.display = 'block';
}


// opens popup window for the flv player
// @param vid Path or filename of the video asset *.flv
function getvid( vid , title){
	
	var _w = 515;
	var _h = 430;
	var _cX = (screen.width - _w) / 2;
	var _cY = (screen.height - _h) / 2;
	
	var _params = "resizable=0, location=0 scrollbars=no"+ ', ';
	_params += "width=" + _w + ', ';
	_params += "height=" + _h + ', ';
	_params += "screenX=" + _cX + ', ';
	_params += "screenY=" + _cY + ', ';
	
	_vidwin = window.open("/sciarc_player.html?vid=" + vid +"&title="+title,'sciarcvidplayer', _params);
	
	if (window.focus) { _vidwin.focus(); }

	
}



function getQueryString() {

	var res = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	
	for (var i=0; i<parms.length; i++) {
	
		var pos = parms[i].indexOf('=');
	
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			res[key] = val;
		}
	}
	
	return res;

}

// Stop the overlay effect when the close button is clicked.
function stopvid () {
   video = document.getElementById ( 'video' ).style.display = 'none';
}

function view_instructor ( faculty ) {
   var width = 550;
   var height = 650;
   var left = ( screen.availWidth / 2) - ( width / 2 );
   var top = ( screen.availHeight / 2 ) - ( height / 2 );

   window.open ( '../faculty/index.html', 'Insert', 'width=' + width + ',height=' + height + ', scrollbars=0,status=0,left=' + left + ',top=' + top );
}

function updateDivHeight( dcontainer , nheight ) {
    //alert(dcontainer);
	if(document.all && !document.getElementById) {
 		document.all[dcontainer].style.pixelHeight = nheight;
	}else{
		document.getElementById(dcontainer).style.height = nheight;
	}
}

function updateNewSideBarHeight( nheight ) {
	if(document.all && !document.getElementById) {
 		document.all['newSidebar'].style.pixelHeight = nheight;
	}else{
		document.getElementById('newSidebar').style.height = nheight;
	}
}

function view_instructor(id) {
	window.open("/faculty.php?id="+id,null,"height=640,width=509,status=yes,toolbar=auto,menubar=no,location=no");
}