﻿/*JS-VERSION:2.4.0.0*/
	var speedArray = new Array();
	var imagePresenterArray = new Array();
	
	/* Parameters */
	var speed_delay = 6000; /* adjust delay length here, in miliseconds*/
	var slide_speed = 1000; /* adjust fade duration here, in miliseconds*/

	/*Don't change anything below this point!*/
	var autoslide = true;
	var slideOuter = "slide-wrapper";
	var slideLoading = "slide-loading";
	var slideClass = "slide";
	var naviClass = "navi";
	var activeSuffix = "-active";

	/*Effect handle*/
	var isShowing = 0;
	var slides;
	var navis;	
	var fx1 = new Array();
	var firstDelay = false;
	var pauseFlag = false;
	var timer;
	var playButton;
	
	EventListener(window, 'load', initFrontpageSlideshowPresenter);
	
	function initFrontpageSlideshowPresenter()
	{
		switchTab('show');
		initFrontpageSlideshow();
	}
	
	function initFrontpageSlideshow() {		
		displayloading = document.getElementById(slideLoading);
		if (displayloading) displayloading.style.display = "none";
		else return;
		displayslide = document.getElementById(slideOuter);
		if (displayslide) displayslide.style.display = "block";
		
		if (readCookie("com_jw_fpss") == "true") autoslide = true;
		else if (readCookie("com_jw_fpss") == "false") autoslide = false;	
		playButton = document.getElementById('playButton');
		if (autoslide) { showPauseButton(); }
		else { showPlayButton(); }
		
		slides = document.getElementsByClassName(slideClass);
		navis = document.getElementsByClassName(naviClass);
		
		if (slides.length == 0 || navis.length == 0) return;
		
		for (i = 0; i < slides.length; ++i) {
			fx1[i] = new fx.Combo(slides[i], { opacity: true, width: false, duration: slide_speed, height: false, toggle: false });
			navis[i].onclick = function() {
				current = null;
				for (j = 0; j < navis.length; ++j) {
					if (this == navis[j]) current = j;
				}
				
				/*ROSH: 19.04.07 post load image*/
				if($('presenterImage'+current))
					$('presenterImage'+current).src = imagePresenterArray[current];
					
				if (current != isShowing) {
					fx1[isShowing].clearTimer();
					if (fx1[isShowing].el.offsetHeight) fx1[isShowing].hide();
					fx1[current].toggle();
					navis[isShowing].className = naviClass;
					navis[current].className = naviClass + activeSuffix;
					navis[current].parentNode.style.backgroundColor = '#ADADAD';
					navis[isShowing].parentNode.style.backgroundColor = '';
					isShowing = current;
					if (!debugMode) {
						imgName = imagePresenterArray[current].split("/");
						dcsMultiTrack('DCS.dcsuri', '/presenter/', 'WT.cue', 'userSlide', 'WT.ad', imgName[imgName.length-1].substring(0, imgName[imgName.length-1].lastIndexOf(".")));
					}
					clearSlide();
				}
				
				return false;
			}
			if (i != 0) {
				fx1[i].hide();
			} else {
				navis[i].className = naviClass + activeSuffix;
				navis[i].parentNode.style.backgroundColor = '#ADADAD';
			}
		}
		navis[isShowing].parentNode.style.backgroundColor = '#ADADAD';
		window.setTimeout('fixBackgroundColorForDarkPixelImage(true);', 250);
	}
	/**/
	function showPauseButton() {
		createCookie("com_jw_fpss", "true",365);
		// playButton.innerHTML = "Pause"; /* change "Pause" label here*/
		playButton.getElementsByTagName("img")[0].src = "/Style%20Library/images/buttons/presenter_stop.gif";
		playButton.title = "Pause"; /* change "Pause" label here*/
		pauseFlag = false;
		autoSlide();
	}
	/**/
	function showPlayButton() {
		createCookie("com_jw_fpss", "false",365);
		// playButton.innerHTML = "Play"; /* change "Play" label here*/
		playButton.getElementsByTagName("img")[0].src = "/Style%20Library/images/buttons/presenter_play.gif";
		playButton.title = "Play"; /* change "Play" label here*/
		pauseFlag = true;
		clearTimeout(timer);
		firstDelay = false;
	}
	/**/
	function showNext() {
		
		if (slides.length <= 1) return;
		fx1[isShowing].clearTimer();
		if (fx1[isShowing].el.offsetHeight) fx1[isShowing].hide();
		navis[isShowing].className = naviClass;
		fixBackgroundColorForDarkPixelImage(false);
		if (isShowing == slides.length - 1) {
			fx1[0].toggle();
			isShowing = 0;
		} else {
			fx1[++isShowing].toggle();
		}
		window.setTimeout('fixBackgroundColorForDarkPixelImage(true);', 1000);
		navis[isShowing].className = naviClass + activeSuffix;
	}
	/**/
	function showPrev() {
		if (slides.length <= 1) return;
		fx1[isShowing].clearTimer();
		if (fx1[isShowing].el.offsetHeight) fx1[isShowing].hide();
		navis[isShowing].className = naviClass;
		
		if (isShowing == 0) {
			fx1[slides.length - 1].toggle();
			isShowing = slides.length - 1;
		} else {
			fx1[--isShowing].toggle();
		}
		navis[isShowing].className = naviClass + activeSuffix;
	}
	/**/
	function autoSlide() {
		if (!pauseFlag) {
			/*timer = setTimeout('autoSlide()', speed_delay);*/
			timer = setTimeout('autoSlide()', parseInt(speedArray[isShowing])+250);
			if (!firstDelay) 
			{
				firstDelay = true;
			}
			else 
			{
				applyPicture(isShowing+1);
				/*ROSH:BUGFIX*/
				for(var k=0;k<navis.length;++k)
				{
					navis[k].parentNode.style.backgroundColor = '#CCCCCC';
				}
				var tmp = isShowing;
				if (tmp+1 == navis.length) 
				{
					tmp = -1;
				}
				
				navis[tmp+1].parentNode.style.backgroundColor = '#ADADAD';
				if (!debugMode && autoPresenterTracking) {
					imgName = imagePresenterArray[tmp+1].split("/");
					dcsMultiTrack('DCS.dcsuri', '/presenter/', 'WT.cue', 'autoSlide', 'WT.ad', imgName[imgName.length-1].substring(0, imgName[imgName.length-1].lastIndexOf(".")));
				}
				showNext();
			}
		}
	}
	/**/
	function clearSlide() {
		if (!pauseFlag) {
			clearTimeout(timer);
			firstDelay = false;
			autoSlide();
		}
	}
	/**/
	function playButtonClicked() {
		if (pauseFlag) showPauseButton();
		else showPlayButton();
	}

	function fixBackgroundColorForDarkPixelImage(stat)
	{
		var obj = null;
		if($('fpss-container'))
		{
			if($('fpss-container').style)
			{
				if(stat)
				{
					$('fpss-container').style.backgroundColor = 'black';
				}
				else
				{
					$('fpss-container').style.backgroundColor = 'white';
				}				
			}
		}
	}
