/*
* file: broadcastschedule.js
* date: 11/9/2007
* created by: Alicia Persaud
*/

var Timer;

// submit form and either add or subtract 6 hours to schedule start time.
function moveSchedule(direction) {
	var finaltime = document.schedform.timeselectbox.value;
	if(direction=="left"){
		finaltime = parseFloat(finaltime) - 6;
		if(finaltime < 0) {
			finaltime = 0;
		}
	} else {
		finaltime = parseFloat(finaltime) + 6;
		if(finaltime > 18) {
			finaltime = 18;
		}
	}
	document.schedform.timeselectbox.value = finaltime;
	document.schedform.submit();
	
}

function ScrollLeft(){
  Timer = setInterval("document.getElementById('schedulediv').scrollLeft -= 15", 15);
}//end ScrollLeft()

function ScrollRight(){
  Timer = setInterval("document.getElementById('schedulediv').scrollLeft += 15", 15);
}//end ScrollRight()

function setTimeFrame(type, selectedtime){ 
/*works for Firefox and IE 6.x*/
var anchorObject = document.getElementById(selectedtime);
var xpos = FindPosition(anchorObject); 
var scroll = xpos[0];

switch(type){
  case 'full': document.getElementById('schedulediv').scrollLeft=scroll-125;break;
  case 'tv': document.getElementById('schedulediv').scrollLeft=scroll-135; break;
  case 'radio': document.getElementById('schedulediv').scrollLeft=scroll-135; break;
  default:break;
}
/*Uses smooth scrolling function - a bit buggy b/c causes schedule to timeout*/
//doScroll((anchorObject.x-100), anchorObject.y, 20); 
}// end setTimeFrame()


 // Figure out where the object is on the screen by adding  
 // up all the offsets for all the containing parent objects 
 function FindPosition(obj) {  
 // Assign the obj object to a temp variable  
 tmpObj = obj;  
  
 // Get the offsets for the current object  
 var obj_left = tmpObj.offsetLeft;  
 var obj_top = tmpObj.offsetTop;  
   
   // If the current object has a parent (ie contained in a table, div, etc..)  
   if (tmpObj.offsetParent) {  
     
     // Loop throw all the parents and add up their offsets  
     // The while loop will end when no more parents exist and a null is returned  
     while (tmpObj = tmpObj.offsetParent) {  
     obj_left += tmpObj.offsetLeft;  
     obj_top += tmpObj.offsetTop;  
     }  
   }  
 return [obj_left , obj_top];  
 }

/*Smooth scrolling function*/
      function scrollTo(id)
      {
        var obj = document.getElementById(id);        
        var objPos = {'x':obj.offsetLeft, 'y':obj.offsetTop};
        
        doScroll(objPos.x, objPos.y, 5);
      }

      function doScroll(x, y, xSpeed, ySpeed)
      {
        if (typeof ySpeed == 'undefined') ySpeed = xSpeed;

        //var scrollObject = document.documentElement;
        var scrollObject = document.getElementById('schedulediv');
        var currentScroll = {'x':scrollObject.scrollLeft, 'y':scrollObject.scrollTop};
        var newX, newY;
        
        // calculate the new scroll position
        newX = currentScroll.x < x ? currentScroll.x + xSpeed : currentScroll.x - xSpeed;
        newY = currentScroll.y < y ? currentScroll.y + ySpeed : currentScroll.y - ySpeed;

        // check if we've got to the position specified by x & y
        if (newX == x || newX < x && currentScroll.x > x || newX > x && currentScroll.x < x)
        {
          newX = x;
          xSpeed = 0;
        }       
        if (newY == y || newY < y && currentScroll.y > y || newY > y && currentScroll.y < y)
        {
          newY = y;
          ySpeed = 0;
        }       

        // set the scroll
        scrollObject.scrollLeft = newX;
        scrollObject.scrollTop = newY;

        // check if we've hit the scroll extents
        if (scrollObject.scrollLeft != newX) xSpeed = 0;
        if (scrollObject.scrollTop != newY) ySpeed = 0;

        if (xSpeed || ySpeed) setInterval("doScroll(" + x + "," + y + "," + xSpeed + "," + ySpeed + ");", 20);
      }


function toggleChannel(elem1, elem2){
  var display = document.getElementById(elem1).style.display;
  var display2 = document.getElementById(elem2).style.display;
  if(display=="none"){
		document.getElementById(elem1).style.display="block";
  }
  else{
    document.getElementById(elem1).style.display="none";
  }
  
  if(display2=="none"){
       document.getElementById(elem2).style.display="block";
  }
  else{
      document.getElementById(elem2).style.display="none";
  }

}