var SlideShow = {};
SlideShow.DivRotation = {};
//SlideShow.DivRotation.DivList=['div_sshow_1', 'div_sshow_2', 'div_sshow_3', 'div_sshow_4', 'div_sshow_5', 'div_sshow_6', 'div_sshow_7'];
//SlideShow.DivRotation.UrlList=['', '', '', '', '', '', ''];
//SlideShow.DivRotation.TargetList=['', '', '', '', '', '', ''];
//SlideShow.DivRotation.DelayList=[2, 2, 2, 2, 2, 2, 2];
SlideShow.DivRotation.FadeSpeed = 5;
SlideShow.DivRotation.FadeChange = 2; // áttűnés ideje
SlideShow.DivRotation.ChangeInterval = 8; // Másodpercenkénti váltás
SlideShow.DivRotation.RandomFirstDiv = 0; // 1, ha véletlenszerű div
SlideShow.DivRotation.DivPrev = null;
SlideShow.DivRotation.Timer = null;
SlideShow.DivRotation.TimerFadeIn = null;
SlideShow.DivRotation.TimerFadeOut = null;
SlideShow.DivRotation.IDX = 0;
SlideShow.DivRotation.WidthSV=0

SlideShow.DivRotation.SetOpacity = function(obj, opacity)
{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Windows
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari < 1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;	
	// Rgi Mozilla s Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;

	if (opacity === 0) 
	{
		obj.style.visibility = 'visible';
	}
};

SlideShow.DivRotation.FadeIn = function(id, opacity, change, speed)
{
	var  obj = document.getElementById(id);	
	if (-1 != navigator.userAgent.indexOf('MSIE')) 
	{
		obj.style.filter="blendTrans(duration=0.5)";
		if (obj.filters.blendTrans.status != 2) 
		{
			obj.filters.blendTrans.apply();
			obj.style.visibility="visible";
			obj.filters.blendTrans.play();
		}
	} 
	else
	{
		if (opacity <= 100) 
		{
			this.SetOpacity(obj, opacity);
			opacity += change;
			SlideShow.DivRotation.TimerFadeIn = setTimeout('SlideShow.DivRotation.FadeIn("'+obj.id+'", '+opacity+', '+change+', '+speed+')', speed);
		} 
		else 
		{
			this.SetOpacity(obj, 100);
		}
	}
};

SlideShow.DivRotation.FadeOut = function(id, opacity, change, speed)
{
	var  obj = document.getElementById(id);
	
	if (opacity > 0) 
	{
		this.SetOpacity(obj, opacity);
		opacity -= change;
		SlideShow.DivRotation.TimerFadeOut = setTimeout('SlideShow.DivRotation.FadeOut("'+obj.id+'", '+opacity+', '+change+', '+speed+')', speed);
	} 
	else 
	{
		this.SetOpacity(obj, 0);
		obj.style.visibility = 'hidden';
	}
};

SlideShow.DivRotation.GetPageX = function(el)
{
	var Firefox = document.getElementById && !document.all;
	var offsetParent = el;
	var n = 0;
	while (offsetParent !== null && offsetParent !== document.body) 
	{
		n += offsetParent.offsetLeft;
		if (!Firefox) 
		{
			parseInt(offsetParent.currentStyle.borderLeftWidth, 10)>0?n+=parseInt(offsetParent.currentStyle.borderLeftWidth, 10):"";
		}
		offsetParent=offsetParent.offsetParent;
	}        
	return n;
};

SlideShow.DivRotation.GetPageY = function(el) 
{
	var Firefox = document.getElementById && !document.all;
	var offsetParent = el;
  var n = 0;
	while (offsetParent !== null && offsetParent !== document.body) 
	{
		n += offsetParent.offsetTop;
		if (!Firefox) 
		{
			parseInt(offsetParent.currentStyle.borderTopWidth, 10)>0?n+=parseInt(offsetParent.currentStyle.borderTopWidth, 10):"";
		}
		offsetParent=offsetParent.offsetParent;
	}
	return n;
};

SlideShow.DivRotation.IsSlideShowRunning = function() 
{
	if (SlideShow.DivRotation.Timer) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
};

SlideShow.DivRotation.SlideShowRun = function(run) 
{
	var div_pause_play = document.getElementById('slideshow_control_pp');
	if (run) 
	{
		if (SlideShow.DivRotation.Timer) 
		{
			return;
		}
 		SlideShow.DivRotation.PhotoSlideStart(SlideShow.DivRotation.IDX+1, true);
		div_pause_play.innerHTML = '<img border="0" title="Stop" src="img/pause.gif" width="14" height="14">';
	} 
	else
	{
		if (!SlideShow.DivRotation.Timer) 
		{
			return;
		}
		clearTimeout(SlideShow.DivRotation.Timer);
		SlideShow.DivRotation.Timer = null;
		div_pause_play.innerHTML = '<img border="0" title="Start" src="img/play.gif" width="14" height="14">';
	}
};

