var activePic = Array(0,0,0,0);

function showPicture(notice, address, picture, module){
	activePic[module] = picture;
	showSwitchers(notice);	
	var field = $('notice_' + notice);
	var info = $('notice_info_' + notice);
	info.hide();
	var movie = $('notice_movie_' + notice);
	movie.hide();

	$('tloCena'+notice).show();
	$('cena'+notice).show();


	var pictures = field.childElements();
	for(var i = 0; i < pictures.length; i++){
		if(pictures[i].readAttribute('id') == 'picture_'+notice+'_'+picture){
//			Effect.Appear(pictures[i]);
			pictures[i].show();
		}else if(pictures[i].visible){
//			Effect.Fade(pictures[i]);
			pictures[i].hide();
		}
	}

	for(var i = 0; i < 49; i++){
		
		var button = $('picbutton_'+notice+'_'+i);
		if(button != null){
			button.show();
			var button2 = $('picbutton_klik_'+notice+'_'+i);
			if(button2 != null){
				button2.hide();
			}
		}
	}

	button = $('picbutton_'+notice+'_'+picture);
	button.hide();
	button2 = $('picbutton_klik_'+notice+'_'+picture);
	button2.show();
	
	var infoButton = $('info_button_' + notice);
	infoButton.show();
	var infoButton2 = $('info_button_klik_' + notice);
	infoButton2.hide();
	
	var videoButton = $('video_button_' + notice);
	videoButton.show();
	var videoButton2 = $('video_button_klik_' + notice);
	videoButton2.hide();
	
	var currPict = $('currPict_'+notice);
	var p=parseInt(picture)+1;
	currPict.update(p.toString());
	
}

function showSwitchers(notice){
	var rollBar = $('rollBar_'+notice);
	var blackBar = $('blackBar_'+notice);
	rollBar.show();
	blackBar.hide();

}

function hideSwitchers(notice){
	var rollBar = $('rollBar_'+notice);
	var blackBar = $('blackBar_'+notice);
	rollBar.hide();
	blackBar.show();

}


function showInfo(notice){
	hideSwitchers(notice);
	var field = $('notice_' + notice);
	var pictures = field.childElements();
	for(var i = 0; i < pictures.length; i++){
		pictures[i].hide();
	}

	$('tloCena'+notice).hide();
	$('cena'+notice).hide();
	var movie = $('notice_movie_' + notice);
	movie.hide();
	var info = $('notice_info_' + notice);
	info.show();
	for(var i = 0; i < 49; i++){
		
		var button = $('picbutton_'+notice+'_'+i);
		if(button != null){
			button.show();
			var button2 = $('picbutton_klik_'+notice+'_'+i);
			if(button2 != null){
				button2.hide();
			}
		}
	}
	
	var videoButton = $('video_button_' + notice);
	videoButton.show();
	var videoButton2 = $('video_button_klik_' + notice);
	videoButton2.hide();
	
	var infoButton = $('info_button_' + notice);
	infoButton.hide();
	var infoButton2 = $('info_button_klik_' + notice);
	infoButton2.show();
}

function showMovie(notice){
	var field = $('notice_' + notice);
	var pictures = field.childElements();
	for(var i = 0; i < pictures.length; i++){
		pictures[i].hide();
	}

	$('tloCena'+notice).hide();
	$('cena'+notice).hide();

	var info = $('notice_info_' + notice);
	info.hide();
	var movie = $('notice_movie_' + notice);
	movie.show();
	
	for(var i = 0; i < 49; i++){
		var button = $('picbutton_'+notice+'_'+i);
		if(button != null){
			button.show();
			var button2 = $('picbutton_klik_'+notice+'_'+i);
			if(button2 != null){
				button2.hide();
			}
		}
	}
	
	var videoButton = $('video_button_' + notice);
	videoButton.hide();
	var videoButton2 = $('video_button_klik_' + notice);
	videoButton2.show();
}


function addKlik(id){
	var button = $(id);
	var button_klik = $(id+"_klik");
	button.hide();
	button_klik.show();
	
}

