//alert('html-slide-show.js included');

var Fader_Html = function(cBFunc){
	this.m_slideDir = 'rtl';
	//this.brdrWidth = '0';
	//this.brdrStyle = 'solid';
	//this.brdrClr = '#f00';
	this.m_fadeClr = '#fff';//transparent
	
	this.m_baseopacity = 0.0; //set base opacity when mouse isn't over element (decimal below 1)
	this.m_increment = 0.2; //amount of opacity to increase after each iteration (suggestion: 0.1 or 0.2)
	this.m_framesCntnt = ['<div>we wre ok</div>', '<img src="di-images/anim/a2.gif" />', '<img src="di-images/anim/a3.gif">', '<img src="di-images/anim/a4.gif">'];
	this.m_framesHref = ['http://didiran.com/1', 'http://didiran.com/2', 'http://didiran.com/3', 'http://didiran.com/4'];
	this.m_framesTitle = ['layer 1 title', 'layer 2 title', 'layer 3 title', 'layer 4 title'];
	this.framesFollow = [true, true, true, true];//rel="nofollow"
	
	
	this.m_navBarLoc = 'in';//out
	this.m_outerNavBtnCntnr = '';//container for outside nav bottuns
	this.m_navBtnTblCntnrClass = '';
	this.m_hasPrevNextBtn = false;
	this.m_advBtnTop = 150;
	this.m_advBtnLeft = 0;
	this.m_advBtnRight = 0;
	this.m_advBtnBtm = 10;
	
	this.m_normBtnHtml = [
		'<span style="border: 1px solid #000; background-color:#0ff; padding:2px; margin:2px; cursor:pointer;">1</span>',
		'<span style="border: 1px solid #000; background-color:#0ff; padding:2px; margin:2px; cursor:pointer;">2</span>',
		'<span style="border: 1px solid #000; background-color:#0ff; padding:2px; margin:2px; cursor:pointer;">3</span>',
		'<span style="border: 1px solid #000; background-color:#0ff; padding:2px; margin:2px; cursor:pointer;">4</span>'
	];
	this.m_hoverBtnHtml = [
		'<span style="border: 1px solid #f00; background-color:#ff0; padding:2px; margin:2px;">1</span>',
		'<span style="border: 1px solid #f00; background-color:#ff0; padding:2px; margin:2px;">2</span>',
		'<span style="border: 1px solid #f00; background-color:#ff0; padding:2px; margin:2px;">3</span>',
		'<span style="border: 1px solid #f00; background-color:#ff0; padding:2px; margin:2px;">4</span>'
	];
	this.m_selectedBtnHtml = [
		'<span style="border: 1px solid #f00; background-color:#f0f; padding:2px; margin:2px;">1</span>',
		'<span style="border: 1px solid #f00; background-color:#f0f; padding:2px; margin:2px;">2</span>',
		'<span style="border: 1px solid #f00; background-color:#f0f; padding:2px; margin:2px;">3</span>',
		'<span style="border: 1px solid #f00; background-color:#f0f; padding:2px; margin:2px;">4</span>'
	];
	
	this.m_currentopacity = 0.7;
	this.m_cBFunc = cBFunc;
	
	//times
	this.m_frmInx = 0;
	this.m_fTimer;
	this.m_chngType = 'fade';
	this.m_speedT = 90;
	this.m_stayT = 5000;
	
	this.m_isClckdOnBtn = 0;
	this.m_btnPrvHtml = '';
				
};