SlideShow.DivRotation.PhotoSlideShowInit = function(idx, slideshow)
{
  if (idx>=0)
	{
    if (idx>=SlideShow.DivRotation.DivList.length) idx=0;
	}
	else
	{
		if (SlideShow.DivRotation.RandomFirstDiv) 
		{
			idx = Math.floor(Math.random()*this.DivList.length);
		} 
		else 
		{
			idx = 0;
		}
	}
  SlideShow.DivRotation.IDX=idx;

  div_controls = document.createElement('DIV');
  div_controls.id = 'slideshow_controls';
  div_controls.className = 'slideshow_controls_box';
  document.body.appendChild(div_controls);

	var control_onclick = function() 
	{
		if (SlideShow.DivRotation.IsSlideShowRunning()) 
		{
			SlideShow.DivRotation.SlideShowRun(false);
		}

		if (SlideShow.DivRotation.TimerFadeIn) 
		{
			clearTimeout(SlideShow.DivRotation.TimerFadeIn);
			SlideShow.DivRotation.TimerFadeIn = null;
		}
		if (SlideShow.DivRotation.TimerFadeOut) 
		{
			clearTimeout(SlideShow.DivRotation.TimerFadeOut);
			SlideShow.DivRotation.TimerFadeOut = null;
		}

		var curr = this.id.substr(8);
    var curr_idx;
		for (i = 0; i < SlideShow.DivRotation.DivList.length; i++) 
		{
			if (SlideShow.DivRotation.DivList[i] == curr) 
			{
				curr_idx = i;
			}
			SlideShow.DivRotation.FadeOut(SlideShow.DivRotation.DivList[i], 0, 0, 0);
		}

		SlideShow.DivRotation.PhotoSlideStart(curr_idx, false);
	};

	for (i = 0; i < SlideShow.DivRotation.DivList.length; i++) 
	{
		var div = document.createElement('DIV');
		div.id = 'control_'+SlideShow.DivRotation.DivList[i];
		div_controls.appendChild(div);
		div.innerHTML = i+1;
		div.className = 'slideshow_control';
		div.onclick = control_onclick;
	}

	var div_pause_play;
	div_pause_play = document.createElement('DIV');
	div_pause_play.id = 'slideshow_control_pp';
	div_controls.appendChild(div_pause_play);
	div_pause_play.innerHTML = '<img border="0" title="Stop" src="img/pause.gif" width="14" height="14">';
	div_pause_play.className = 'slideshow_control';
	div_pause_play.onclick = function() 
	{
		if (SlideShow.DivRotation.IsSlideShowRunning()) 
		{
			SlideShow.DivRotation.SlideShowRun(false);
		} 
		else 
		{
			SlideShow.DivRotation.SlideShowRun(true);
		}
	};

  SlideShow.DivRotation.WidthSV=div_controls.offsetWidth-4;

  div_controls.style.width=SlideShow.DivRotation.WidthSV+'px';
	
  SlideShow.DivRotation.PhotoSlideStart(idx, slideshow);	
}

SlideShow.DivRotation.PhotoSlideStart = function(idx, slideshow)
{
  if (idx>=SlideShow.DivRotation.DivList.length) idx=0;
  SlideShow.DivRotation.IDX=idx;

  var div_curr;
	var i;
	var div_controls = document.getElementById('slideshow_controls');

	if (this.DivPrev) 
	{
		if (this.DivPrev.id != this.DivList[idx]) 
		{
			this.FadeOut(this.DivPrev.id, 100, this.FadeChange, this.FadeSpeed);
		}
	}

	div_curr = document.getElementById(this.DivList[idx]);
	this.FadeIn(div_curr.id, 0, this.FadeChange, this.FadeSpeed);
	
	if (div_controls) 
	{
		e=document.getElementById(this.DivList[this.IDX]);
		w=e.offsetWidth;
		h=e.offsetHeight;
		Y=SlideShow.DivRotation.GetPageY(div_curr);
		X=SlideShow.DivRotation.GetPageX(div_curr);
		Firefox = document.getElementById && !document.all;
    if (Firefox)
		{
//      div_controls.style.top = 3 + Y +  'px'; // top
      div_controls.style.top = (SlideShow.DivRotation.GetPageY(div_curr) + parseInt(div_curr.offsetHeight, 10) - 33) + 'px'; // bottom
	  	div_controls.style.left = 0 + X + 'px';
  		div_controls.style.visibility = 'visible';
		}
		else
		{
//      div_controls.style.top = 0 + Y +  'px'; // top
      div_controls.style.top = (SlideShow.DivRotation.GetPageY(div_curr) + parseInt(div_curr.offsetHeight, 10) - 35) + 'px'; // bottom
	  	div_controls.style.left = 0 + X + 'px';
  		div_controls.style.visibility = 'visible';
		}
    div_controls.style.zindex='1';

		if (this.UrlList[idx]!="")
		{
			if (this.TargetList[idx]=="b")
   			url='<a class="slideshow_url_link" href="'+this.UrlList[idx]+'">&raquo;</a>'; 
			else
  			url='<a class="slideshow_url_link" href="'+this.UrlList[idx]+'" target="_blank">&raquo;</a>';
		}


		if (this.DivPrev) 
		{
			var div_prev_ctrl = document.getElementById('control_'+this.DivPrev.id);
			div_prev_ctrl.className = "slideshow_control";
		}
		var div_curr_ctrl = document.getElementById('control_'+this.DivList[idx]);
		div_curr_ctrl.className = "slideshow_control slideshow_control_active";
	}
	
	this.DivPrev = div_curr;
	if (slideshow) 
	{
//		SlideShow.DivRotation.Timer = setTimeout("SlideShow.DivRotation.PhotoSlideStart("+((idx+1) % this.DivList.length)+", "+slideshow+");", this.ChangeInterval * 1000);
		SlideShow.DivRotation.Timer = setTimeout("SlideShow.DivRotation.PhotoSlideStart("+((idx+1) % this.DivList.length)+", "+slideshow+");", this.DelayList[idx] * 1000);
	}
};



