/*

help:

Attribute  	The event occurs when...  	FF  	N  	IE
onabort 	Loading of an image is interrupted 	1 	3 	4
onblur 	An element loses focus 	1 	2 	3
onchange 	The user changes the content of a field 	1 	2 	3
onclick 	Mouse clicks an object 	1 	2 	3
ondblclick 	Mouse double-clicks an object 	1 	4 	4
onerror 	An error occurs when loading a document or an image 	1 	3 	4
onfocus 	An element gets focus 	1 	2 	3
onkeydown 	A keyboard key is pressed 	1 	4 	3
onkeypress 	A keyboard key is pressed or held down 	1 	4 	3
onkeyup 	A keyboard key is released 	1 	4 	3
onload 	A page or an image is finished loading 	1 	2 	3
onmousedown 	A mouse button is pressed 	1 	4 	4
onmousemove 	The mouse is moved 	1 	6 	3
onmouseout 	The mouse is moved off an element 	1 	4 	4
onmouseover 	The mouse is moved over an element 	1 	2 	3
onmouseup 	A mouse button is released 	1 	4 	4
onreset 	The reset button is clicked 	1 	3 	4
onresize 	A window or frame is resized 	1 	4 	4
onselect 	Text is selected 	1 	2 	3
onsubmit 	The submit button is clicked 	1 	2 	3
onunload 	The user exits the page 	1 	2 	3

*/

var activeThumb = null;


function thumbOver(thumb) {
if ( thumb.className == 'thumb_sel' ) return false;
thumb.className = 'thumb_over';
}

function thumbOut(thumb) {
	if ( thumb.className == 'thumb_sel' ) return false;
	thumb.className = 'thumb_out';    
}

function thumbClick(thumb) {
	thumb.className = 'thumb_sel';
if ( activeThumb != null ) {
  activeThumb.className = 'thumb_out';
}
activeThumb = thumb;
thumb.className = 'thumb_sel';
setImage( thumb.id.substr(6) );
}

function setImage( aid ) {
	img = loadedImages[aid];
if ( typeof( img ) != 'object' ) return false;
	document.getElementById( 'viewerTitle' ).innerHTML = img.cim;
	document.getElementById( 'viewerImg' ).src = img.kep;
	document.getElementById( 'viewerDesc' ).innerHTML = img.kepalairas;
}

function initGallery() {
	setImage(0);
}

function scrollThumbs( dir ) {
	dir = dir * 110;
	var thumbEl = document.getElementById( 'thumbs' );
	thumbEl.scrollLeft = thumbEl.scrollLeft + dir;
}


// rotation
var pDelay = 5000;
var pRotate = true;

function initPreviews() {
	//showbox(pCurrent, 10);
	rotatePreviews();

}

function rotatePreviews() {
	if (pRotate == true) {

		var pMax = document.getElementById('selector').childNodes[0].length;
		var pCurrent = Math.floor( Math.random() * pMax +1 );

		showbox(pCurrent, pMax, color);

		//d = document.getElementById('debug');
		//d.innerHTML = pCurrent;

		if (pCurrent == pMax) { pCurrent = 1; } else { pCurrent++ }
		setTimeout("rotatePreviews()", pDelay);
	}
}


function showbox(pID, ppMax, color) {

	// display the box, highlight the button
	pic = document.getElementById('box_' + pID);
	act = document.getElementById('button_' + pID);

	pic.style.visibility = 'visible';
	act.className = 'active';
	act.childNodes[0].style.color = '#' + color;



	for(i=1;i <= ppMax; i++) {
		if(i!=pID){
			// remove all the boxes, remove highlights from the buttons
			document.getElementById('box_' + i).style.visibility = 'hidden';
			inact = document.getElementById('button_' + i);
			inact.className = 'inactive';
			inact.childNodes[0].style.color = '#000000';

		}
	}
}

function leadtoggle(key){
	pRotate = false;
	var title = document.getElementById('title' + key);
	var lead = document.getElementById('lead' + key);

	//title.style.display = 'none';
	//lead.style.display = 'block';
}

