
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

/// Browser detect

var browserType = navigator.appName

if (browserType == 'Microsoft Internet Explorer'){
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
}else if(browserType == 'Netscape'){
    var ua = navigator.userAgent;
    var re  = new RegExp("Firefox/([0-9]\.[0-9]{1,2})\.[0-9]{1,4}");
    
    if (re.exec(ua) != null){rv = RegExp.$1;}
	browserType = 'Firefox';
}else{
	browserType = 'none';
	rv = 0
}
 
var browserVersion = rv;


//// lightbox
var img;
var lightboxOpen = false
var lightboxTitle
var currentPicture = ''

function showLightbox(imgurl, title){
	currentPicture = imgurl
	lightboxTitle = title;
	if(!lightboxOpen){
		showLoader()
		lightboxOpen = true
		img = document.createElement('img'); 
		img.id = 'lightboxloadimage'; 
		Event.observe(img, 'load', function(e){addToLightbox(e);},false); 
		//$('lightboxpica').appendChild(img); 
		img.src = imgurl; 
		
		$('ajaxmessage_curtain').style.height = $('fulltable').getHeight() + 'px';
		$('ajaxmessage_curtain').style.display = 'block';
	}
}

function showLoader(){
	var scrollOffsets = document.viewport.getScrollOffsets();
	$('mylightbox').style.display = 'block';
	$('lightboxinfo').style.display = 'none';
	$('lightboxcontainer').style.width = '24px';
	$('lightboxcontainer').style.height = '24px';
	$('lightboxtable_centtd').style.width = '24px';
	$('lightboxtable_centtd').style.height = '24px';
	$('mylightbox').style.width = '90px';
	$('mylightbox').style.height = '60px';
	$('mylightbox').style.left = ((document.viewport.getWidth()/2)-62) + 'px';
	$('mylightbox').style.top = ((document.viewport.getHeight()/2) + scrollOffsets[1]) + 'px';
}

function closelightbox(){
	$('lightboxpica').innerHTML = '';
	$('lightbox_leftarrow').style.display = 'none';
	$('lightbox_rightarrow').style.display = 'none';
	$('mylightbox').fade({duration:0.2, afterFinish: function(){lightboxClosed()}})
	lightboxOpen = false
}

function lightboxClosed(){
	var scrollOffsets = document.viewport.getScrollOffsets();
	$('ajaxmessage_curtain').style.display = 'none';
	$('lightbox_leftarrow').style.display = 'none';
	$('lightbox_rightarrow').style.display = 'none';
	$('lightbox_leftarrow').style.top = '0px';
	$('lightbox_rightarrow').style.top = '0px';
	$('mylightbox').style.display = 'none';
	$('lightboxpica').innerHTML = '';
	$('lightboxtext').innerHTML ='';
	$('lightboxcontainer').style.width = '56px';
	$('lightboxcontainer').style.height = '56px';
	$('lightboxtable_centtd').style.width = '56px';
	$('lightboxtable_centtd').style.height = '56px';
	$('mylightbox').style.width = '56px';
	$('mylightbox').style.height = '56px';
	$('mylightbox').style.left = ((document.viewport.getWidth()/2)) + 'px';
	$('mylightbox').style.top = ((document.viewport.getHeight()/2) + scrollOffsets[1]) + 'px';
	

}

function addToLightbox(e){
	
	$('lightboxpica').innerHTML = '';
	$('lightboxpica').appendChild(img);
	$('lightboxtext').innerHTML ='';
	$('lightboxtext').innerHTML = lightboxTitle
	var padding = 60
	var myDuration = 0.3
	var myTransition = Effect.Transitions.sinoidal
	
	Event.stop(e);
	var scrollOffsets = document.viewport.getScrollOffsets();
	
	$('lightbox_leftarrow').style.display = 'none';
	$('lightbox_rightarrow').style.display = 'none';
	$('lightbox_leftarrow').style.top = '0px';
	$('lightbox_rightarrow').style.top = '0px';
	$('lightboxinfo').style.display = 'none';
	$('mylightbox').style.visibility = 'hidden';
	$('mylightbox').style.display = 'block';
	
	
	$('lightboxcontainer').morph('width:'+img.getWidth()+'px; height:'+img.getHeight()+'px;', {duration:myDuration, transition: myTransition})
	$('lightboxtable_centtd').morph('width:'+(img.getWidth())+'px; height:'+((img.getHeight()))+'px;', {duration:myDuration, transition: myTransition})
	$('mylightbox').morph('width:'+(img.getWidth() + padding + 140)+'px; height:'+((img.getHeight() + padding)+120)+'px;', {duration:myDuration, transition: myTransition})
	$('mylightbox').style.left = ((document.viewport.getWidth()/2)-62) + 'px';
	$('mylightbox').style.top = ((document.viewport.getHeight()/2) + scrollOffsets[1]) + 'px';
	
	new Effect.Move('mylightbox', { x: ((document.viewport.getWidth()/2)-((img.getWidth() + padding)/2)-62), y: (((document.viewport.getHeight()/2)-((img.getHeight() + padding)/2)) + scrollOffsets[1]), mode: 'absolute', transition: myTransition, duration:myDuration, afterFinish: function(){fadePictureIn()}});
	
	
	
	$('lightboxcontainer').style.display = 'none';
	$('mylightbox').style.visibility = 'visible';
	lightboxTitle = ''
}

