// Workcast 

var d=document;				
var iContainer;  				// container for images		
var newPos = 0;	 				// scroll to position
var oldPos = 0;	 				// previous postion
var scrollNum;  				// max scroll distance
var l = new Object();          // left hand controller
var r = new Object();          // right hand controller
var imageArray; 				// how many images we are dealing with
var w;          				// width of images
var m;          				// rollover position
var dir;	
var num;					
var descriptions=new Array();


descriptions = ["In this informative, interactive webinar you will find out from industry expert Stewart Kibby on how webinars are helping organisations drive more leads.",
                "Webcasting for Recruitment - In this informative webcast you will find out how Webcast Manager is invigorating the recruitment process.",
                "Outsource or Insource your web events? WorkCast looks at the objectives of webinars, challenges to success, steps to a good webinar and return on investment.",
                "Chris Wilds from Communicator Corp talks about how WorkCast helped with his company's webcasting needs."]

var urls=new Array();

urls = ["http://view3.workcast.net/?paks=5737606124615832",
                "http://view3.workcast.net/?paks=6364941679418405",
                "http://view3.workcast.net/?paks=1351707238468350",
                "http://view3.workcast.net/?paks=9687393863345054"]

function addOnload(myfunc) {

	if(window.addEventListener)
		window.addEventListener('load', myfunc, false);
	else if(window.attachEvent)
		window.attachEvent('onload', myfunc);
}

addOnload(initialise);

function initialise() {
	
	iContainer = d.getElementById("imageContainer");
	imageArray =iContainer.getElementsByTagName('img');
	
	l=d.getElementById("scrollLeft");
	r=d.getElementById("scrollRight");
	
	l.num = 0;
	r.num = 0;
	
	l.onclick = function() {
		dir = 0;
		scrollObjects(dir);
	}
	
	r.onclick = function() { 
		dir = 1;
		scrollObjects(dir);
	}

	w = getW(imageArray[0]); // get width of a single image

	if (w<211) { 
	
		w+=9;
		
		m="-45";
	
	} else {
		
		w+=16; // add borders and padding
	
		m = "45"; // the rollovers for the arrows
	}
	
	
	scrollNum = ((imageArray.length-2)*w)*-1;
	
	r.onmouseover = function () {
		rollover(this, 1);
	}
	
	checkContainerPos();

}

function checkContainerPos() {
	
	var iCW = getW(iContainer);
	
	if (newPos==0) {
		l.style.filter = "alpha(opacity=50)";
		l.style.opacity = ".5";
		l.style.cursor = "default";
		if (l.num>0) l.onmouseover = null;
	} else {
		l.onmouseover = function () {
			l.num=1;
			rollover(this, 1);
		}
		
		l.onmouseout = function () {
			rollover(this, 0);
		}
		l.style.filter = "alpha(opacity=100)";
		l.style.opacity = "1";
		l.style.cursor = "pointer";
	}
	
	if (newPos==((imageArray.length-1)*w)*-1)  {
		r.style.filter = "alpha(opacity=50)";
		r.style.opacity = ".5";
		r.style.cursor = "default";
		if (r.num>0) r.onmouseover = null;
	} else {
		r.onmouseover = function () {
			r.num=1;
			rollover(this, 1);
		}
		r.onmouseout = function () {
			rollover(this, 0);
		}
		r.style.filter = "alpha(opacity=100)";
		r.style.opacity = "1";
		r.style.cursor = "pointer";
	}
	
	
}

function rollover(whatRoll, whatWay) {
	
	i = d.getElementById(whatRoll.id);
	switch (whatWay) {
		case 0: i.style.backgroundPosition = "left top"; break;
		case 1: i.style.backgroundPosition = "left " + m + "px"; break;
	}	
}

function scrollObjects(dir) {
	
	oldPos = newPos;
	
	if (dir == 1) {
		if (oldPos>=scrollNum) {
			newPos-=w;
			new Effect.Move(iContainer.id, {x: newPos, y: 0, mode: 'absolute', afterFinish:checkContainerPos()});
		}
	
	} else {
		if (oldPos<0) {
			newPos+=w;
			new Effect.Move(iContainer.id, {x: newPos, y: 0, mode: 'absolute', afterFinish:checkContainerPos()});
		}
	}
}

function getW(obj) {
   
   return(obj.offsetWidth);
}

function getX(obj) {
   
   return(obj.offsetLeft);
}


function getY(obj) {
   
   return(obj.offsetTop);
}

function showOverlay(whatVid, whatImage, num) {
	
	bg = d.getElementById("overlay");
	vT = d.getElementById("videoText");
	vid=d.getElementById(whatVid);
	image=d.getElementById(whatImage);
	
	var xPos = getX(d.getElementById(image.id))-6;
	var yPos = getY(d.getElementById(image.id))-6;
	bg.style.left = (xPos+6)+"px";
	bg.style.top = (yPos+6)+"px";
	bg.style.display = "block";
	bg.style.cursor = "pointer";
	bg.innerHTML = descriptions[num];
	bg.onclick = function () {
		window.open(urls[num], 'auditorium', 'toolbar=0, menubar=0, location=0, status=0, resizable=1, scrollbars=yes');
	}
}

function hideOverlay() {
	bg = d.getElementById("overlay");
	bg.style.display = "none";
	
}


