function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function videoClick(url, img, desc, width, height, fcolor, bcolor, autostart)
{
	document.getElementById('videoText').innerHTML = desc;
	if(/^[\w\d]{11}$/.test(url))
	{
		document.getElementById('video').innerHTML = '<object width="' + width + '" height="' + height + '"><param name="movie" value="http://www.youtube.com/v/' + url + '&hl=en_US&fs=1&color1=' + fcolor + '&color2=' + bcolor + '&border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + url + '&hl=en_US&fs=1&color1=' + fcolor + '&color2=' + bcolor + '&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + width + '" height="' + height + '"></embed></object>';
	}
	else
	{
		if(fcolor.substr(0,1) == '#') { fcolor = '0x' + fcolor.substr(1); }
		if(bcolor.substr(0,1) == '#') { bcolor = '0x' + bcolor.substr(1); }
		var s1 = new SWFObject("media/mediaplayer.swf","single",width,height,"8");
		s1.addParam("allowfullscreen","true");
		s1.addVariable("file",url);
		s1.addVariable("width",width);
		s1.addVariable("height",height);
		s1.addVariable("backcolor",bcolor);
		s1.addVariable("frontcolor",fcolor);
		s1.addVariable("autostart", "false");
		s1.addVariable("image",img);
		s1.write("video");
	}
}

function init()
{
	var left = document.getElementById('leftButton');
	var right = document.getElementById('rightButton');
	var content = document.getElementById('featureContent');
	var photo = document.getElementById('featurePhoto');
	var headline = document.getElementById('featureTitle');
	var summary = document.getElementById('featureText');
	var indent = left.offsetWidth + right.offsetWidth + 12;
	var inc = function(i) { return (i + 1) % features.length; }
	var dec = function(i) { return (i + features.length - 1) % features.length; }
	var features = [];
	content.current = 0;
	left.onclick = function() { content.display(dec(content.current)); }
	right.onclick = function() { content.display(inc(content.current)); }
	
	for(var i in content.childNodes)
	{
		if(content.childNodes[i].tagName)
		{
			var feature = content.childNodes[i];
			features.push(feature);
			feature.photo = feature.childNodes[0];
			feature.style.width = feature.photo.offsetWidth + 'px';
			feature.headline = feature.childNodes[1].childNodes[0];
			feature.summary = feature.childNodes[2];
			feature.onmouseover = function()
			{
				photo.src = this.photo.src.replace('/_thumbnails/', '/');
				headline.innerHTML = this.headline.innerHTML;
				headline.href = this.headline.href;
				try 
				{ 
					summary.innerHTML = this.summary.innerHTML; 
				} 
				catch(e) 
				{
					for(var i = 0; i < summary.childNodes.length; i++)
					{
						summary.removeChild(summary.childNodes[i]);
					}
					for(var i = 0; i < this.summary.childNodes.length; i++)
					{
						summary.appendChild(this.summary.childNodes[i].cloneNode(true));
					}
				}
			}
		}
	}
	
	features[0].onmouseover();
	
	
	content.display = function(start)
	{
		var end = content.current = start;
		var width = 0;
		var c = 0;
		for(var i = 0; i < features.length; i++)
		{
			try { content.removeChild(features[i]); } catch(e) {}
		}
		while(width < content.offsetWidth && c++ < 100)
		{
			content.appendChild(features[end]);
			width += features[end].offsetWidth;
			end = inc(end);
		}
		if(width >= (content.offsetWidth - indent))
		{
			end = dec(end);
			width -= features[end].offsetWidth;
			content.removeChild(features[end]);
		}
		end = dec(end);
		var margin = (content.offsetWidth - width - indent) / (end < start ? end + features.length - start + 1 : (end - start + 1)) / 2;
		for(var i = 0; i < features.length; i++)
		{
			features[i].style.margin = '0px ' + margin + 'px';
		} 
	}
	
	
	content.display(0);
}
