function applyeffect(){
if (document.all && photoslider.filters){
photoslider.filters.revealTrans.Transition=Math.floor(12)
photoslider.filters.revealTrans.stop()
photoslider.filters.revealTrans.apply()
}
}



function playeffect(){
if (document.all && photoslider.filters)
photoslider.filters.revealTrans.play()
}

function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}


function btn()
{
if (which == 0) document.getElementById('back').style.display='none' 
else document.getElementById('back').style.display='' 
if (which == photos.length-1) document.getElementById('forw').style.display='none' 
else document.getElementById('forw').style.display=''
}

function backward(){
if (which>0){
which--
//applyeffect()
document.images.photoslider.src=photos[which]
document.getElementById('kepnev').firstChild.nodeValue=kepnev[which];
// document.getElementById('forras').firstChild.nodeValue=forras[which];
// document.getElementById('datum').firstChild.nodeValue=datum[which];
btn()
playeffect()
keeptrack()
}
}

function forward(){
if (which<photos.length-1){
which++
//applyeffect()
document.images.photoslider.src=photos[which]
document.getElementById('kepnev').firstChild.nodeValue=kepnev[which];
// document.getElementById('forras').firstChild.nodeValue=forras[which];
// document.getElementById('datum').firstChild.nodeValue=datum[which];
btn()
playeffect()
keeptrack()
}
}

function selected(number, max){
applyeffect()
document.images.photoslider.src=photos[number]
if (which != photos.length)
{
which=number
}
//document.getElementById('categ').firstChild.nodeValue=categoryname[which];
document.getElementById('kepnev').firstChild.nodeValue=kepnev[which];
// document.getElementById('forras').firstChild.nodeValue=forras[which];
// document.getElementById('datum').firstChild.nodeValue=datum[which];
for(i=0;i<max;i++){
	document.getElementById('a' + i).style.borderColor = '#EBE2CE';
}
document.getElementById('a' + which).style.borderColor = '#77160D';
// Ki kellet iktatnom mert az ie keresi a gombokat amikre hivatkozik
//btn()
playeffect()
keeptrack()
}

function transport(name){
var pwidth=bigwidth[which];
var pheight=bigheight[which];

myleft=(screen.width)?(screen.width-pwidth)/2:100;
mytop=(screen.height)?(screen.height-pheight)/2:100;

f_popup = open("","cartridge_popup","width="+pwidth+",height="+pheight+",left="+myleft+", top="+mytop+",status=yes,toolbar=no,menubar=no,resizable=no");
	f_popup.document.open();
	f_popup.document.write("<HTML><HEAD><TITLE>"+categoryname[which]+" - "+kepnev[which]+"</TITLE></HEAD>");
	f_popup.document.write("<script type='text/javascript'>");
	f_popup.document.write("function FitPic() { ");
	f_popup.document.write("var NS = (navigator.appName=='Netscape')?true:false;");
	f_popup.document.write("iWidth = (NS)?window.innerWidth:document.body.clientWidth; ");
	f_popup.document.write("iHeight = (NS)?window.innerHeight:document.body.clientHeight; ");
	f_popup.document.write("iWidth = document.images[0].width - iWidth; ");
	f_popup.document.write("iHeight = document.images[0].height - iHeight; ");
	f_popup.document.write("window.resizeBy(iWidth, iHeight); ");
	f_popup.document.write("self.focus(); } ");
	f_popup.document.write("</script>");
	f_popup.document.write("<BODY style='margin: 0px 0px 0px 0px; padding: 0px;' bgcolor='#000000'  onload='FitPic();'>");
	f_popup.document.write("<a href='javascript:;' onClick='javascript:window.close();'><img src='"+bigphotos[which]+"' title='" + name + "' border='0'></a>");
	f_popup.document.write("</BODY></HTML>");
	f_popup.document.close();
}

// KEP MEGJELENITES
function Display_Image(serverurl, func, param){
	if(!param)param = '';
	$('ws_content_prod').innerHTML = '';
	ajaxRequest = new Ajax.Request(
		serverurl + '/functions/ajaxfunc.php',
		{
			method: 'get',
			parameters: 'funcid=' + func + '&img=' + bigphotos[which] + param,
			onComplete: function(request) 
			{
				// alert(request.responseText);
				MyZoom_Isset = false;
				Display_Cover(request);
				
			}
		}
	)
}