function fadePictureIn(){
	var picpicFiles = new Array();
	picpicArray = document.getElementsByClassName('picpic');
	
	for(var n=0; n<picpicArray.length; n++){
		var cumo = picpicArray[n].innerHTML;
		var daraboltString = cumo.split("'");
		picpicFiles[n] = daraboltString[1];	
	}
	
	thisid = picpicFiles.indexOf(currentPicture)
	//alert(thisid)
	
	$('lightboxcontainer').appear({duration: 0.3, afterFinish: function(){showLightInfo()}})
	
	$('lightbox_leftarrow').style.top = (($('mylightbox').getHeight()/2) - 180)+'px';
	if(thisid > 0){$('lightbox_leftarrow').style.display = 'block';}

	$('lightbox_rightarrow').style.top = (($('mylightbox').getHeight()/2) - 180)+'px';
	if(thisid < (picpicArray.length-1)){$('lightbox_rightarrow').style.display = 'block';}

	
}

function showLightInfo(){
	Effect.SlideDown('lightboxinfo', { duration: 0.2 });
}

function lightboxNextpic(){
	picpicArray:Array
	var picpicFiles = new Array();
	var picpicTitles = new Array();
	picpicArray = document.getElementsByClassName('picpic');
	
	for(var n=0; n<picpicArray.length; n++){
		var cumo = picpicArray[n].innerHTML;
		var daraboltString = cumo.split("'");
		picpicFiles[n] = daraboltString[1];
		picpicTitles[n] = daraboltString[3];	
	}
	
	thisid = picpicFiles.indexOf(currentPicture)
	changeLightbox(picpicFiles[(thisid+1)], picpicTitles[(thisid+1)]);
}

function lightboxPrevpic(){
	picpicArray:Array
	var picpicFiles = new Array();
	var picpicTitles = new Array();
	picpicArray = document.getElementsByClassName('picpic');
	
	for(var n=0; n<picpicArray.length; n++){
		var cumo = picpicArray[n].innerHTML;
		var daraboltString = cumo.split("'");
		picpicFiles[n] = daraboltString[1];
		picpicTitles[n] = daraboltString[3];	
	}
	
	thisid = picpicFiles.indexOf(currentPicture)
	changeLightbox(picpicFiles[(thisid-1)], picpicTitles[(thisid-1)]);
}

function changeLightbox(imgurl, title){
	$('lightboxloadimage').fade({duration:0.07})
	$('lightbox_leftarrow').style.display = 'none';
	$('lightbox_rightarrow').style.display = 'none';
	$('lightboxinfo').fade({duration:0.07, afterFinish: function(){changeLightbox_smaller(imgurl, title)}})
	//closelightbox()
	//var setfunc = 'showLightbox(\''+imgurl+'\', \''+title+'\')';
	//setTimeout(setfunc,500);
}

function changeLightbox_smaller(imgurl, title){
	var padding = 60
	var myDuration = 0.3
	var mysize = 200
	var myTransition = Effect.Transitions.sinoidal
	var scrollOffsets = document.viewport.getScrollOffsets();
	
	
	$('lightboxcontainer').morph('width:'+mysize+'px; height:'+mysize+'px;', {duration:myDuration, transition: myTransition})
	$('lightboxtable_centtd').morph('width:'+(mysize)+'px; height:'+(mysize)+'px;', {duration:myDuration, transition: myTransition})
	$('mylightbox').morph('width:'+(mysize + padding + 140)+'px; height:'+((mysize + padding)+120)+'px;', {duration:myDuration, transition: myTransition})
	new Effect.Move('mylightbox', { x: ((document.viewport.getWidth()/2)-((mysize + padding)/2)-62), y: (((document.viewport.getHeight()/2)-((mysize + padding)/2)) + scrollOffsets[1]), mode: 'absolute', transition: myTransition, duration:myDuration, afterFinish: function(){changeLightbox_newload(imgurl, title)}});

}

