
function SubmenuShow(id)
{
	var submenuShowId = id+'S';
	
	for (i = 1; i <= 100; i++)
	{
		if (!document.getElementById('M'+i+'S'))
		{
			break;
		}
		
		var mId = 'M'+i;
		if (mId == id)
		{
			document.getElementById(id).className = "active";
			if (document.getElementById(submenuShowId))
				document.getElementById(submenuShowId).className = "submenu-show";
		}
		else
		{
			var subId = 'M'+i+'S';
			document.getElementById(mId).className = "";
			if (document.getElementById(subId))
				document.getElementById(subId).className = "";
		}
	}
}

function OpenNews(id)
{
	if (document.getElementById(id))
	{
		if (document.getElementById(id).style.display == 'none')
		{
			document.getElementById(id).style.display = '';
		}
		else
		{
			document.getElementById(id).style.display = 'none';
		}
	}
}

function SwitchTourBox(id)
{
	for (var i = 1; i <= 4; i++)
	{
		var b = document.getElementById('TourBox'+i);
		var l = document.getElementById('TourBoxLink'+i);
		if (b)
		{
			if (i == id)
			{
				b.style.display = '';
				l.className = 'tour-box-link-active';
			}
			else
			{
				b.style.display = 'none';
				l.className = '';
			}
		}
	}
}

function SwitchFilter(id)
{
	for (var i = 1; i <= 2; i++)
	{
		var b = document.getElementById('Filter'+i);
		var l = document.getElementById('FilterLink'+i);
		if (b)
		{
			if (i == id)
			{
				b.style.display = '';
				l.className = 'filter-link-active';
			}
			else
			{
				b.style.display = 'none';
				l.className = '';
			}
		}
	}
}

var activeOplGp = 0;
function SwitchOplRes(id, oplId)
{
	activeOplGp = oplId;
	
	for (var i = 1; i <= 20; i++)
	{
		if (document.getElementById('OplRes'+i))
		{
			var b = document.getElementById('OplRes'+i);
			var l = document.getElementById('OplResLink'+i);
			if (b)
			{
				if (i == id)
				{
					b.style.display = '';
					l.className = 'filter-link-active';
				}
				else
				{
					b.style.display = 'none';
					l.className = '';
				}
			}
		}
		else
		{
			break;
		}
	}
}

function SetOplRes(obj)
{
	if (activeOplGp)
	{
		obj.href = obj.href + '?fGp=' + activeOplGp;
	}
}


function TexyFormat(w)
{
	var e = document.getElementById('Content');
	var s = document.selection;
	e.focus();
	
	if (s)
	{
		var r = s.createRange();
		var d = r.duplicate();
		
		var t1 = d.text.replace(/^(\s+)/,"");
		var pre = RegExp.$1
		t1 = t1.replace(/(\s+)$/,"");
		var t = pre + w + t1 + w + RegExp.$1
	}
	else
	{
		var ss = e.selectionStart;
		var se = e.selectionEnd;
		
		var t1 = e.value.substring(ss,se).replace(/^(\s+)/,"");
		var pre = RegExp.$1
		t1 = t1.replace(/(\s+)$/,"");
		var post = RegExp.$1;
		
		var t = pre + w + t1 + w + RegExp.$1
		
		if (pre.length) ss += pre.length;
		if (post.length) se -= post.length;
		
		var t = e.value.substring(0,ss) + w + t1 + w + e.value.substring(se);
		//var t = e.value.substring(0,ss) + w + e.value.substring(ss,se) + w + e.value.substring(se);
	}
	
	t = t.replace(/( )+\[\/(i|b)\]/img,"[/$2]$1");
	
	if (d)
	{
		d.text = t;
	}
	else
	{
		e.value = t;
		e.selectionEnd = e.selectionStart = ss;
	}
	
	return false;
}

function TexySmile(w)
{
	var e = document.getElementById('Content');
	var s = document.selection;
	e.focus();
	
	if (s)
	{
		var r = s.createRange();
		var d = r.duplicate();
		var t = d.text+w;
	}
	else
	{
		var ss = e.selectionStart;
		var se = e.selectionEnd;
		var t = e.value.substring(0,ss)+e.value.substring(ss,se)+w+e.value.substring(se);
	}
	
	if (d)
	{
		d.text = t;
	}
	else
	{
		e.value = t;
		e.selectionEnd = e.selectionStart = ss;
	}
	
	return false;
}



/* AJAX ============================================================================================================ */
function AjaxLoader(url, place)
{
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		httpRequest = new XMLHttpRequest();
	}
	
	if (!httpRequest)
		return false;
	
	httpRequest.open('GET', url);
	httpRequest.onreadystatechange = function () { AjaxResult(place); };
	httpRequest.send(null);
}