function Display_Cover(request){
	var myDiv = 'ws_content_prod';
	var myLayer = $(myDiv);
	
	var body_dimensions = $('body').getDimensions();  
	Width = body_dimensions.width + 'px';  
	Height = body_dimensions.height + 'px';  
	$('ws_cover').setStyle({width: Width,height: Height,display: 'block'});

	myLayer.innerHTML = request.responseText;
	// position_layer(myDiv, 500);
	position_layer_IsSize(myDiv);
	// position_layer(myDiv);
	// myLayer.style.display = '';	
	new Effect.Appear(myDiv,
			{
				duration:2,
				from:0.0-0.0,
				to:1.0-0.0
			}
		);

	// new Move_Galery_Thumb('motiongallery', 600, 800);
	// alert(request.responseText);
}
// # END - KEP MEGJELENITES

// # KEPET BEFOGLALO DIV MERETEZESE
var myDivMargin = 10;
function position_layer_IsSize(div, kat){
	if(kat)plusCount = CumImgCount[kat];
	else plusCount = 0;
	
  var dim = document.viewport.getDimensions();
  var myLayer = $(div);
  AktTop = document.viewport.getScrollOffsets().top;
  mywidth = bigwidth[plusCount+which];
  myheight = bigheight[plusCount+which];
	myLayer.style.width = (parseInt(mywidth)+myDivMargin*2) + 'px';
	$('move_thumb').setStyle({width: mywidth + 'px'});
	// myheight += (myheight<50 ? plusheight : 0);
  
  newLeft = (dim.width-mywidth)/2;
	if(myheight > dim.height)newtop = AktTop + 10;
  else newtop = AktTop + (dim.height-myheight)/2;
	if(newLeft < 10)newLeft = 10;
	if(newtop < 10)newtop = 10;

  // alert(myLayer.style.left + ' - ' + myLayer.style.top);
  myLayer.style.left = newLeft + "px";
  myLayer.style.top = newtop + "px";
}
// # END - KEPET BEFOGLALO DIV MERETEZESE


// var OldMit1;
var showAktiv = 0;
var ShowHideOk = true;
function Show_Hide_Ok(){
	ShowHideOk = true;
}
var lastDate=0;

// # GALLERY MOZGO
var MoveGallery_scrollspeed = 2;	// sebesseg
var MoveGallery_CDTime = 50;				// idozito

// Ne modositsd
var MoveGallery_left = 0;
var MoveGallery_aktiv = 0;				// Aktiv idozito
var MoveGallery_aktWay = 1;				// Irany
var MoveGallery_aktwidth = 0;			// 

var MoveGallery_moveGallery;	// $(GalleryID)
var MoveGallery_DivWidth;			// div szelessege
var MoveGallery_WidthAll;			// a kiskepek szumma szelessege
// END - Ne modositsd

var MoveGallery_ThumbBorderColor_On = '#77160d';			// 
var MoveGallery_ThumbBorderColor_Off = '#ebe2ce';			// 