Fader_Html.prototype.getHtml = function(){
	var objName = this.m_cBFunc;
	var navLayerCntnt='';
	
	if(this.m_navBarLoc == 'in'){
		navLayerCntnt += '<table class="'+this.m_navBtnTblCntnrClass+'" border="0" ><tr style="height:'+this.m_advBtnTop+'px;"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td style="width:'+this.m_advBtnRight+'px;">&nbsp;</td><td>';
	}
		
		navLayerCntnt += '<table><tr>';
		var e = 0;
		if(this.m_hasPrevNextBtn){
			navLayerCntnt += '<td><div onclick="'+objName+'.prevFrame()"  onmouseover="if(this.isOver!=1){this.isOver=1; this.prvHtml=this.innerHTML; this.innerHTML='+objName+'.m_prevBtnHover}" onmouseout="this.isOver=0; this.innerHTML=this.prvHtml; ">'+this.m_prevBtnNorm+'</div></td>';
		}
		while(e < this.m_framesCntnt.length){
			navLayerCntnt += '<td><div id="'+objName+'_navBtnCntnr_'+e+'" onclick="'+objName+'.chngFrame('+e+')"  onmouseover="if(this.isOver!=1){this.isOver=1; this.prvHtml=this.innerHTML; this.innerHTML='+objName+'.m_hoverBtnHtml['+e+']}" onmouseout="this.isOver=0; this.innerHTML=this.prvHtml; ">';//'+objName+'.mOut('+e+'); return true;
			if(e==0){
				navLayerCntnt += this.m_selectedBtnHtml[e];
			}else{
				navLayerCntnt += this.m_normBtnHtml[e];
			}
			navLayerCntnt += '</div></td>';
			e++;
		}
		if(this.m_hasPrevNextBtn){
			navLayerCntnt += '<td><div onclick="'+objName+'.nextFrame()"  onmouseover="if(this.isOver!=1){this.isOver=1; this.prvHtml=this.innerHTML; this.innerHTML='+objName+'.m_nextBtnHover}" onmouseout="this.isOver=0; this.innerHTML=this.prvHtml; ">'+this.m_nextBtnNorm+'</div></td>';
		}
		navLayerCntnt += '</tr></table>';
	
	if(this.m_navBarLoc == 'in'){	
		navLayerCntnt += '</td><td style="width:'+this.m_advBtnLeft+'px;">&nbsp;</td></tr><tr style="height:'+this.m_advBtnBtm+'px;"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>';
	}
		
	var outHtml = '';
	
	outHtml += '<div id="'+objName+'_htmlSlideShowMainCntnr" class="'+objName+'_genCss" style="position:absolute; border: '+this.m_brdrWidth+'px '+this.m_brdrStyle+' '+this.m_brdrClr+'; direction:'+this.m_slideDir+';">';
		outHtml += '<div id="'+objName+'_contentLayer" class="'+objName+'_genFrmsCss">';
			for(var eCL in this.m_framesCntnt){
				lL = this.m_framesCntnt[eCL];
				if(lL) outHtml += '<div id="'+objName+'_layerCntnr_'+eCL+'" >'+lL+'</div>';
				//cLog('<div id="'+objName+'_layerCntnr_'+eCL+'">'+lL+'</div>');
			}
		outHtml += '</div>';
		outHtml += '<div id="'+objName+'_faderMask" class="'+objName+'_genFrmsCss" style="background-color:'+this.m_fadeClr+'; cursor:pointer;" onclick="window.open('+objName+'.href, \'_self\')" >&nbsp;</div>';
		if(this.m_navBarLoc == 'in'){
			outHtml += '<div id="'+objName+'_navBtn" class="'+objName+'_genFrmsCss" onclick="'+objName+'.clickedOnSlideBody()" style="cursor:pointer;">'+navLayerCntnt+'</div>';
		}else{
			if(fObj(this.m_outerNavBtnCntnr))fObj(this.m_outerNavBtnCntnr).innerHTML = '<div id="'+objName+'_navBtn" class="'+objName+'_outerNavBtnCntnr" onclick="'+objName+'.clickedOnSlideBody()" >'+navLayerCntnt+'</div>';
		}
	outHtml += '</div>';	
	
	return outHtml;

};

Fader_Html.prototype.fadeIt = function(direction){
	var objName = this.m_cBFunc;
	
	//cLog(objName+' '+this.m_fTimer);
	clearTimeout(this.m_fTimer);
	if(this.m_chngType=='simple'){
		this.m_currentopacity = 1;
	}
	if(this.m_currentopacity>0.9){
		direction="fOut";
		this.m_frmInx++;
		if(this.m_frmInx > this.m_framesCntnt.length-1) this.m_frmInx=0;
		this.turnOnFrame(this.m_frmInx);
		
	}else if(this.m_currentopacity<0.1){
		this.chngFrame();
		
	}
	if(this.m_chngType=='simple'){
		this.m_fTimer = setTimeout(objName+".fadeIt('fIn')", this.m_stayT );
		return;
	}
	var fadeamount = (direction=="fIn") ? this.m_increment : -this.m_increment;
	if ((direction=="fIn" && this.m_currentopacity<1) || (direction=="fOut" && this.m_currentopacity > this.m_baseopacity)){
		this.setOpacity(this.m_currentopacity+fadeamount);
		this.m_fTimer = setTimeout(objName+".fadeIt('"+direction+"')", this.m_speedT );
	}
};