function leadoff(key){
	var pRotate = true;
	var title = document.getElementById('title' + key);
	var lead = document.getElementById('lead' + key);

	//title.style.display = 'block';
	//lead.style.display = 'none';
}

function keyFunc(id, value){
	var obj = document.getElementById(id);
	obj.style.opacity = value/100;
	return obj;
}
function cache(id){
	if(lastID != undefined){
		var tmp = lastID;
	}
	var lastID = id; 
	return tmp;
}
tMax = 2;
function switcher(pID) {
	cache(pID);
	if(cache(pID) == pID){
		alert('same');
	}
	var bodyObj = document.getElementById("pbody");
	var originalHeight = bodyObj.offsetHeight;
	bodyObj.style.height = originalHeight + 'px';

	if(pID == 2){
		fademe = 'box1';
	} else {
		fademe = 'box2';
	}
	//doOpacityChangeMem(keyFunc(fademe, 10),100,0,10,11,0.5);
	keyFunc('box' + pID, 0);
	document.getElementById('box' + pID).style.display = 'block';
	document.getElementById('switch'+pID+'left').style.display = 'block';
	document.getElementById('switch'+pID+'right').style.display = 'block';
	document.getElementById('switch' + pID).className = 'active';

	for(i=1;i <= tMax; i++) {
		if(i!=pID){
			document.getElementById('box' + i).style.display = 'none';
			// div height changed now
			document.getElementById('switch'+i+'left').style.display = 'none';
			document.getElementById('switch'+i+'right').style.display = 'none';
			document.getElementById('switch' + i).className = 'inactive';
		}
	}
	

	// get new div height
	var newObj = document.getElementById("innerbody");
	var newHeight = newObj.offsetHeight;
	
	//if(!newHeight) newHeight = 500;
	//alert(newHeight);
	//newObj.style.height = originalHeight+'px';
	doHeightChangeMem(bodyObj,originalHeight,newHeight,15,11,0.5);
	doOpacityChangeMem(keyFunc('box' + pID, 0),0,100,15,11,0.5);
	//doHeightChangeMem(elem,startHeight,endHeight,steps,intervals,powr, attached_func)
}

var sMax = 5;

function showstar(obj, pID) {

	for(i=1;i <= pID; i++) {

		document.getElementById(obj + '_star_' + i).className = 'switch-active';

	}

	for(y=pID+1; y <= sMax; y++) {

		document.getElementById(obj + '_star_' + y).className = 'switch-inactive';

	}

}

function verify_search(key){
	if (key.value.length < 3){
		alert('Minimum 3 karakter megadása szükséges.');
		return false;
	}
}

function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	} catch(err) { }
}


function popup(id,w,h) {
	var x = ((screen.width-w)/2);
	var y = ((screen.height-h)/2);
	var popup = window.open(''+id,'','width='+w+',height='+h+',hotkeys=0,dependent=1,alwaysRaised=1,location=0,resizable=1,status=0,titlebar=0,toolbar=0,directories=0,menubar=0,scrollbars=1,left=' +x+',top='+y+'');
}
function popup_ns(id,w,h) {
	var x = ((screen.width-w)/2);
	var y = ((screen.height-h)/2);
	var popup = window.open(''+id,'','width='+w+',height='+h+',hotkeys=0,dependent=1,alwaysRaised=1,location=0,resizable=0,status=0,titlebar=0,toolbar=0,directories=0,menubar=0,scrollbars=0,left=' +x+',top='+y+'');
}

function popup_banner(id,w,h) {
	var x = 100;
	var y = '40';
	var popup = window.open(''+id,'','width='+w+',height='+h+',hotkeys=0,dependent=1,alwaysRaised=1,location=0,resizable=0,status=0,titlebar=0,toolbar=0,directories=0,menubar=0,scrollbars=0,left=100,top=250');
}