function removeKlik(id){
	var button = $(id);
	var button_klik = $(id+"_klik");
	button.show();
	button_klik.hide();
	
}
var pierwszeZLewej = new Array(1,1,1,1);
function moveRight(noticeId, picNum, modNum, address){

	if(parseInt(parseInt(activePic[modNum]))+1  ==  pierwszeZLewej[parseInt(modNum)]+5){
		if(pierwszeZLewej[parseInt(modNum)]+6 <= picNum){
			if(pierwszeZLewej[parseInt(modNum)] + 6 <= 48){
	
				for(var i = 1; i <= 6 ; i++){
					var nowyNumer = pierwszeZLewej[parseInt(modNum)] + i;
					var nowyNumer2 = nowyNumer - 1;
					var td = $('picbuttontd_' + noticeId + '_' + i);
					if(nowyNumer > parseInt(picNum)){
						td.writeAttribute('onclick', "");
						td.update("<img  id='picbutton_"+noticeId+"_"+nowyNumer2.toString()+"' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/"+nowyNumer.toString()+"bttn_empty.jpg' width='27' height='23' />");
					}else{
						var onclick = td.readAttribute('onclick');
						onclick = onclick.substr(12).replace(')', '');
						var onclickTab = onclick.split(',');
						var newOnClick = "showPicture(" + onclickTab[0] + ", " + onclickTab[1] + ", '" + nowyNumer2.toString() + "')"; 
						td.writeAttribute('onclick', newOnClick);
						td.update("<img id='picbutton_" + noticeId + "_" + nowyNumer2.toString() + "' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/" + nowyNumer.toString() + "bttn.jpg' width='27' height='23' /><img style='display: none;' id='picbutton_klik_" + noticeId + "_" + nowyNumer2.toString() + "' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/" + nowyNumer.toString() + "bttn_klik.jpg' width='27' height='23' />");
								
					}
				}
				pierwszeZLewej[parseInt(modNum)]++;
			}
		}
	}	
	if(parseInt(activePic[parseInt(modNum)])+1 < picNum){
		var next = parseInt(activePic[parseInt(modNum)])+1;
		showPicture(noticeId, address, next.toString(), modNum);
	}
}
function rewindRight(noticeId, picNum, modNum){
	if(pierwszeZLewej[parseInt(modNum)]+6 <= picNum){
		for(var i = 0; i < 6; i++){
			moveRight(noticeId, picNum, modNum);
		}
	}
}
function moveLeft(noticeId, picNum, address, modNum){
	if(parseInt(activePic[parseInt(modNum)]) - 1 == pierwszeZLewej[modNum]-2){
	if(pierwszeZLewej[parseInt(modNum)] -1 >= 1){
		for(var i = 1; i <= 6 ; i++){
			var nowyNumer = pierwszeZLewej[parseInt(modNum)] + i - 2;
			var nowyNumer2 = nowyNumer - 1;
			var td = $('picbuttontd_' + noticeId + '_' + i);
			if(nowyNumer > parseInt(picNum)){
				td.writeAttribute('onclick', "");
				td.update("<img  id='picbutton_"+noticeId+"_"+nowyNumer2.toString()+"' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/"+nowyNumer.toString()+"bttn_empty.jpg' width='27' height='23' />");
			}else{
				var onclick = td.readAttribute('onclick');
				if(onclick != null && onclick != ''){
					onclick = onclick.substr(12).replace(')', '');
					var onclickTab = onclick.split(',');
					var newOnClick = "showPicture(" + onclickTab[0] + ", " + onclickTab[1] + ", '" + nowyNumer2.toString() + "')"; 
					td.writeAttribute('onclick', newOnClick);
				}else{
					td.writeAttribute('onclick', "showPicture('" + noticeId + "', '" + address + "', '" + nowyNumer2.toString() + "')");
				}
				td.update("<img id='picbutton_" + noticeId + "_" + nowyNumer2.toString() + "' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/" + nowyNumer.toString() + "bttn.jpg' width='27' height='23' /><img style='display: none;' id='picbutton_klik_" + noticeId + "_" + nowyNumer2.toString() + "' class='button' src='/~tomek/teneryfa/public/images/buttons/pictures/" + nowyNumer.toString() + "bttn_klik.jpg' width='27' height='23' />");		
			}
		}
		pierwszeZLewej[parseInt(modNum)]--;
	}
	}
	if(parseInt(activePic[parseInt(modNum)])-1 >= 0){
		var next =  parseInt(activePic[parseInt(modNum)])-1;
                showPicture(noticeId, address, next.toString(), modNum);
        }

}
function rewindLeft(noticeId, picNum, address,modNum){
	for(var i = 0; i < 6; i++){
		moveLeft(noticeId, picNum, address, modNum);
	}
}