function show_hide(mit1, mit2, WidthAll, event, othis) {
		
	$(mit1).style.visibility='hidden';
	$(mit2).style.visibility='visible';
	
	MoveGallery_DivWidth = $(othis).getWidth();
	MoveGallery_WidthAll = WidthAll;
	MoveGallery_moveGallery = $('motiongallery');
	$('motioncontainer').style.width = MoveGallery_DivWidth + 'px';
	
	if(mit2 == "move_thumb"){
		mouseX = Event.pointerX(event);
		if((MoveGallery_DivWidth/2)+parseInt($("ws_content_prod").style.left) > mouseX)
			MoveGallery_aktWay = 0;
		else MoveGallery_aktWay = 1;
	
		Move_Thumb();
		MyZoom();
	}
}
function Move_Thumb(){

	if(MoveGallery_DivWidth < MoveGallery_WidthAll && MoveGallery_aktWay < 2){
		MoveGallery_aktwidth = parseInt(MoveGallery_WidthAll)+MoveGallery_left;
		
	
		// # Mozgás jobb oldali jelenletnel -> balra
		if(MoveGallery_aktWay > 0){
			if(MoveGallery_aktwidth > MoveGallery_DivWidth){
				clearTimeout(MoveGallery_aktiv);
				MoveGallery_moveGallery.style.left = parseInt(MoveGallery_moveGallery.style.left)-MoveGallery_scrollspeed + 'px';
				MoveGallery_left = parseInt(MoveGallery_moveGallery.style.left);
				MoveGallery_aktiv = setTimeout("Move_Thumb()", MoveGallery_CDTime);
				if(MySlider){
					// alert(MoveGallery_aktwidth);
					MyZoom_HandleLeft = MyZoom_HandleRate*(MoveGallery_WidthAll-MoveGallery_aktwidth);
					// MyZoom_HandleLeft += MyZoom_HandleRate*MoveGallery_scrollspeed;
					$('zoom_handle').style.left = MyZoom_HandleLeft + 'px';
					// alert(MyZoom_Rate + ' - ' + MoveGallery_scrollspeed + ' - ' + MyZoom_HandleLeft);
				}

			}	
			else if(MoveGallery_aktiv)clearTimeout(MoveGallery_aktiv);
		}
		// # Mozgás bal oldali jelenletnel -> jobbra
		else{
			if(MoveGallery_aktwidth < MoveGallery_WidthAll){
				clearTimeout(MoveGallery_aktiv);
				MoveGallery_moveGallery.style.left = parseInt(MoveGallery_moveGallery.style.left)+MoveGallery_scrollspeed + 'px';
				MoveGallery_left = parseInt(MoveGallery_moveGallery.style.left);
				MoveGallery_aktiv = setTimeout("Move_Thumb()", MoveGallery_CDTime);
				if(MySlider){
					MyZoom_HandleLeft = MyZoom_HandleRate*(MoveGallery_WidthAll-MoveGallery_aktwidth);
					// MyZoom_HandleLeft -= MyZoom_HandleRate*MoveGallery_scrollspeed;
					$('zoom_handle').style.left = MyZoom_HandleLeft + 'px';
					// alert(MyZoom_Rate + ' - ' + MoveGallery_scrollspeed + ' - ' + MyZoom_HandleLeft);
				}
			}	
			else if(MoveGallery_aktiv)clearTimeout(MoveGallery_aktiv);
		}
	}
}
// # END - GALLERY MOZGO

// # GALERIA KEPCSERELO
var Image_Replace_Cnt;
function Image_Replace2(kat){
	// myImg.innerHTML = ; 
	Image_Replace_Cnt = '<img src="' + bigphotos[CumImgCount[kat]+which] + '" border="0">';
	c = 0;
	while(thumb = $('thumb' + c)){
		thumb.style.borderColor = MoveGallery_ThumbBorderColor_Off;
		thumb.className = 'img_off';
		c++;
	}
	$('thumb' + which).style.borderColor = MoveGallery_ThumbBorderColor_On;
	$('thumb' + which).className = 'img_on';
	new Effect.Opacity('ws_content_prod', { 
		from: 1, 
		to: 0 ,
		afterFinish:function(request){
			MyZoom_Isset = false;
			$('GalleryBig').innerHTML = Image_Replace_Cnt;
			$('GalleryBig').style.width = bigwidth[CumImgCount[kat]+which] + 'px';
			$('GalleryBig').style.height = bigheight[CumImgCount[kat]+which] + 'px';
			$('move_thumb').style.width = bigwidth[CumImgCount[kat]+which] + 'px';
			// alert($(myDiv).style.width + ' - ' + $('GalleryBig').getWidth());
			$('Gallinside').style.width = $('GalleryBig').getWidth() + 'px';
			$('ws_content_prod').style.width = $('GalleryBig').getWidth() + 20 + 'px';
			MoveGallery_DivWidth = parseInt($('Gallinside').style.width);
			// Ha kisebb a jelenlegi kep akkor a mozgo resz kicsuszna pl. jobb szelso helyzetben
			if(MoveGallery_aktwidth < MoveGallery_DivWidth && MoveGallery_WidthAll>MoveGallery_DivWidth){
				MoveGallery_aktwidth = MoveGallery_DivWidth;
				pos = Position.cumulativeOffset('GalleryBig');
				MoveGallery_moveGallery.style.left = pos[0]-(MoveGallery_WidthAll-MoveGallery_aktwidth);
			}
			$('motioncontainer').style.width = MoveGallery_DivWidth + 'px';
			// alert($(myDiv).style.width);
			position_layer_IsSize('ws_content_prod', kat);
			MyZoom();
			if(MySlider){$('zoom_handle').style.left = MyZoom_HandleLeft + 'px';}
			new Effect.Opacity('ws_content_prod', { from: 0, to: 1 });
		}
	});
}
// # END - GALERIA KEPCSERELO

