
///////////////////////////////////////////////////////
// BHFlick v1.04 (c) 2006-2008 Howard Brown
///////////////////////////////////////////////////////
function BHFlick(p)
{
	var s='',tb,tr,td,i,div,h;
	bhUI.createObject('Flick',this);
	if(!p.id){
	p={id:arguments[0]};}
	this.frames=new Array();
	this.index=-1;this.delay=9000;
	this.nextFrame=null;this.prevFrame=null;
	this.status=0;this.working=null;this.wait=null;
	this.zIndex=5;this.div=div=bhUI.element(p.id);
	this.wrap=div;
	//div.style.width=p.width+'px';div.style.height=p.height+'px';
	div.style.position='relative';
	this.div=div=div.addElement();
	//div.style.width=p.width+'px';div.style.height=p.height-20+'px';
	div.style.overflow='hidden';
	if(typeof(div.style.opacity)!=__UF)s="opacity=(v/100)";
	else if(typeof(div.style.MozOpacity)!=__UF)s="MozOpacity=(v/100)";
	else if(typeof(div.filters)!=__UF)s="filter=v==100?'':'alpha(opacity='+v+')'";
	this.mode=s?'fade':'normal';
	this.setOpacity=new Function("e","v","e.style."+s);
	this.ul=this.wrap.addElement('UL');
	this.ul.className="flick-frame-nav";
	if(p.frames){
	for(i=0;i<p.frames.length;i++)this.addFrame(p.frames[i]);}
	this.navclick=p.navonclick?p.navonclick:new Function("i","this.showFrame(i);");
}

BHFlick.prototype.addFrame=function(content)
{
	var i,a,li,div;if(typeof(content)=='string'){
	div=this.div.addElement();div.innerHTML=content;
	}else{div=content;this.div.appendChild(div);}
	div.className="flick-frame-mask";
	//div.style.visibility='hidden';div.style.zIndex=this.zIndex;div.style.display='block';
	i=this.frames.push(div)-1;li=this.ul.addElement('LI');
	a=li.addElement('A');a.onclick=new Function(this.Tx+".navclick("+i+");return false;");
	div.nav=a;a.href="";
	return i;
}

BHFlick.prototype.getFrame=function(i)
{
	return this.frames[i];
}


BHFlick.prototype.showFrame=function(i)
{
	if(this.index==i)return;
	clearTimeout(this.wait);
	clearInterval(this.working);
	this.index=i;
	this.work();
}

BHFlick.prototype.transition=function()
{
	switch(this.mode)
	{
	case 'fade':
	{
		if(this.opacity<100)
		{
			if(this.prevFrame)this.setOpacity(this.prevFrame,100-this.opacity);
			this.opacity+=10;
			this.setOpacity(this.nextFrame,this.opacity);
			return;
		}
		else
		{	
			clearInterval(this.working);
			if(this.prevFrame)
			{
				this.prevFrame.style.visibility='hidden';
				this.prevFrame.style.zIndex=this.zIndex;
			}
		}
	}
	break;
	case 'normal':
	{
		if(this.prevFrame)this.prevFrame.style.visibility='hidden';
		this.nextFrame.style.visibility='inherit';
	}
	break;
	}
	
	this.nextFrame.nav.className='active';
	if(this.prevFrame)this.prevFrame.nav.className='';
	if(this.status)this.wait=setTimeout(this.Tx+'.ar()',this.delay);
	this.working=0;
}

BHFlick.prototype.ar=function()
{
	
	if(this.pause)
	{
		this.wait=setTimeout(this.Tx+'.ar()',this.delay);
	}
	else
	{
		this.index++;
		if(this.index>=this.frames.length)this.index=0;
		this.work();
	}
}

BHFlick.prototype.work=function()
{
	this.prevFrame=this.nextFrame;
	this.nextFrame=this.frames[this.index];
	if(this.prevFrame==this.nextFrame)this.prevFrame=null;
	switch(this.mode)
	{
	case 'fade':
		{
			this.opacity=10;
			this.setOpacity(this.nextFrame,10);
			this.nextFrame.style.visibility='inherit';
			if(this.prevtFrame)this.nextFrame.style.zIndex=this.prevFrame.style.zIndex+1;
			else this.nextFrame.style.zIndex++;
			this.working=setInterval(this.Tx+'.transition()',50);
		}
		break;
	case 'normal':
		{
		}
		break;
	}
	this.transition();
}

BHFlick.prototype.play=function()
{
	if( !this.status )
	{
		this.status=1;
		if(!this.working)
		 	this.work();
	}
}