function changeLightbox_newload(imgurl, title){

	$('lightboxpica').innerHTML = '<img src="../images/ajaxloader.gif" alt="load" style="margin-top:88px; margin-left:88px;"/>';
	currentPicture = imgurl
	lightboxTitle = title;
	lightboxOpen = false
	if(!lightboxOpen){
		//showLoader()
		lightboxOpen = true
		img = document.createElement('img'); 
		img.id = 'lightboxloadimage'; 
		Event.observe(img, 'load', function(e){changeLightbox_ToLightbox(e);},false); 
		//$('lightboxpica').appendChild(img); 
		img.src = imgurl; 
	}
}

function changeLightbox_ToLightbox(e){
	
	$('lightboxpica').innerHTML = '';
	$('lightboxpica').appendChild(img);
	$('lightboxtext').innerHTML ='';
	$('lightboxtext').innerHTML = lightboxTitle
	var padding = 60
	var myDuration = 0.5
	var myTransition = Effect.Transitions.sinoidal
	
	Event.stop(e);
	var scrollOffsets = document.viewport.getScrollOffsets();
	
	$('lightbox_leftarrow').style.display = 'none';
	$('lightbox_rightarrow').style.display = 'none';
	$('lightbox_leftarrow').style.top = '0px';
	$('lightbox_rightarrow').style.top = '0px';
	$('lightboxinfo').style.display = 'none';
	//$('mylightbox').style.visibility = 'hidden';
	//$('mylightbox').style.display = 'block';
	
	
	$('lightboxcontainer').morph('width:'+img.getWidth()+'px; height:'+img.getHeight()+'px;', {duration:myDuration, transition: myTransition})
	$('lightboxtable_centtd').morph('width:'+(img.getWidth())+'px; height:'+((img.getHeight()))+'px;', {duration:myDuration, transition: myTransition})
	$('mylightbox').morph('width:'+(img.getWidth() + padding + 140)+'px; height:'+((img.getHeight() + padding)+120)+'px;', {duration:myDuration, transition: myTransition})
	//$('mylightbox').style.left = ((document.viewport.getWidth()/2)) + 'px';
	//$('mylightbox').style.top = ((document.viewport.getHeight()/2) + scrollOffsets[1]) + 'px';
	
	new Effect.Move('mylightbox', { x: ((document.viewport.getWidth()/2)-((img.getWidth() + padding)/2)-62), y: (((document.viewport.getHeight()/2)-((img.getHeight() + padding)/2)) + scrollOffsets[1]), mode: 'absolute', transition: myTransition, duration:myDuration, afterFinish: function(){fadePictureIn()}});
	
	
	
	$('lightboxcontainer').style.display = 'none';
	//$('mylightbox').style.visibility = 'visible';
	lightboxTitle = ''
}


function alertposition(obj){
	$(obj).style.top = ((document.viewport.getHeight()/2) - ($(obj).offsetHeight/2)) + 'px';
	$(obj).style.left = ((document.viewport.getWidth()/2) - ($(obj).offsetWidth/2)) + 'px';
}

function showAlert(cim, szoveg, gomb){
	//alert('aaaa')
	if (browserType == 'Microsoft Internet Explorer' && browserVersion < 7){
		var selects = $('content').getElementsByTagName('select')
		for(var n=0; n<selects.length; n++){
			selects[n].style.display = 'none'
		}
	}
	//document.all.dropDownMenu.style.display = "none"
	
	//$('myselect').style.zIndex = 100
	//alert($('myselect').style.zIndex)
	$('ajaxmessage').style.display = 'block'
	$('ajaxalerttext').innerHTML = '<h3>'+cim+'</h3>'+szoveg;
	$('alertokbutt').innerHTML = gomb
	
	
	alertposition('ajaxmessage');
}

function closemessage(){
	if (browserType == 'Microsoft Internet Explorer' && browserVersion < 7){
		var selects = $('content').getElementsByTagName('select')
		for(var n=0; n<selects.length; n++){
			selects[n].style.display = 'block'
		}
	}
	
	$('ajaxmessage').style.display = 'none';
	try{extclosemessage()}catch(err){}
}

