
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

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 });
}


///// left column box changer

function changeboxcontent(fromnum, tonum){
	var from_data = $('lefttab_'+fromnum).innerHTML
	var from_title_data = $('leftmenuitem_'+fromnum).innerHTML
	var to_data = $('leftactive_'+tonum).innerHTML
	var tochild = $('leftactive_'+tonum).childElements()
	var to_title_id = tochild[0].id
	var sp = to_title_id.split("_")
	var to_title_idnum = sp[1]
	var to_title_data = tochild[0].childElements()
	to_title_data = to_title_data[0].innerHTML
	
	Effect.Fade('lefttab_'+fromnum, { duration: 0.4, afterFinish: function(){
		new Insertion.Bottom($('leftcont_list_'+tonum), '<li id="lefttab_'+to_title_idnum+'" style="display:none;"><a href="javascript:void(0)" onclick="changeboxcontent('+to_title_idnum+', '+tonum+'); return false;" id="leftmenuitem_'+to_title_idnum+'">'+to_title_data+'</a></li>')
		Effect.Appear('lefttab_'+to_title_idnum, { duration: 0.4 });
		$('lefttab_'+fromnum).remove();	
	}});
	
	
	Effect.Fade('leftactive_'+tonum, { duration: 0.4, afterFinish: function(){
		$('leftactive_'+tonum).innerHTML = '<div id="lefttitle_'+fromnum+'"><a href="javascript:void(0)" onclick="openboxcontent('+tonum+', '+fromnum+'); return false;">'+from_title_data+'</a></div>';
		Effect.Appear('leftactive_'+tonum, { duration: 0.4 });
	}});
	
	
	Effect.Fade('leftboxcontent_'+to_title_idnum, { duration: 0.4, afterFinish: function(){
		$('leftboxcontent_div_'+tonum).morph('height:'+$('leftboxcontent_'+fromnum).getHeight()+'px;', { duration: 0.2, afterFinish: function(){
			Effect.Appear('leftboxcontent_'+fromnum, { duration: 0.3 });
		}});
	}});
	

}

function openboxcontent(container_id, id){
	if($('leftboxcontent_'+id).style.display == 'none'){
		$('leftboxcontent_div_'+container_id).morph('height:'+$('leftboxcontent_'+id).getHeight()+'px;', { duration: 0.2, afterFinish: function(){
			Effect.Appear('leftboxcontent_'+id, { duration: 0.3 });
		}});
	}else{
		Effect.Fade('leftboxcontent_'+id, { duration: 0.3, afterFinish: function(){
			$('leftboxcontent_div_'+container_id).morph('height:0px;', { duration: 0.2});
		}});
	}
}

function leftboxpager(container_id, count){
	var actid = $('leftactive_'+container_id).childElements()
	actid = actid[0].id.split('_'+container_id+'')
	actid = parseInt(actid[1])
	
	var counter
	if(actid == count){counter = 1;}else{counter = actid+1;}
	
	changeboxcontent(container_id+''+counter, container_id);
}

// open bongesz

var lastbongopened = 0
var opennow = 0
var opsto

var currentSublist = ''
var subTime;


function openbong(id){
	opennow = id
	opsto = setTimeout('openbongnow()', 300)
}

function openbongnow(){
	if($('hideshow_'+opennow).style.display == 'none'){
		Effect.BlindDown('hideshow_'+opennow, { duration: 0.3 });
	}
}

function openbongexit(){
	clearTimeout(opsto)
	
}

function addCurrentSublist(name){
	currentSublist = name
	showSublist(name)
}

var menuOvetTimeOut
var activeSublist

function showSublist(item){
	menuOvetTimeOut	= setTimeout("drawSublist('"+item+"')",500);
}

function drawSublist(item){
	
	var subArray = new Array();
	subArray[0] = 'tn_profilom_sublist'
	subArray[1] = 'tn_uzenetek_sublist'
	subArray[2] = 'tn_ismeroseim_sublist'
	
	for(var n=0; n<subArray.length; n++){
		if(subArray[n] == item){
			$(subArray[n]).style.display = 'inline'

			try{
			if(navigator.appName == 'Microsoft Internet Explorer' && browserVersion == 6 ){}else{
				$(subArray[n].replace('_sublist', '')).style.backgroundColor = '#E9F2F9';
			}
			}catch(err){}
		}else{
			$(subArray[n]).style.display = 'none'
			try{
				if(navigator.appName == 'Microsoft Internet Explorer' && browserVersion == 6 ){}else{
				$(subArray[n].replace('_sublist', '')).style.backgroundColor = '#D3E5F3';
				}
			}catch(err){}
		}
	}
	
	stopTout()
}


function hideTout(){
	//alert(currentSublist)
	//alert('aaaaa')
	try{clearTimeout(menuOvetTimeOut);}catch(err){}
	stopTout()
	subTime=setTimeout("showSublist('"+currentSublist+"')",600);
}

function stopTout(parent_item){
	try{
	clearTimeout(subTime);
	}catch(err){}
	
	try{
		if(navigator.appName == 'Microsoft Internet Explorer' && browserVersion == 6 ){}else{
			$(parent_item).style.backgroundColor = '#E9F2F9';
		}
	}catch(err){}
}


var lastOpenSlide
var slideTimer

function mySlider(id){
	slideTimer = setTimeout("mySliderOpen('"+id+"')",300)
}

function mySliderOpen(id){
	//if($(id).style.display == 'none'){
	if(lastOpenSlide !== id){
		clearTimeout(slideTimer);
		try{Effect.BlindUp(lastOpenSlide, { duration: 0.3 });}catch(err){}
		Effect.BlindDown(id, { duration: 0.5 });	
		lastOpenSlide = id
	}
}

