var step=5; 
var objDialogWindow = null;
var cartsCounter = 0;
var arrCart1 = new Array();
var arrCart2 = new Array();
var arrCart3 = new Array();

// ------------- oldalterület görgetése -------------------------------------------------------------------

function verifyCompatibleBrowser()
{ 
	this.ver = navigator.appVersion ;
    this.dom = document.getElementById ? 1 : 0 
    this.ie5=(this.ver.indexOf("MSIE")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5); 
    return this;
} 

var speed=1; 
var bw=new verifyCompatibleBrowser();
var loop;
var timer;
var initialised; 
var actualSubtitleIndex = 0;

function ConstructObject(obj,nest)
{ 
    nest=(!nest) ? '':'document.'+nest+'.'; 
    this.el = bw.dom ? document.getElementById(obj) : bw.ie4 ? document.all[obj] : bw.ns4 ? eval(nest+'document.'+obj) : 0; 
    this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style: bw.ns4 ? eval(nest+'document.'+obj):0; 
    this.scrollHeight = bw.ns4 ? this.css.document.height : this.el.offsetHeight; 
    this.clipHeight = bw.ns4 ? this.css.clip.height : this.el.offsetHeight;
    this.up=MoveAreaUp;
	this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; 
	this.x; 
	this.y; 
    this.obj = obj + "Object"; 
    eval(this.obj + "=this");
    return this;
} 

function MoveArea(x,y)
{ 
    this.x=x;
	this.y=y; 
    this.css.left=this.x;
    this.css.top=this.y; 
} 
 
function MoveAreaDown(move)
{ 
    if (this.y>-this.scrollHeight+objContainer.clipHeight)
	{ 
    	this.MoveArea(0,this.y-move); 
	    if(loop) setTimeout(this.obj+".down("+move+")",speed); 
    } 
} 

function MoveAreaUp(move)
{ 
	if(this.y<0)
	{ 
    	this.MoveArea(0,this.y-move) 
	    if(loop) setTimeout(this.obj+".up("+move+")",speed); 
    } 
} 
 
function PerformScroll(nspeed)
{ 
        if(initialised)
		{ 
            nspeed = nspeed*step;
			 loop=true; 
             if(nspeed>0) objScroller.down(nspeed); 
             else objScroller.up(nspeed); 
        } 
} 
 
function PerformPicScroll(nspeed)
{ 
        if(initialised)
		{ 
                loop=true; 
	            nspeed = nspeed*step;
                if(nspeed>0) objPicScroller.down(nspeed); 
                else objPicScroller.up(nspeed); 
        } 
} 

function CeaseScroll()
{ 
    loop=false; 
    if(timer) clearTimeout(timer); 
} 

function InitialiseScrollableArea()
{ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 

    objPicContainer=new ConstructObject('divPicContainer') 
    objPicScroller=new ConstructObject('divPicContent','divPicContainer') 
    objPicScroller.MoveArea(0,0) 
    objPicContainer.css.visibility='visible' 

    initialised=true; 

//	if (bw.ns4 || bw.ns5) step=10;
} 


