/*
	AddThis konfiguráció
*/
var addthis_config = {
    data_track_clickback: true
}

/*
	Külső link figyelése  (XHTML Strict esetében a target="_blank" nem valid, helyette rel="external" és az
	  alábbi kód használandó
*/
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

/*
DIV elrejtése/megjelenítése ID alapján
*/
function divHideUnhide(d) {
	if(d.length < 1) { return; }
	if(document.getElementById(d).style.display == "none") { 
		document.getElementById(d).style.display = "block"; 
	} else { 
		document.getElementById(d).style.display = "none"; 
	}
}

/* ThickBox valid javítás 
function fixHeight(scrollHeight, offsetHeight){
	return (scrollHeight > offsetHeight ? scrollHeight : offsetHeight + ‘px’);
}

function fixMarginTop(offsetHeight,documentElement,scrollTop){
	return (0 - parseInt(offsetHeight / 2) + (TBWindowMargin = documentElement && documentElement.scrollTop || scrollTop) + ‘px’);
} 
*/

/*
Albumkiválasztás
*/
function setvalueback(myID, mySrc, myValue) {
	f = document.getElementById( myID );
	if(f){
		f.value = myValue;
		tb_remove();
	}else{
		alert(myID + ' nem található!\n(setvalueback:' +  myValue + ', ' + mySrc + ')');
	}
	f = document.getElementById( myID +"_selector");
	if(f){
		f.src = mySrc;
		tb_remove();
	}else{
		alert(myID + ' nem található!\n(setvalueback:' +  myValue + ', ' + mySrc + ')');
	}
}

/*
Memo mezők szöveghosszának korlátozása
*/
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function tagtoinput(inputid, tag){
	if (!document.getElementById(inputid)) return;
	var xs = document.getElementById(inputid).value.trim();
	xs=xs.replace(', ', ',');
	var xa = xs.split(',');
	al=xa.length;
	for(i=0;i<xa.length;i++){
		if(xa[i]==tag) xa.splice(i, 1);
	}
	if(al==xa.length) xa.push(tag);
	xa.sort();
	xs = xa.toString();
	if(xs[0]==',')xs=xs.substr(1,xs.length-1);
	document.getElementById(inputid).value = xs;
	return;
}

function load(url,place,class) {
	document.getElementById(place).innerHTML = "<div class=\"class\">Betöltés...<br><img src=\"img/preloader.gif\" alt=\"Betöltés\"/></div>";
	var req = null;
	if (window.XMLHttpRequest)
		req = new XMLHttpRequest()
	else
		if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");

	req.onreadystatechange = function() {
	if (req.readyState == 4)
		if (req.status == 200)
			document.getElementById(place).innerHTML = req.responseText;
		else
			document.getElementById(place).innerHTML = "AJAX error.";
	}
	req.open("GET", url, true);
	req.send(null);
}

/*Fejléc autofade*/

function rotateHeader() {
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
}

function rotate() {	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);
	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
};
