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

/// 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

function showLightbox(imgurl, title){
	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; 
	}
}

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)) + 'px';
	$('mylightbox').style.top = ((document.viewport.getHeight()/2) + scrollOffsets[1]) + 'px';
}

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

function lightboxClosed(){
	var scrollOffsets = document.viewport.getScrollOffsets();
	$('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 = 56
	var myDuration = 0.3
	var myTransition = Effect.Transitions.sinoidal
	
	Event.stop(e);
	var scrollOffsets = document.viewport.getScrollOffsets();
	
	$('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)+'px; height:'+((img.getHeight() + padding))+'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)), 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(){
	$('lightboxcontainer').appear({duration: 0.3, afterFinish: function(){showLightInfo()}})
}

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




//// alert

function alertposition(obj, myHeight){
	var myViewWidth = document.viewport.getWidth();
	var scrollOffsets = document.viewport.getScrollOffsets();
	if(myHeight > 0){
		$(obj).style.top = ((document.viewport.getHeight()/2) - (myHeight/2))+ scrollOffsets[1] + 'px';
	}else{
		$(obj).style.top = ((document.viewport.getHeight()/2) - ($(obj).offsetHeight/2))+ scrollOffsets[1] + 'px';
	}
	
	$(obj).style.left = ((myViewWidth/2) - ($(obj).offsetWidth/2)) + 'px';
}


function showAlertExtended(cim, szoveg){
	
	var posVertiExt = 0
	
	for( var a = 2; a < arguments.length; a++ ) {
		if(arguments[a] !== undefined){
			if(arguments[a].title !== undefined && arguments[a].title !== 'positionChange'){
				new Insertion.After('alert_butt_container', '<td align="center" id="alert_funcbutt_'+a+'"><div class="alert_butt_align"><a href="javascript:void(0)" onclick="'+arguments[a].func+'(); return false;" style="cursor:pointer;"><span class="alertbuttleft"><span class="alertbuttright">'+arguments[a].title+'</span></span></a></div></td>')
			}else{
				if(arguments[a].title == 'positionChange'){
					posVertiExt = arguments[a].newpos
				}
				
				
			}
			try{var callfunction = arguments[a].extra; callfunction();}catch(err){}
		}
	}
	
	$('ajaxmessage_curtain').style.height = $('siteFullContainer').getHeight() + 'px';
	$('ajaxmessage_curtain').style.display = 'block';
	$('alerttitle').innerHTML=cim;
	if(szoveg.indexOf('#') == 0){
		var insertId = szoveg.replace('#', '')
		$('alerttext').innerHTML=$(insertId).innerHTML;
	}else{
		$('alerttext').innerHTML=szoveg;
	}
	
	$('ajaxmessage').style.display = 'block'
	
	
	alertposition('ajaxmessage', posVertiExt);

}


function closealert(){
	for( var a = 2; a < 10; a++ ) {
		try{
			$('alert_funcbutt_'+a).remove();
		}catch(err){}
	}
	
	$('ajaxmessage_curtain').style.display = 'none';
	$('ajaxmessage').style.display = 'none';
	
	try{$('loginToImg').remove();}catch(err){}
}



/// home pager
var currentHomeAuto = true
var currentHomePage = 1
var maxHomePage = 6
var homeTimer

function homepager(id){
	try{clearTimeout(homeTimer)}catch(err){}
	$('homeaji_' + currentHomePage).fade({duration:0.8})
	$('homeajibutt_' + currentHomePage).style.fontWeight = 'normal'
	$('homeaji_' + id).appear({duration:0.8})
	$('homeajibutt_' + id).style.fontWeight = 'bold'
	currentHomePage = id
	
	$('picture_link').href = $('link_'+id);
	
}

function homepager_next(){
	var myid 
	if(currentHomePage < maxHomePage){
		myid = currentHomePage+1
	}else{
		myid = 1
	}
	homepager(myid)
}

function homepager_prev(){
	var myid 
	if(currentHomePage > 1){
		myid = currentHomePage-1
	}else{
		myid = maxHomePage
	}
	homepager(myid)
}

function homepager_run(){
	clearTimeout(homeTimer)
	homepager_next()
	homeTimer = setTimeout("homepager_run()",5000);
}

function homepager_auto(){
	homeTimer = setTimeout("homepager_run()",5000);
	
}

function publishPicasso()
{
	
	new Ajax.Request('/megosztas/3/'+picasso_image_name, 
	{
  		method: 'get'
	});

	document.location.href="/alkalmazasok/picasso/aktualis_rajzok";

}


function publishMandala()
{
	
	new Ajax.Request('/megosztas/3/'+mandala_image_name, 
	{
  		method: 'get'
	});

	document.location.href="/";

}

function publishBlog()
{
	document.location.href="/blogok/publicate_entry/"+request_blog_id;
}

function textareaCounter(num, areaid, charid, maxid){
	if($(areaid).value.length < (num+1)){
		$(charid).innerHTML = $(areaid).value.length
	}else{
		$(areaid).value = $(areaid).value.substring(0, num);
	}
}


