var opacity;
var obj_op;
var change_code;
var step = 10;
var speed = 30;
var slideShowTime = 2000;

function changeTo( id, gallery ) {
    x = document.getElementById(id);

    opacity = 100;
    obj_op = x;
	obj_op.style.opacity = opacity/100;
	obj_op.style.filter = 'alpha(opacity=' + opacity + ')';

	try{
	      clearInterval( eval('timer_'+gallery+'_hide') );
	}catch(e){	}
	try{
	      clearInterval( eval('timer_'+gallery+'_show') );
	}catch(e){	}

    eval( 'timer_'+gallery+'_hide = setInterval("hide('+gallery+');", speed)' );

}

function hide( gallery ) {
    opacity -= step;
	obj_op.style.opacity = opacity/100;
	obj_op.style.filter = 'alpha(opacity=' + opacity + ')';
    if ( opacity <= 0 ) {
        clearInterval( eval('timer_'+gallery+'_hide') );
        obj_op.innerHTML = change_code;
		eval( 'timer_'+gallery+'_show = setInterval("show('+gallery+');", speed)' );
    }
}

function show( gallery ) {
    opacity += step;
	obj_op.style.opacity = opacity/100;
	obj_op.style.filter = 'alpha(opacity=' + opacity + ')';
    if ( opacity >= 100 ) {
        clearInterval( eval('timer_'+gallery+'_show') );
		obj_op.style.opacity = 1;
		obj_op.style.filter = 'alpha(opacity=100)';
    }
}

function showGalleryPic( act_pic, gallery, noFade ) {

	document.getElementById( 'gallery_'+gallery+'_thumb_pic_'+eval('gallery_'+gallery+'_act_pic') ).className = '';

	img_code = '<img src="'+eval('gallery_'+gallery+'_images[act_pic]')+'" id="gallery_'+gallery+'_full_pics" name="gallery_'+gallery+'_full_pics"'+eval('gallery_'+gallery+'_images_params[act_pic]')+' />';
	if ( eval('gallery_'+gallery+'_link_full_image') )
		img_code = '<a href="'+eval('gallery_'+gallery+'_images[act_pic]')+'" class="gallery_full_pics_link" target="_blank">'+img_code+'</a>';

	change_code = img_code;

// Kép lecserélése
	if ( noFade )
		document.getElementById('gallery_'+gallery+'_full_pic').innerHTML = img_code;
	else
	    changeTo( 'gallery_'+gallery+'_full_pic', gallery );

	eval('gallery_'+gallery+'_act_pic  = act_pic');

	document.getElementById( 'gallery_'+gallery+'_thumb_pic_'+act_pic ).className = 'gallery_active';

}

function gallery_prew( gallery ) {
	act_pic = eval('gallery_'+gallery+'_act_pic');

	if ( eval('gallery_'+gallery+'_act_pic') > 0 ) act_pic--;
	else
	if ( eval('gallery_'+gallery+'_circle_view') ) act_pic = eval('gallery_'+gallery+'_pic_count');


	showGalleryPic( act_pic, gallery );

}

function gallery_next( gallery ) {
	act_pic = eval('gallery_'+gallery+'_act_pic');

	if ( eval('gallery_'+gallery+'_act_pic') < eval('gallery_'+gallery+'_pic_count') ) act_pic++;
		else
		if ( eval('gallery_'+gallery+'_circle_view') )
			act_pic = 0;
		else
		try{
			if ( eval( 'gallery_'+gallery+'_slideshow_run' ) )
				changeSlideShow( gallery );
		}catch(e){}

	showGalleryPic( act_pic, gallery );

}

function changeSlideShow( gallery ) {
	var button = document.getElementById('slidShowButton');

	if ( eval( 'gallery_'+gallery+'_slideshow_run' ) ) {
		try{
		      clearInterval( eval('timer_'+gallery+'_slideshow') );
		}catch(e){}
		eval( 'gallery_'+gallery+'_slideshow_run = 0' )
		button.src = 'sablons/cms/pics/start.jpg';
	} else {
		eval( 'timer_'+gallery+'_slideshow = setInterval("gallery_next('+gallery+');", slideShowTime)' );
		eval( 'gallery_'+gallery+'_slideshow_run = 1' )
		button.src = 'sablons/cms/pics/stop.jpg';
	}
}

/* -------------------------- 2.0 -------------------------*/

function BlurOff( obj ) {
	var opacity_ff = obj.style.opacity
	var opacity_ie = obj.style.filter

	obj.style.opacity = 1;
	obj.style.filter = 'alpha(opacity=100)';
}

function BlurOn( obj ) {

	try {
		obj.style.opacity = opacity_ff;
		obj.style.filter = opacity_ie;
	} catch(e) {
		obj.style.opacity = 0.8;
		obj.style.filter = 'alpha(opacity=80)';
	}
}

function showFullPic( pic_id ) {
	try {
		document.getElementById('GalleryFullPic').style.display = 'block';
	} catch(e) {
		body_obj = document.getElementById('body');
		body_obj.innerHTML = '<div id="GalleryFullPic"><div id="GalleryLayer" onClick="hideFullPic()"></div><div id="GalleryPicLayer" onClick="hideFullPic()"></div></div>'+body_obj.innerHTML;
	}

	document.getElementById('GalleryPicLayer').innerHTML = '<img src="'+gallery_images[pic_id]+'" id="GalleryTheFullPic"/>';

	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
			_offsetY = window.pageYOffset;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.documentElement.clientHeight;
//			winH = document.body.offsetHeight;
			_offsetY = document.documentElement.scrollTop;
		}
	}

	set_height = Math.max( document.getElementById('main').offsetHeight, winH );
	document.getElementById('GalleryFullPic').style.height = set_height+'px';

	layer = document.getElementById('GalleryPicLayer');
	image = document.getElementById('GalleryTheFullPic');
	layer.style.left = ( (winW/2) - Math.max( (image.width/2), 100 ) )+'px';
	layer.style.top = ( (winH/2) - Math.max( (image.height/2), 100 ) + _offsetY )+'px';
//	layer.style.top = '100px';

}

function hideFullPic() {
	document.getElementById('GalleryFullPic').style.display = 'none';
}