// # GALERIA SCROLLBAR
var MyZoom_Isset = false;
var MyZoom_Left;
var MyZoom_Rate;
var MyZoom_HandleLeft  = 0;
var MyZoom_HandleWidth  = 0;
var MyZoom_HandleRate  = 0;
var MySlider;

function MyZoom() {
	if(!MyZoom_Isset){
		if(MoveGallery_WidthAll > MoveGallery_DivWidth){
			// MyZoom_HandleLeft = (MoveGallery_WidthAll-MoveGallery_aktwidth);
			$('zoom_slider').style.width = MoveGallery_DivWidth + 'px';
			$('zoom_handle').style.width = parseInt(MoveGallery_DivWidth*MoveGallery_DivWidth/MoveGallery_WidthAll) + 'px';
			MyZoom_HandleWidth = $('zoom_handle').getWidth();
			MyZoom_HandleRate = (MoveGallery_DivWidth-MyZoom_HandleWidth)/(MoveGallery_WidthAll-MoveGallery_DivWidth);
			MyZoom_HandleLeft = MyZoom_HandleRate*(MoveGallery_WidthAll-MoveGallery_aktwidth);

			pos = Position.cumulativeOffset('motioncontainer');
			MyZoom_Left = pos[0];
			MyZoom_Rate = ((MoveGallery_WidthAll-MoveGallery_DivWidth)/MoveGallery_DivWidth);
			
			var zoom_slider = $('zoom_slider'),
					// rgb_slider = $('rgb_slider'),
					box = $('motiongallery');

			MySlider = new Control.Slider(zoom_slider.down('.handle'), zoom_slider, {
				range: $R(0, MoveGallery_DivWidth),
				sliderValue: 0,
				onSlide: function(value) {
					box.setStyle({ left: MyZoom_Left-parseInt(value*MyZoom_Rate) + 'px' });
				},
				onChange: function(value) { 
					box.setStyle({ left: MyZoom_Left-parseInt(value*MyZoom_Rate) + 'px' });
				}
			});
		}
		else{
			$('zoom_slider').style.visibility = 'hidden';
		}
		MyZoom_Isset = true;
	}
};
// # END - GALERIA SCROLLBAR


// ************************************************************************
// Nem hasznalt fv-ek
// ************************************************************************

