//Array with last ID
lastId = new Array();
var baseurl, languageid;

  function checkBrowserName(name){
	    var agent = navigator.userAgent.toLowerCase();
	    if (agent.indexOf(name.toLowerCase())>-1) {
	      return true;
	    }
	    return false;
	  }



function showFlash( filename, actId, fallbackImgFilename, isie ) {
	// prepare arrays
	if ($chk(js)) {
		var twoStrings = js.split(";");
		if (twoStrings[0] && twoStrings[1]) {
			var links = twoStrings[0].split(",");
			var flashs = twoStrings[1].split(",");
		}
	}

	//show flash file
	actId = actId.toInt();
	if ($chk(actId) == false) {
		var actId = 1;
	} 
	
	if (!$chk(isie)) {
		var isie = 0;
	}

	if (actId < links.length) {
		nextActId = actId+1;
	} else {
		nextActId = 1;
	}

	var flash =  '';
	var link = '';
	var i = actId-1;
	var badcase = 1;
	if ($chk(flashs) && $chk(links)) {
		while (link == '') {
				badcase++;
			if (badcase > 50) break;
			if ($chk(links[i])) {
				link  = links[i]
				break;
			} else {
				i++;
				if (i > links.length) {
					i = 1;
				}
			}
		}
		i = actId+1;
		flashs.unshift('');
		while (flash == '') {
			badcase++;
			if (badcase > 100) break;	
			if ($chk(flashs[i])) {
				flash = flashs[i];
				break;
			} else {
				i++;
				if (i > flashs.length) {
					i = 1;
				}
			}		
		}
	}

	// get flashVars for a replace
	var flashVars = 'targetlinkid='+link+'&nextflashfile='+flash+'&baseurl='+jsBaseurl+'&languageid='+jsLanguageid+'&actId='+nextActId+'&isie='+isie;

	if (isie || checkBrowserName('MSIE')) {
		if ($chk($('flashContainer'))) {
			//flashVars.replace(/%20/g, '&')
			var newObject = '<div><object id="flashObject" width="980" height="396" data="uploads/media/'+filename+'?'+flashVars+'" type="application/x-shockwave-flash"><param name="movie" value="uploads/media/'+ filename +'" /><param name="wmode" value="opaque" /><param name="quality" value="high" /><param name="flashVars" value="'+flashVars+'" /></object></div>';
			document.getElementById('flashContainer').innerHTML = newObject;

		}
	} else {
		$('flashObject').getChildren('param [name=flashVars]').setProperty('value', flashVars);
		document.getElementById('flashObject').data = 'uploads/media/'+ filename;
		document.getElementById('flashActId').value = actId;
		// let firefox2 rerender content
		if (document.getElementById('flashObject').getStyle('position') == 'absolute') {
			document.getElementById('flashObject').setStyle('position', 'relative');
		} else {
			document.getElementById('flashObject').setStyle('position', 'absolute');
		}
	}

	//show fallbackimage
	document.getElementById('fallbackContainer').innerHTML = '<img height="396" width="980" alt="' + fallbackImgFilename + '" title="' + fallbackImgFilename + '" src="uploads/media/' + fallbackImgFilename + '">';
	//activate link
	var myElement = $('stagemenu_' + actId);
/*
	if (!myElement.getProperty('class').contains('active')) {
		myElement.set('class', 'active');
	}
*/
	//hide last clicked link
/*
	if( lastId[1] && lastId[1] != actId ) {
		var myElement = $('stagemenu_' + lastId[1]);
		myElement.set('class', '');
	}
*/
	lastId[1] = actId;
/*
	if (actId != 1) {
		$('stagemenu_1').set('class', '');
	}
*/	
	for (i = 1; i < flashs.length; i++) {
		var myElement = $('stagemenu_' +i);
		if (i != actId) {
			myElement.set('class', '');
			myElement.hideFocus = true;
		} else {
			if (!myElement.getProperty('class').contains('active')) {
				myElement.set('class', 'active');
				myElement.focus();
			}
		}
	}

	return false;
}

function showThumbnail( id ){
	document.getElementById('thumbimg_' + id ).style.display = 'block';
}

function hideThumbnail( id ){
	document.getElementById('thumbimg_' + id ).style.display = 'none';
}

window.addEvent('domready', function() {
	if ($chk($('stagemenu_1'))) {
		$('stagemenu_1').set('class', 'active');
	}
});