function mySliderStop(){
	clearTimeout(slideTimer);
}



//// MESSAGES


function showuserpic(idnum, imgurl){
	document.onmousemove = moveuserpic;
	$('msg_upic').innerHTML = '<img src="'+imgurl+'" alt=""/>'
	
}

function hideuserpic(idnum){
	
	$('msg_upic').style.display = 'none'
	document.onmousemove = null;
	$('msg_upic').innerHTML = ''
}



function moveuserpic(e) {
	if (browserType == 'Microsoft Internet Explorer'){
		x = event.clientX;
  		y = event.clientY;
	}else{
		x = e.pageX
  		y = e.pageY
	}
  	
	$('msg_upic').style.left = parseInt(x) +15+'px';
	$('msg_upic').style.top = parseInt(y) +8+'px';
	
	$('msg_upic').style.display = 'block'
}

function addmsguser(name, id){
	$('addeduserids').value = $('addeduserids').value + ''+id+';';
	$('msg_add_userlist_'+id).style.display = 'none'
	new Insertion.Bottom('recepientsList', '<span id="addeduser_'+id+'" class="addeduserspan">'+name+' <a href="javascript:void(0)" onclick="removemsguser('+id+')" class="deletelink">X</a></span>')
}

function removemsguser(id){
	$('addeduser_'+id).remove();	
	$('msg_add_userlist_'+id).style.display = 'block'
	
	var newValue = ''+$('addeduserids').value+''
	$('addeduserids').value = newValue.replace(';'+id+';', ';');
}

//// 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){
	
	for( var a = 2; a < arguments.length; a++ ) {
		if(arguments[a] !== undefined){
			new Insertion.After('alert_butt_container', '<td align="center" id="alert_funcbutt_'+a+'"><div id="alert_butt_container2"><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>')
		}
	}
	
	$('ajaxmessage_curtain').style.height = $('fullsiteContainer').getHeight() + 'px';
	$('ajaxmessage_curtain').style.display = 'block';
	$('alerttitle').innerHTML=cim;
	$('alerttext').innerHTML=szoveg;
	$('ajaxmessage').style.display = 'block'
	
	
	alertposition('ajaxmessage');

}


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';
}

function funcname(){
	alert('aaaaaaa')
}

/* eredklodesi */

function showErdeklodesiKat(id, pos){
	for( var a = 0; a < 20; a++ ) {
		try{
			$('erdeklodesi_check_'+a).style.display = 'none'	
			$('fokategoria_'+a).style.background = 'none'
		}catch(err){}
	}
	
	$('erdekarrow').style.top = 5 + (pos * 26) + 'px'
	$('erdeklodesi_check_'+id).style.display = 'block'	
	$('fokategoria_'+id).style.background = '#FFFFFF'
}

function selectErdeklodesi(id){
	var inputs = $('erdeklodesi_check_'+id).getElementsBySelector('input')

	for(var i=0; i<inputs.length; i++){
			inputs[i].checked = true;
			inputs[i].checked = 'checked';
	}
	
	new Ajax.Request('/profilom/erdeklodesi_korok', {
  		method: 'post',
  		parameters: { katid: id }
	});

	
}

function selectErdeklodesiLine(id, element){
	var added = false
	
	if(element.checked){added = true}
	
	new Ajax.Request('/profilom/erdeklodesi_korok', {
  		method: 'post',
  		parameters: { erdid: id, add: added}
	});
}


function topcloser(){
	
	var onoff = false
	
	if($('mytopdatas').style.display == 'none'){
		onoff = true
	}
	
	Effect.toggle('mytopdatas', 'blind', { duration: 1.0 });
	
	new Ajax.Request('/ajaxevent.php?type=topclose', {
		method: 'post',
		parameters: { closed: onoff}
	});
}

function loadOembed(){
	var oPath = '/curl.php';
	var oUrl = escape($('youtubeurl').value)
	
	new Ajax.Request(oPath, {
		method: 'get',
		parameters: { url: oUrl},
		onComplete: function(request) {
			
			if(request.responseText !== '404 Not Found'){
				readOembed(request.responseXML);
			}else{
				if($('youtubecontent').style.overflow == 'visible' && $('youtubecontent').style.display !== 'none'){
					Effect.SlideUp('youtubecontent', { duration: 0.2 });
				}
				
				$('youtube_title').innerHTML = '';
				$('youtube_thumb').innerHTML = '';
				
				$('embed').value = '';
				$('original_title').value = '';
				$('thumbnail_image').value = '';
			}
			
		}
	});
}

function readOembed(xmldata){
	xmlDoc = xmldata;
	$('youtube_title').innerHTML = '<b>' + xmlDoc.getElementsByTagName('title')[0].childNodes[0].nodeValue + '</b>';
	$('youtube_thumb').innerHTML = '<img src="' + xmlDoc.getElementsByTagName('thumbnail_url')[0].childNodes[0].nodeValue + '" width="120" alt=""/>';
	
	$('embed').value = xmlDoc.getElementsByTagName('html')[0].childNodes[0].nodeValue;
	$('original_title').value = xmlDoc.getElementsByTagName('title')[0].childNodes[0].nodeValue;
	$('thumbnail_image').value = xmlDoc.getElementsByTagName('thumbnail_url')[0].childNodes[0].nodeValue;
	
	//alert($('youtubecontent').style.display)
	
	if($('youtubecontent').style.display == 'none'){
		//alert('aaa')
		Effect.SlideDown('youtubecontent', { duration: 0.7, afterFinish: function(){$('youtubecontent').style.height = '106px';}});
	}

}


/// home pager
var currentHomeAuto = true
var currentHomePage = 1
var maxHomePage = 5
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
}

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);
	
}