function Image_Replace(serverurl, func, kat, param){
	// alert(kat + ' - cum: ' + CumImgCount[kat] + ' - which: ' + which);
	if(!param)param = '';
	myImg = $('GalleryBig');
	ajaxRequest = new Ajax.Request(
		serverurl + '/functions/ajaxfunc.php',
		{
			method: 'get',
			parameters: 'funcid=' + func + '&img=' + bigphotos[CumImgCount[kat]+which] + '&kat=' + kat + param,
			onComplete: function(request) 
			{
				// myImg.innerHTML = ; 
				Image_Replace_Cnt = request.responseText;
				c = 0;
				while(thumb = $('thumb' + c)){
					thumb.style.borderColor = MoveGallery_ThumbBorderColor_Off;
					c++;
				}
				$('thumb' + which).style.borderColor = MoveGallery_ThumbBorderColor_On;
				new Effect.Opacity('ws_content_prod', { 
					from: 1, 
					to: 0 ,
					afterFinish:function(request){
						MyZoom_Isset = false;
						$('GalleryBig').innerHTML = Image_Replace_Cnt;
						$('GalleryBig').style.width = bigwidth[CumImgCount[kat]+which] + 'px';
						$('GalleryBig').style.height = bigheight[CumImgCount[kat]+which] + 'px';
						// alert($(myDiv).style.width + ' - ' + $('GalleryBig').getWidth());
						$('Gallinside').style.width = $('GalleryBig').getWidth() + 'px';
						$('ws_content_prod').style.width = $('GalleryBig').getWidth() + 20 + 'px';
						MoveGallery_DivWidth = parseInt($('Gallinside').style.width);
						$('motioncontainer').style.width = MoveGallery_DivWidth + 'px';
						// alert($(myDiv).style.width);
						position_layer_IsSize('ws_content_prod', kat);
						new Effect.Opacity('ws_content_prod', { from: 0, to: 1 });
					}
				});
				// alert($('GalleryBig').getWidth());
			}
		}
	)
}


// WidthAll - thumbok szelessege
// DivWidth - galery szelessege
// moveGaleryID - a mozgatott reteg id-je
function Move_Galery_Thumb(moveGaleryID, DivWidth, WidthAll){
	// alert('teszt');
	// alert(navigator.appVersion.include('MSIE'));
	this.leftID = 'move_left';
	this.rightID = 'move_right';
	this.moveGaleryID = moveGaleryID;
	this.moveGalery = $(moveGaleryID);
	this.DivWidth = DivWidth;
	this.WidthAll = WidthAll;
	
	var oThis = this;
	// alert(this.myID  + " - " + this.subMenu + " - " + this.IsSubMenu);
	Event.observe(this.leftID, 'mouseover', function(event) { oThis.Go1(event); });
	Event.observe(this.leftID, 'mouseout', function(event) { oThis.Stop1(event); });
	Event.observe(this.rightID, 'mouseover', function(event) { oThis.Go2(event); });
	Event.observe(this.rightID, 'mouseout', function(event) { oThis.Stop2(event); });
}
Move_Galery_Thumb.prototype = {
	left:	0,
	aktwidth: 0,
	CDTime: 50,
	aktiv: 0,
	scrollspeed: 2,
	aktWay: 1,

	Go1 : function(){
		this.aktWay = -1;
		this.Move();
	},
	
	// right side -> way = left
	Go2 : function(){
		this.aktWay = 1;
		this.Move();
	},
	
	Stop1 : function(){
		if(this.aktiv)clearTimeout(this.aktiv);
	},
	
	Stop2 : function(){
		if(this.aktiv)clearTimeout(this.aktiv);
	},
	
	// way = 1 => jobbra ha -1 akkor balra
	Move : function(){
		// alert(way);
		if(this.DivWidth < this.WidthAll){
			this.aktwidth = parseInt(this.WidthAll)+this.left;
			// alert(this.aktwidth + ' - ' + this.DivWidth);
			if(this.aktWay > 0){
				if(this.aktwidth > this.DivWidth){
					// alert(this.moveGalery.style.left);
					this.moveGalery.style.left = parseInt(this.moveGalery.style.left)-this.scrollspeed + 'px';
					this.left = parseInt(this.moveGalery.style.left);
					this.aktiv = setTimeout(this.Move.bind(this), this.CDTime);
				}	
				else if(this.aktiv)clearTimeout(this.aktiv);
			}
			else{
				if(this.aktwidth < this.WidthAll){
					this.moveGalery.style.left = parseInt(this.moveGalery.style.left)+this.scrollspeed + 'px';
					this.left = parseInt(this.moveGalery.style.left);
					this.aktiv = setTimeout(this.Move.bind(this), this.CDTime);
			// alert('this.DivWidth: ' + this.DivWidth + ' - this.WidthAll: ' + this.WidthAll + ' - this.aktwidth: ' + this.aktwidth + ' - this.left: ' + this.left);
				}					
				else if(this.aktiv)clearTimeout(this.aktiv);
			}
		
		}
	}
}