function showAir(){
	$('air').toggle();
}
function darkBackground(){

       var bg = $('darkbackground');
       var body = $('cialo');
       bg.writeAttribute('style', 'z-index: 2; background-color: black; border: 1px solid; position: absolute; display: none; top: 0px; left: 0px; width: '+body.getWidth()+'px; height:'+body.getHeight()+'px;');
       Effect.Appear('darkbackground', {to: 0.5});


}

/**
 * @author Sławomir Kokłowski {@link http://www.kurshtml.boo.pl}
 * @copyright NIE usuwaj tego komentarza! (Do NOT remove this comment!)
 */
//
//function Menu(id, style, otworz, wysun, czasRozwin, czasZwin, czasOtworz, czasZamknij, nieInicjalizuj)
//{
//	if (typeof czasRozwin == 'undefined' || czasRozwin < 0) czasRozwin = 25;
//	if (typeof czasZwin == 'undefined' || czasZwin < 0) czasZwin = 25;
//	if (typeof czasOtworz == 'undefined' || czasOtworz < 0) czasOtworz = 250;
//	if (typeof czasZamknij == 'undefined' || czasZamknij < 0) czasZamknij = 500;
//	
//	if (style)
//	{
//		if (style.indexOf(':') < 0)
//		{
//			document.getElementById(id).className += ' ' + style;
//		}
//		else
//		{
//			style = style.replace(/(^\s+|(\s|;)+$)/g, '').split(/\s*;\s*/);
//			for (var i = 0; i < style.length; i++)
//			{
//				style[i] = style[i].split(/\s*:\s*/);
//				for (var j = 0, c, property = ''; j < style[i][0].length; j++)
//				{
//					c = style[i][0].charAt(j);
//					property += c == '-' ? style[i][0].charAt(++j).toUpperCase() : c.toLowerCase();
//				}
//				eval('document.getElementById("' + id + '").style.' + property + ' = "' + style[i][1].replace(/"/g, '\\"') + '"');
//			}
//		}
//	}
//	
//	for (var i = 0; i < document.getElementById(id).getElementsByTagName('dt').length; i++)
//	{
//		var dd = new Array();
//		var el = document.getElementById(id).getElementsByTagName('dt')[i].nextSibling;
//		var nodeName;
//		while (el && (nodeName = el.nodeName.toLowerCase()) != 'dt')
//		{
//			if (nodeName == 'dd')
//			{
//				el._dt = document.getElementById(id).getElementsByTagName('dt')[i];
//				if (otworz)
//				{
//					el.onmouseover = function()
//					{
//						clearTimeout(this._dt._timoutID);
//						this._dt._displayed = false;
//						this._dt.onclick();
//					}
//					el.onmouseout = function()
//					{
//						clearTimeout(this._dt._timoutID);
//						var dt = this._dt;
//						this._dt._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
//					};
//				}
//				dd[dd.length] = el;
//			}
//			el = el.nextSibling;
//		}
//		document.getElementById(id).getElementsByTagName('dt')[i]._dd = dd;
//		document.getElementById(id).getElementsByTagName('dt')[i]._timoutID = null;
//		document.getElementById(id).getElementsByTagName('dt')[i]._displayed = false;
//		document.getElementById(id).getElementsByTagName('dt')[i].onclick = function()
//		{
//			clearTimeout(this._timoutID);
//			if (!this._displayed)
//			{
//				var el = this.parentNode.getElementsByTagName('dt')[0];
//				while (el)
//				{
//					if (el.nodeName.toLowerCase() == 'dt' && el != this)
//					{
//						el._displayed = false;
//						if (czasZwin) display(el, 0);
//						else display(el);
//					}
//					el = el.nextSibling;
//				}
//			}
//			this._displayed = !this._displayed;
//			if (this._displayed && czasRozwin || !this._displayed && czasZwin) display(this, 0);
//			else display(this);
//		};
//		if (otworz)
//		{
//			document.getElementById(id).getElementsByTagName('dt')[i].onmouseover = function()
//			{
//				clearTimeout(this._timoutID);
//				var dt = this;
//				this._timoutID = setTimeout(function () { dt._displayed = false; dt.onclick(); }, czasOtworz);
//			};
//			document.getElementById(id).getElementsByTagName('dt')[i].onmouseout = function()
//			{
//				clearTimeout(this._timoutID);
//				var dt = this;
//				this._timoutID = setTimeout(function () { dt._displayed = true; dt.onclick(); }, czasZamknij);
//			};
//		}
//	}
//	
//	start(document.getElementById(id).getElementsByTagName('dt')[0]);
//	
//	function start(dt)
//	{
//		var hide = true;
//		var el = dt;
//		while (el)
//		{
//			var nodeName = el.nodeName.toLowerCase();
//			if (nodeName == 'dt')
//			{
//				dt = el;
//				hide = true;
//			}
//			if (nodeName == 'dt' || nodeName == 'dd')
//			{
//				if (!nieInicjalizuj && el.getElementsByTagName('a').length && el.getElementsByTagName('a')[0].href && unescape(el.getElementsByTagName('a')[0].href) == unescape(window.location.href))
//				{
//					el.className = (el.className ? el.className + ' ' : '') + 'active';
//					dt._displayed = true;
//					display(dt);
//					hide = false;
//					var el_parentNode = el.parentNode;
//					while (el_parentNode != document.getElementById(id))
//					{
//						if (el_parentNode.nodeName.toLowerCase() == 'dd')
//						{
//							var el_sibling = el_parentNode.previousSibling;
//							while (el_sibling)
//							{
//								if (el_sibling.nodeName.toLowerCase() == 'dt')
//								{
//									el_sibling._displayed = true;
//									display(el_sibling)
//									break;
//								}
//								el_sibling = el_sibling.previousSibling;
//							}
//						}
//						el_parentNode = el_parentNode.parentNode;
//					}
//				}
//			}
//			if (nodeName == 'dd')
//			{
//				if (hide) el.style.display = 'none';
//				start(el.getElementsByTagName('dt')[0]);
//			}
//			el = el.nextSibling;
//		}
//	}
//	
//	function display(dt, i)
//	{
//		if (typeof i == 'undefined')
//		{
//			for (var i = 0; i < dt._dd.length; i++)
//			{
//				dt._dd[i].style.display = dt._displayed ? 'block' : 'none';
//				if (!dt._displayed)
//				{
//					for (var j = 0; j < dt._dd[i].getElementsByTagName('dt').length; j++)
//					{
//						dt._dd[i].getElementsByTagName('dt')[j]._displayed = false;
//						display(dt._dd[i].getElementsByTagName('dt')[j]);
//					}
//				}
//			}
//		}
//		else if (i < dt._dd.length)
//		{
//			var dir = wysun ? !dt._displayed : dt._displayed;
//			var n = dir ? i : dt._dd.length - 1 - i;
//			dt._dd[n].style.display = dt._displayed ? 'block' : 'none';
//			if (!dt._displayed)
//			{
//				for (var j = 0; j < dt._dd[n].getElementsByTagName('dt').length; j++)
//				{
//					dt._dd[n].getElementsByTagName('dt')[j]._displayed = false;
//					display(dt._dd[n].getElementsByTagName('dt')[j]);
//				}
//			}
//			dt._timoutID = setTimeout(function() { display(dt, i + 1); }, dt._displayed ? czasRozwin : czasZwin);
//		}
//	}
//}