function AjaxResult(place)
{
	if (httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			//alert(httpRequest.responseXML.getElementsByTagName('h4').length);
			//var odpovedi = httpRequest.responseXML.getElementsByTagName('h4');
			//alert(odpovedi.length);
			
			
			var oPlace = document.getElementById(place);
			if (oPlace)
			{
				oPlace.innerHTML = httpRequest.responseText;
				
				if (document.getElementById('VgalFlvFile'))
				{
					var player = document.getElementById('VgalFlvPlayer').value;
					var file = document.getElementById('VgalFlvFile').value;
					var image = document.getElementById('VgalFlvImage').value;
					var id = document.getElementById('VgalFlvId').value;
					
					var sJsCmsVideoAjax = new SWFObject(player,"player","500","375","9");
					sJsCmsVideoAjax.addParam("allowfullscreen","true");
					sJsCmsVideoAjax.addParam("allowscriptaccess","always");
					sJsCmsVideoAjax.addParam("wmode","opaque");
					sJsCmsVideoAjax.addVariable("file",file);
					sJsCmsVideoAjax.addVariable("image",image);
					sJsCmsVideoAjax.addVariable("backcolor","000000");
					sJsCmsVideoAjax.addVariable("frontcolor","CCCCCC");
					sJsCmsVideoAjax.addVariable("lightcolor","525252");
					sJsCmsVideoAjax.addVariable("buffer","5");
					sJsCmsVideoAjax.addVariable("width","500");
					sJsCmsVideoAjax.addVariable("height","375");
					sJsCmsVideoAjax.write(id);
				}
				//window.execScript(document.getElementById('VgalScript').innerText, 'javascript');
			}
		}
	}
}


/* SCROLLER ================================================================================================================== */

var pgalScrollerWidth = 91;
var pgalScrollerMoveBy = 5;
var pgalScrollerPosition = 0;
var pgalScrollerItem = 1;
var pgalScrollerItems = 0;
var pgalScrollerInProcess = false;
var pgalScrollerMover = null;

function PgalScrollerMove(direction)
{
	if (!pgalScrollerItems)
		return;
	
	if (!pgalScrollerMover)
		pgalScrollerMover = document.getElementById('PgalRollerMover');
	
	if (pgalScrollerInProcess)
		return;
	
	var by = 0;
	
	if(direction == 'next')
	{
		if (pgalScrollerItem + pgalScrollerMoveBy > pgalScrollerItems)
			by = 0;
		else if (pgalScrollerItem + (pgalScrollerMoveBy * 2) > pgalScrollerItems)
			by = pgalScrollerMoveBy - ((pgalScrollerItem + (pgalScrollerMoveBy * 2)) - pgalScrollerItems) + 1;
		else
			by = pgalScrollerMoveBy;
		
		pgalScrollerItem += by;
		
		if (by)
		{
			move = pgalScrollerWidth * by;
			PgalScrollerMoveBy(-move);
			pgalScrollerInProcess = true;
		}
	}
	
	if(direction == 'previous')
	{
		if (pgalScrollerItem == 1)
			by = 0;
		else if (pgalScrollerItem - pgalScrollerMoveBy < 1)
			by = pgalScrollerItem - 1;
		else
			by = pgalScrollerMoveBy;
		
		pgalScrollerItem -= by;
		
		if (by)
		{
			move = pgalScrollerWidth * by;
			PgalScrollerMoveBy(move);
			pgalScrollerInProcess = true;
		}
	}
	
}

function PgalScrollerMoveBy(px)
{
	var step = getStep(px);
	
	if (px < 0)
		step = -step;
	
	pgalScrollerPosition = pgalScrollerPosition + step
	
	pgalScrollerMover.style.left = pgalScrollerPosition + "px";
	pgalScrollerMover.position = pgalScrollerPosition;
	
	px -= step;
	if (px)
		window.setTimeout('PgalScrollerMoveBy(' + px.toString() + ')', 10);
	else
		pgalScrollerInProcess = false;
}

function getStep(px)
{
	if(px < 0)
		px = -px;
	
	if(px >= 300)
		return 50;
	
	if(px >= 50)
		return 20;
	
	if(px >= 10)
		return 5;
	
	return 1;
}


function ReloadPhotogallery(path, id, items)
{
	PgalSlideshowStop();
	
	pgalScrollerItem = 1;
	pgalScrollerItems = items;
	pgalScrollerPosition = 0;
	pgalScrollerMover = null;
	
	AjaxLoader(path, id);
	window.location = '#PgalScr';
}

function ReloadVideogallery(path, id)
{
	AjaxLoader(path, id);
	window.location = '#VgalScr';
}


var pgalSlideshowRun = false;
var pgalSlideshowNextId;
var pgalSlideshowInterval;
var pgalSlideshowUrl = '';

function PgalSlideshowPlay()
{
	//alert('PLAY');
	document.getElementById('PgalSlidePlay').style.display = 'none';
	document.getElementById('PgalSlideStop').style.display = '';
	
	pgalSlideshowRun = true;
	
	if (PgalSlideshowReload())
		pgalSlideshowInterval = window.setInterval('PgalSlideshowReload()', 6000);
}

function PgalSlideshowStop()
{
	//alert('STOP');
	document.getElementById('PgalSlidePlay').style.display = '';
	document.getElementById('PgalSlideStop').style.display = 'none';
	
	pgalSlideshowRun = false;
	
	if (pgalSlideshowInterval)
		window.clearInterval(pgalSlideshowInterval);
}

function PgalSlideshowReload()
{
	//alert('RELOAD');
	if (!pgalSlideshowRun)
	{
		PgalSlideshowStop();
		return false;
	}
	
	if (!document.getElementById('PgalTopNextId'))
	{
		PgalSlideshowStop();
		return false;
	}
	
	var nextId = parseInt(document.getElementById('PgalTopNextId').value);
	
	if (!nextId || !pgalSlideshowUrl)
	{
		PgalSlideshowStop();
		return false;
	}
	
	var url = pgalSlideshowUrl + String(nextId);
	AjaxLoader(url, 'PgalTopImgBox');
	
	return true;
}


function limitText(limitField, limitNum)
{
	if (limitField.value.length > limitNum)
	{
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}











