Fx.Properties = Fx.Styles.extend({	
			increase: function(){for (	var p in this.now) this.element[p] = this.now[p];	}	
		});



Fx.FlyingScroller = Fx.Properties.extend({
	initialize: function(el, options){
		this.parent(el, options);
		this.options = Object.extend(this.options || {}, Object.extend({
			paddingLeft: 0,
			paddingTop: 0
		}, options || {}));
	},
	toElement: function(el, paddingLeft, paddingTop){
		this.goTo(el.offsetLeft - (paddingLeft || this.options.paddingLeft || 0), el.offsetTop - (paddingTop || this.options.paddingTop || 0));
	},
	goTo: function(x, y){
		this.start({
			'scrollLeft': [this.element.scrollLeft, x],
			'scrollTop': [this.element.scrollTop, y]
		})
	}
});

var last_id = null;
var last_on = null;

var WGBHLab =
{
	start: function()
	{
		
		var main_nav = new Fx.FlyingScroller($('showcase-holder'), {
				transition: Fx.Transitions.Quad.easeInOut,
				duration: 700,
				paddingLeft: 0,
				paddingTop: 0
			
			});
		
		
		var main_nav_lks = new Array();
		var linkuri = $$('a');
		
		
		for (m=0; m<linkuri.length; m++)
		{
			if(linkuri[m].getAttribute('rel')=='vid_link')
			{
				main_nav_lks.push(linkuri[m]);	 
			}
			
			/**
			if(linkuri[m].getAttribute('href').match('http:'))
			{
				//alert(linkuri[m].getAttribute('href'));
				if(!linkuri[m].getProperty('target'))
				{
					linkuri[m].setAttribute('target','lab-external')
					
				}
			}**/
		}
		

		
		for (i=0; i<main_nav_lks.length; i++)
		{
		
			/**
		   	if(i ==0) 
		   	{
		   		if($(main_nav_lks[0].parentNode).hasClass('playlist-item'))
		   		{
		   			$(main_nav_lks[0].parentNode).addClass('playlist-on');
		   			last_on = $(main_nav_lks[0].parentNode);
		   		}
		   	}
		   	**/
		   	
		   	myparnode = $(main_nav_lks[i].parentNode);
		   	if(!myparnode.hasClass('playlist-item'))
			{
				myparnode = myparnode.parentNode;
			}
			
			myparnode.addEvent('click', function (e)
			{
				//get first a with rel tag
				thisa = $E('a',this);
				thisa.fireEvent('click');
			});

			main_nav_lks[i].addEvent('click', function (e)
			{
				if(e)
				{
					e = new Event(e);
					e.stopPropagation();
				}
				if(last_on != null)
				{
					last_on.removeClass('playlist-on');
					last_on = null;
				}
				
				var pnode = $(this.parentNode)
				if(!pnode.hasClass('playlist-item'))
				{
					pnode = pnode.parentNode;
				}
				
				if(pnode.hasClass('playlist-item'))
				{
					pnode.addClass('playlist-on');
					last_on = pnode;
				}
				
				WGBHLab.clearvid();
				var target_vid = $(this.className);
				
				
				if(this.getAttribute('rel')=='vid_link')
				{ 
					main_nav.clearTimer().toElement($(target_vid )); 
					return false; 
				}
				
			});
		}
		
		//start on a random element
		ran_num = $random(0,9);		
		ran_num = (ran_num % 5) * 2;
		if($(main_nav_lks[ran_num].parentNode).hasClass('playlist-item'))
		{
			//get first a with rel tag
			thisa = $E('a',$(main_nav_lks[ran_num]).parentNode);

			if(thisa)
			{
				thisa.fireEvent('click');
			}
		}		
   
		//preload images
		var aPreLoad	= new Array();
		var aPreLoadi	= 0;

		//do rollover
		$$('img','input').each(function(el){

			if(el.hasClass('roll'))
			{
				//let's preload
				aPreLoad[aPreLoadi] = new Image();
				aPreLoad[aPreLoadi].src = el.src.replace(el.src.replace(/(\.[^.]*)$/, "_h$1"));
				aPreLoadi++;

				el.addEvent('mouseover',function(){
					this.setAttribute('src',this.src.replace(/(\.[^.]*)$/, "_h$1"));
				});

				el.addEvent('mouseout',function(){
				this.setAttribute('src',this.src.replace(/_h(\.[^.]*)$/, "$1"));

				});
			}
		});

		//memory clean up
		delete aPreLoad;   
   
	},

	dovid: function(thisid,vidpath,width,height,uniid)
	{
		if (!document.getElementById) return true;
		
		this.clearvid();
		last_id = thisid;	
		QTReplace.replace(thisid, vidpath, "qtvid"+thisid, width, height);
		return false;
	},
	
	clearvid:function()
	{
		if(last_id != null)
		{
			//safari bug stop it
			try {
				if(document['qtvid'+last_id])
				{
					document['qtvid'+last_id].Stop();
				}
			}
			catch(e)
			{
			}

			
			try {
				var divv = document.getElementById(last_id);
				if(divv)
				{
					divv.innerHTML = '&nbsp;';
				}
			}
			catch(e)
			{
			}			
			
		}
		last_id = null;	
	}

};

/*
	QTReplace is developed by Robert Nyman, http://www.robertnyman.com, and it is released according to the
	Creative Commons Deed license (http://creativecommons.org/licenses/GPL/2.0/)
*/
// ---
var QTReplace = {
	elmToReplace : null,
	replace : function (elmToReplace, src, id, width, height, version, params){
		this.elmToReplace = document.getElementById(elmToReplace);
		if(this.elmToReplace){
			this.elmToReplace.innerHTML = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" id="' + id + '" name="' + id + '" width="' + width + '" height="220" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="SRC" value="'+src+'" /><param name="AUTOPLAY" value="true" /><param name="CONTROLLER" value="true" /><param name="BGCOLOR" value="#D9D4CE" /><embed src="'+src+'" id="' + id + '" id="' + name + '" cache="true" width="' + width + '" height="' + height + '" enablejavascript="true" autoplay="true" controller="true" bgcolor="#D9D4CE" pluginspage="http://www.apple.com/quicktime/download/" /></object>';
			

		}
	}

};

// ---

window.addEvent('domready', WGBHLab.start);