/*
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgs = new Array(), txts = new Array(), zInterval = null, current=0, tcurrent=0, pause=false, next=false, blinktimer = null;

function blink()
{
	blinktimer = null;
	pathname = document.getElementById('play').src;
	filename = pathname.substr(pathname.lastIndexOf("/")+1,pathname.length);
	if (filename == 'play_blink.png')
	{
		document.getElementById('play').src= 'uploads/img/play_active.png';
 }
	else
	{
		document.getElementById('play').src = 'uploads/img/play_blink.png';
	}
 blinktimer = setTimeout(blink, 500);
	return;
}

function stopblink()
{
	clearTimeout(blinktimer);
	document.getElementById('play').src= 'uploads/img/play.png';
}

function togglePlay()
{
	if(document.getElementById('control').style.display=='block')
	{
		document.getElementById('play').onmouseover = '';
		document.getElementById('play').onmouseout = '';
		blink();
	}
	else
	{
		document.getElementById('play').onmouseover = 'this.src=uploads/img/play_active.png';
		document.getElementById('play').onmouseout = 'this.src=uploads/img/play.png';
		stopblink();
	}
}

function playNext()
{
	stopblink();
	if(timer)
	{
		document.getElementById('control').style.display='block';
  clearTimeout(timer);
	 timer = null;
	 so_xfade();
	}
	else
	{
		document.getElementById('control').style.display='block';
		timer = null;
		next = true;
	}
}

function playPrevious()
{
	if(timer)
	{
		document.getElementById('control').style.display='block';
  clearTimeout(timer);
	 timer = null;
	 so_xfade();
	}
	else
	{
		document.getElementById('control').style.display='block';
		timer = null;
		next = true;
	}
}


function so_init()
{
	if(!d.getElementById || !d.createElement)return;

	css = d.createElement('link');
	css.setAttribute('href','uploads/css/slideshow2.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	d.getElementsByTagName('head')[0].appendChild(css);

	imgs = d.getElementById('rotator').getElementsByTagName('img');

        if(!imgs[0]) {
          return false;
        }

	
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = 'block';
	imgs[0].xOpacity = .99;

	if(d.getElementById('bottomright') && d.getElementById('bottomright').getElementsByTagName('div')[0])
	{

        
 	txts = d.getElementById('bottomright').getElementsByTagName('div');

  for(t=1;t<txts.length;t++) txts[t].xOpacity = 0;
	 txts[0].style.display = 'block';
 	txts[0].xOpacity = .99;
 }

	timer = setTimeout(so_xfade,2000);
}

function so_xfade()
{
	if(document.getElementById('control').style.display!='none')
 {
		timer = null;
 	cOpacity = imgs[current].xOpacity;
 	nIndex = imgs[current+1]?current+1:0;
 	nOpacity = imgs[nIndex].xOpacity;

 	cOpacity-=.05;
 	nOpacity+=.05;

 	imgs[nIndex].style.display = 'block';
 	imgs[current].xOpacity = cOpacity;
 	imgs[nIndex].xOpacity = nOpacity;

 	setOpacity(imgs[current]);
 	setOpacity(imgs[nIndex]);

  if(txts.length > 0)
		{
  	tcOpacity = txts[tcurrent].xOpacity;
  	tnIndex = txts[tcurrent+1]?tcurrent+1:0;
  	tnOpacity = txts[tnIndex].xOpacity;

  	tcOpacity-=.05;
 	 tnOpacity+=.05;

  	txts[nIndex].style.display = 'block';
  	txts[current].xOpacity = tcOpacity;
 	 txts[nIndex].xOpacity = tnOpacity;

  	setOpacity(txts[tcurrent]);
  	setOpacity(txts[tnIndex]);
		}
		
 	if(cOpacity<=0)
 	{
	 	imgs[current].style.display = 'none';
	 	current = nIndex;
   
			if(txts.length > 0)
			{
  		txts[tcurrent].style.display = 'none';
  		tcurrent = tnIndex;
			}

			if(next == false)
			 {
//		   timer = null;
     timer = setTimeout(so_xfade,3000);
//					timer = null;
				}
			else
			{
				next = false;
				clearTimeout(timer);
				timer = null;
				so_xfade();
			}
 	}
 	else
 	{
 		setTimeout(so_xfade,20);
 	}
	}
	else
	{
		setTimeout(so_xfade,100);
	}
	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}