function confirmRequest(msg, url) {
	if (confirm(msg)) {
		location = url;
		}	
}
function menufloat_y(y) {
	//alert('something');
	if(y > 39){
		document.getElementById('menu').style.height = y + 'px';
	} else {
		document.getElementById('menu').style.height = 39 + 'px';
	}
}

function blueprint() {
	var width = window.innerWidth;
	var height = window.innerHeight;
	if(document.getElementById('dhtml_goodies_id' + divCounter).style.display == 'none'){
		document.getElementById('dhtml_goodies_id' + divCounter).style.display = 'block';
	} else {
		document.getElementById('dhtml_goodies_id' + divCounter).style.display = 'none';
	}
}


function showElement(menu_id){
	var obj = document.getElementById(menu_id);
    obj.style.visibility = "visible";
}

function rollOutElement(menu_id){
	var obj = document.getElementById(menu_id);
    //document.getElementById(menu_id).style.visibility = "hidden";
    showElement(menu_id);

	var originalHeight = obj.offsetHeight;
	doHeightChangeMem(obj,10,originalHeight,15,11,0.5);

}

function hideElement(menu_id){
    document.getElementById(menu_id).style.visibility = "hidden";
}

function setBGColor(id){
   document.getElementById('' + id + '').style.backgroundColor = '#494949';
}

function unsetBGColor(id){
   document.getElementById(id).style.backgroundColor = 'transparent';
}

function flashSend(id, str){
	//alert(id+' _ '+str);
	popup('/tools/mail/0/' + id + '/' +str+ '', 450, 160);
}

/* flash.player */
function showBig(link, galid){
	popup_ns('/gallery/' + link +'/' + galid + '', 757, 487);
}

function go(where){
	if(where!="") window.location=where;
}

function colorSite(id){
	top.location='/tools/color/' + id;
}

function getVideo(){
	location.hash='#player';
}

function setPlayer(type, id){
	location.hash='#player';
	//frames['flashplayer'].document

	d = document;
	f = d.frames ? d.frames['fp'] : d.getElementById('flashplayer');
	p = f.document || f.contentWindow.document;
	q = p["cool_player"];
	if(type == 'photo') q.loadGallery(id);
	//if(type == 'video') q.loadVideo(id);
}

function videoPopup(id){
	popup_ns('/home/fullplayer/' + id + '', 640, 485);
}

/*function webaudit_hit(wid){	
	var wa=new WEBAUDIT();
	var felbontas = "";
	var same =  Math.floor(Math.random()*1000000);
	var wa_referrer = "@r=";
	
	if(wa.WACID==null)
	{
	  wa.WACID=wa.generateID('A');
	  wa.setCookie(wa.WACIDName,wa.WACID,wa.getTopDomain(wa.getDomain(document.URL)));
	}
	
	same = same + "@c=" + wa.WACID;
	if(screen) felbontas='@s='+screen.width+'x'+screen.height;
	if(document.referrer) wa_referrer=wa_referrer+document.referrer;
	same = same + felbontas + wa_referrer;

	var hiturl = "http://audit.median.hu/cgi-bin/track.cgi?uc=" + wid + "&dc=1&ui=" + same;
	window.webaudit_image = new Image();
	window.webaudit_image.src = hiturl;
	
}*/

function webaudit_hit(){

	var wa=new WEBAUDIT();
	var felbontas = "";
	var same =  Math.floor(Math.random()*1000000);
	var wa_referrer = "@r=";

	if(wa.WACID==null)
	{
	  wa.WACID=wa.generateID('A');
	  wa.setCookie(wa.WACIDName,wa.WACID,wa.getTopDomain(wa.getDomain(document.URL)));
	}
	
	same = same + "@c=" + wa.WACID;
	if(screen) felbontas='@s='+screen.width+'x'+screen.height;
	if(document.referrer) wa_referrer=wa_referrer+document.referrer;
	same = same + felbontas + wa_referrer;

	var hiturl = "http://audit.median.hu/cgi-bin/track.cgi?uc=11845886883715&dc=1&ui=" + same;
	window.webaudit_image = new Image();
	window.webaudit_image.src = hiturl;
	
}