function MM_swapImgRestore() 
{ 
  var i,x,a=document.MM_sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() 
{ 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// ------------- képcsere -------------------------------------------------------------------
function ChangeImage(imagePath,imageWidth,imageHeight,subtitleIndex)
{
	if (imagePath != actualImagePath) actualSubtitleIndex = subtitleIndex;
	subtitle = subtitles[subtitleIndex];
	actualImagePath = imagePath;
	actualImageWidth = imageWidth;
	actualImageHeight = imageHeight;

	if (subtitle.length<1) subtitle = '';

	var content = "<table border=0 cellpadding=0 cellspacing=0 width='150' align='right'><tr>"+
		   		  "<td align=right><img name='picture' src='"+imagePath+"' width='"+imageWidth+"' height='"+imageHeight+"' border=1 hspace=0 vspace=0 class='keretes'></td></tr>";
	if (subtitle.length>1)
			content+= "<tr><td align=right valign='top' class='feherk'><table border=0 cellpadding='3' cellspacing='0' width='100%'><tr>"+
		        	  "<td class='feherk'>"+subtitle+"</td></tr></table></td></tr></table>";
	if (bw.ns4)
	{
		document.divPictureLayer.document.open();
		document.divPictureLayer.document.write(content);
		document.divPictureLayer.document.close(); 
	}
	else if (bw.ie4) document.all['divPictureLayer'].innerHTML = content;
	else document.getElementById('divPictureLayer').innerHTML = content;
}

// ------------------ tovább ugrás, másik honlapra --------------------------------------------
function HomePage(id,language){
	var timeObj = new Date();
	var pageURL = homePageSystemRoot+"objektum.php";
	pageURL+= '?sablon=' + templateNumber;
	pageURL+= '&id=' + id;
	pageURL+= '&nyelv=' + language;
	homePageWin = window.open(pageURL,'','top=5,left=5,width=785,height=440,scrollbars=1,resizable=1');
}

function AddObjectToCorb(argObjectId)
{
 	if (top.opener != null) top.opener.AddObjectToCorb(argObjectId);
}

//---------------- listában következő honlap kirakása ----------------------------------------

var arrObjectIds = new Array(1);
var objectIndex = -1;

function GetObjectIndex()
{
	if (top.opener == undefined) return;
	if (top.opener.document == undefined) return;
	if (top.opener.document.f == undefined) return;
	if (top.opener.document.f.OLResults == undefined) return;
	if (top.opener == null) return;
	if (top.opener.document == null) return;
	if (top.opener.document.f == null) return;
	if (top.opener.document.f.OLResults == null) return;
	if (top.opener.document.f.OLResults.value.indexOf('+')==-1) return;
	arrObjectIds = top.opener.document.f.OLResults.value.split('+');
	var cntObjectIds = arrObjectIds.length;
	for (i=0;i<cntObjectIds;i++)
	{
		if (arrObjectIds[i]==objectId) objectIndex=i;
	}
}

function NextObject()
{
	if (objectIndex == -1) return;
	cntObjects = (arrObjectIds.length-2);
	if (objectIndex<cntObjects) objectIndex++;
	else objectIndex = 0;
	id = arrObjectIds[objectIndex];
	if (id==objectId)
	{
		NextObject();
		return;
	}
	
	pageURL = homePageSystemRoot+"objektum.php";
	pageURL+= '?sablon=' + templateNumber;
	pageURL+= '&id=' + id;
	pageURL+= '&nyelv=' + language;
	top.opener.OpenDialogWindow('785','430',pageURL,'auto');
}

function PrevObject()
{
	if (objectIndex == -1) return;
	cntObjects = (arrObjectIds.length-2);
	if (objectIndex>0) objectIndex--;
	else objectIndex = cntObjects;
	id = arrObjectIds[objectIndex];
	if (id==objectId)
	{
		PrevObject();
		return;
	}

	pageURL = homePageSystemRoot+"objektum.php";
	pageURL+= '?sablon=' + templateNumber;
	pageURL+= '&id=' + id;
	pageURL+= '&nyelv=' + language;
	top.opener.OpenDialogWindow('785','430',pageURL,'auto');
}


function OpenDialogWindow(iWidth,iHeight,URL,scrollbars)
{
	var fClosed=false;   
	var iLeft=window.screen.width/2 - iWidth/2;
	var iTop=window.screen.height/2 - iHeight/2 - 25;   
  
  	if (iWidth>700) iWidth = 700;
  	if (iHeight>500) iHeight = 500;
	   
	if (objDialogWindow != null)
	{
		if (!objDialogWindow.closed)
		{
			objDialogWindow.close(); 
			while (fClosed != objDialogWindow.closed)
			{
				fClosed = objDialogWindow.closed;
			}     
		}
	}       
	objDialogWindow=window.open(URL,"_blank",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scrollbars+',resizable=1,width=' + iWidth + ',height=' + iHeight + ',screenX=' + iLeft + ',screenY=' + iTop + ',left=' + iLeft + ',top=' + iTop);   
}

function GetCookie(name) 
{
    var index = document.cookie.indexOf(name + "=");
    if (index == -1) return null;
    index = document.cookie.indexOf("=", index) + 1; 
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) endstr = document.cookie.length; 
    return unescape(document.cookie.substring(index, endstr));
}

function WriteCartsCounter()
{
	cartContent1 = GetCookie("objectsCart");
	cartContent2 = GetCookie("destinationsCart");
	cartContent3 = GetCookie("programsCart");

	if (cartContent1) arrCart1 = cartContent1.split("+");
	if (cartContent2) arrCart2 = cartContent2.split("+");
	if (cartContent3) arrCart3 = cartContent3.split("+");

	cartsCounter = arrCart1.length + arrCart2.length + arrCart3.length;
	if (cartsCounter>0) document.write(" (" + cartsCounter + ")");
}

// VIRTUÁLIS BARANGOLÁS

var sdur=2; //time to show a pic between fades in seconds
var fdur=1; //duration of the complete fade in seconds
var steps=20; //steps to fade from on pic to the next
var actualPicNum = 1;
var parr = new Array();
var ptofade = false;
var pnext = false;
var ftim = fdur * 1000 / steps;
var stim = sdur * 1000;
var pause = false;
var u = 0;
var slideInProgress = false;

function RoamCreateParr()
{
	parr = new Array();
	for(a = 1; a <= pictureNumber; a++) 
	{
		idakt="img"+a;
		paktidakt = document.getElementById(idakt);
	    ie5exep = new Array(paktidakt);
		parr = parr.concat(ie5exep);
	}
	return parr;
}

/* --------------------------  VIRTUÁLIS BARANGOLÁS ----------------------------------*/

var whichlink;
var whichimage = 0;
var timelayers = new Array();
var pause;
var interval1;
var interval2;
var operation = "changeImage";
var slideWaiting = 5000;
var counter = 0;
var alpha = 0;

function CacheImage(ImageSource) 
{ 
//window.alert("CacheImage("+ImageSource+")");
   var ImageObject = new Image();
   ImageObject.src = ImageSource;
   return ImageObject;
}

function DownloadCompleted() 
{
//   window.alert("Download()");
   if (slideimages[whichimage].complete) 
   {
   		slideReady = true;
        self.defaultStatus = '';
		return true;
   } 
   else return false;
}

function CacheNextSlide() 
{
   if ((whichimage < slideimages.length) && (typeof slideimages[whichimage] == 'string'))
	{ 
      self.defaultStatus = 'Downloading next picture...';
      slideimages[whichimage] = CacheImage(slideimages[whichimage]);
   }
   return true;
}


function gotoshow()
{
	HomePage(slidelinks[whichlink],document.f.hdnLanguage.value);
	Stop();
}

function StartSlideShow() 
{
   if (!document.getElementById)
   {
 		window.alert("Az Ön böngészője nem támogatja az oldalon futó vetítő alkalmazást!\nYour browser does not support the slide show application of this site!");
  		return;
   }

//window.alert("StartSlideShow()");
   whichlink=0;
   whichimage = 0;
   slideimages[0] = CacheImage(slideimages[0]);
   pause = false;
   ShowLayer("divStopButton","visible");
   ShowLayer("divPrevButton","visible");
   ShowLayer("divNextButton","visible");
   SlideIt();
   ShowTimeRemained();
}

function ShowLayer(name,visibility)
{
  if (document.getElementById)  document.getElementById(name).style.visibility = visibility;
  else if (document.all) document.all[name].style.visibility = visibility;
  else if (document.layers) document.layers[name].visibility = visibility;
}

function Previous()
{
	Stop();
	if (whichimage==0) whichimage = slideimages.length-2;
	else if (whichimage == 1) return;
	else whichimage-=2;
	pause = false;
    operation = "changeImage";
	SlideIt();
	Stop();
}

function Next()
{
	Stop();
	pause = false;
    operation = "changeImage";
	SlideIt();
	Stop();
}

function Stop()
{
	pause = true;
	counter = 0;
	clearTimeout(interval1);
	clearTimeout(interval2);
	for (i=0;i<15;i++) ShowLayer("divTime"+i,"hidden");	
	ShowLayer("divStopButton","hidden");
	ShowLayer("divStartButton","visible");
	var sliderLayer = document.getElementById("divSlider");
	sliderLayer.style.filter = "Alpha(Opacity=100)";
	sliderLayer.style.MozOpacity = 1;
}

function Restart()
{
//   if (whichimage==0) whichimage = slideimages.length-1;
//   else whichimage-=1;
   operation = "fadeIn";
   pause = false;
   SlideIt();
   ShowTimeRemained();
   ShowLayer("divStartButton","hidden");
   ShowLayer("divStopButton","visible");
}

function SlideIt()
{
	if (operation=="waitForDownload")
	{
		if (DownloadCompleted()) operation="fadeOut";
		interval2 = setTimeout("SlideIt()",10);
	}
	else if (operation=="fadeIn")
	{
		var sliderLayer = document.getElementById("divSlider");
		sliderLayer.style.filter = "Alpha(Opacity="+alpha+")";
		sliderLayer.style.MozOpacity = alpha/100;
		if (alpha<100)
		{
			alpha+=10;
			interval2 = setTimeout("SlideIt()",20);
		}
		else
		{
			sliderLayer.style.filter = "Alpha(Opacity=100)";
			sliderLayer.style.MozOpacity = 1;
			operation = "waitForDownload";
			interval2 = setTimeout("SlideIt()",slideWaiting);
		}
	}
	else if (operation=="changeImage")
	{
		document.images.slide.src=slideimages[whichimage].src;
		if (slideuntertitles[whichimage])
		{
			document.getElementById('divText').innerHTML = "<table cellpadding=2 cellspacing=0 border=0 width=330><tr><td class=feherk width=200>&nbsp;</td><td class=feherk>"+slideuntertitles[whichimage]+"</td></tr></table>";
		}
		whichlink=whichimage;
		whichimage=(whichimage<slideimages.length-1)? whichimage+1 : 0;
		CacheNextSlide();
		ShowTimeRemained();
		operation = "fadeIn";
		if (!pause) interval2 = setTimeout("SlideIt()",10);
	}
	else if (operation=="fadeOut")
	{
		clearTimeout(interval1);
		for (i=0;i<15;i++) ShowLayer("divTime"+i,"hidden");
		document.getElementById('divText').innerHTML = "&nbsp;";
		counter = 0;
		var sliderLayer = document.getElementById("divSlider");
		sliderLayer.style.filter = "Alpha(Opacity="+alpha+")";
		sliderLayer.style.MozOpacity = alpha/100;
		if (alpha>0) alpha-=10;
		else
		{
			sliderLayer.style.filter = "Alpha(Opacity=0)";
			sliderLayer.style.MozOpacity = 0;
			operation = "changeImage";
		}
		interval2 = setTimeout("SlideIt()",10);
	}
}

function ShowTimeRemained()
{
	if (counter==0) for (i=0;i<15;i++) ShowLayer("divTime"+i,"hidden");
	if (!pause) for (i=0;i<counter;i++) ShowLayer("divTime"+i,"visible");
	if (!pause && (counter<15))
	{
		counter++;
		interval1 = setTimeout("ShowTimeRemained()",(slideWaiting/16));
	}
}