Fader_Html.prototype.clickedOnSlideBody = function(){
	
	if(this.m_isClckdOnBtn == 1){
		this.m_isClckdOnBtn = 0;
		return false;
	}else{
		window.open(this.m_framesHref[this.m_frmInx], "_self");
	}
};

Fader_Html.prototype.mOver = function(btnInx){
	var objName = this.m_cBFunc;
	
	this.m_btnPrvHtml = fObj(objName+'_navBtnCntnr_'+btnInx).innerHTML;
	if(fObj(objName+'_navBtnCntnr_'+btnInx)) fObj(objName+'_navBtnCntnr_'+btnInx).innerHTML = this.m_hoverBtnHtml[btnInx];
	return true;
};

Fader_Html.prototype.mOut = function(btnInx){
	var objName = this.m_cBFunc;
	
	if(fObj(objName+'_navBtnCntnr_'+btnInx)) fObj(objName+'_navBtnCntnr_'+btnInx).innerHTML = this.m_normBtnHtml[btnInx];
	return true;
};

Fader_Html.prototype.turnOnFrame = function(frmNum){
	var objName = this.m_cBFunc;
	/*
	//cLog('turnOnFrame :'+frmNum);
	if(fObj(objName+'_contentLayer')){
		//turn display all off except one of them
		for(var ee in this.m_framesCntnt){
			//fObj(objName+'_contentLayer').innerHTML = this.m_framesCntnt[frmNum];
			fObj(objName+'_contentLayer').innerHTML = this.m_framesCntnt[frmNum];
		}
	}*/
	
	var e = 0;
	//turn on/off proper slid and proper btns
	while(e < this.m_framesCntnt.length){
		if(e==frmNum){
			objX = fObj(objName+'_navBtnCntnr_'+e);
			if(objX) objX.innerHTML = this.m_selectedBtnHtml[e];
			
			layerX = fObj(objName+'_layerCntnr_'+e);
			if(layerX) layerX.style.display = 'block';
			this.href = this.m_framesHref[e];
			
		}else{
			objX = fObj(objName+'_navBtnCntnr_'+e);
			if(objX) objX.innerHTML = this.m_normBtnHtml[e];
			
			layerX = fObj(objName+'_layerCntnr_'+e);
			if(layerX) layerX.style.display = 'none';
			
		}
		e++;
	}
};

Fader_Html.prototype.nextFrame = function(){
	var objName = this.m_cBFunc;
	this.m_isClckdOnBtn = 1;
	
	this.m_frmInx++;
	if(this.m_frmInx > this.m_framesCntnt.length-1) this.m_frmInx=0;
	this.turnOnFrame(this.m_frmInx);
};

Fader_Html.prototype.prevFrame = function(){
	var objName = this.m_cBFunc;
	this.m_isClckdOnBtn = 1;
	
	this.m_frmInx--;
	if(this.m_frmInx < 0) this.m_frmInx = this.m_framesCntnt.length-1;
	this.turnOnFrame(this.m_frmInx);
};

Fader_Html.prototype.chngFrame = function(frmNum){
	var objName = this.m_cBFunc;
	
	//cLog('chngFrame: '+frmNum);
	if(frmNum >= 0){
		this.m_frmInx = frmNum;
		this.turnOnFrame(frmNum);
		
		this.m_currentopacity = 0;
		this.setOpacity(0);
		//cLog(objName+' '+this.m_fTimer);
		clearTimeout(this.m_fTimer);
		this.m_fTimer = setTimeout(objName+".fadeIt('fIn')", (this.m_stayT*3) );
		this.m_isClckdOnBtn = 1;
		
	}else{
		this.setOpacity(0);
		this.m_fTimer = setTimeout(objName+".fadeIt('fIn')", this.m_stayT );
	}
};


Fader_Html.prototype.setOpacity = function(value){
	var objName = this.m_cBFunc;
	
	this.m_currentopacity = value;
	//Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	var faderObj = fObj(objName+'_faderMask');
	if(faderObj){
		faderObj.style.filter="alpha(opacity="+value*100+")";
		faderObj.style.MozOpacity=value;
		faderObj.style.opacity=value;
	}
	
	//if (isIe()){ //IE syntax
	//	faderObj.style.filter="alpha(opacity="+value*100+")";
	//}else if (typeof faderObj.style.MozOpacity!="undefined"){ //Old Mozilla syntax
	//	faderObj.style.MozOpacity=value;
	//}else if (typeof faderObj.style.opacity!="undefined"){ //Standard opacity syntax
	//	faderObj.style.opacity=value;
	//}
	
	//faderObj.m_currentopacity = value;
	return;
};
