jQ = jQuery.noConflict();

/* preset */
var oID = document.getElementById;
var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;
/* /preset */



var Site = function (){

		var certificates = {
			0: "cert_bestw.png",
			1: "cert_iso.png",
			2: "cert_ms.png",
			3: "cert_oracle.png",
			4: "cert_adp.png"
		}

	Event.onReady( function(){ Site.load(); });

	return {
		certificates: function(e,i,b){
			if(b){
				if(document.agent.ie && parseInt(document.agent.ie.version, 10) <= 6){
					$('CertificatesInfo').setStyle({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', src='/i/"+certificates[i]+"', sizingMethod='crop');" });
				} else {
					$('CertificatesInfo').innerHTML = '<img src="i/'+certificates[i]+'" alt="" />';
				}
				$('CertificatesInfo').show();
			} else {
				$('CertificatesInfo').hide();
			}
		},
		load: function(){

				if (document.body.className.indexOf('eng') >= 0) {
					certificates = {
						0: "cert_bestw_eng.png",
						1: "cert_iso_eng.png",
						2: "cert_ms_eng.png",
						3: "cert_oracle_eng.png",
						4: "cert_adp_eng.png"
					}
				}

				if ($('Certificates')) {

				var div=document.createElement('div');
				div.id = 'CertificatesInfo';
				$('Certificates').appendChild(div);
				$('CertificatesInfo').hide();
				
				if ($$('div#Certificates a.adp').length > 0) {
					Event.observe($$('div#Certificates a.adp')[0],'mouseover',Site.certificates.bindAsEventListener(this,4,true));
					Event.observe($$('div#Certificates a.adp')[0],'mouseout',Site.certificates.bindAsEventListener(this,4,false));
				}
				if ($$('div#Certificates a.bestwork').length > 0) {
					Event.observe($$('div#Certificates a.bestwork')[0],'mouseover',Site.certificates.bindAsEventListener(this,0,true));
					Event.observe($$('div#Certificates a.bestwork')[0],'mouseout',Site.certificates.bindAsEventListener(this,0,false));
				}
				if ($$('div#Certificates a.iso').length > 0) {
					Event.observe($$('div#Certificates a.iso')[0],'mouseover',Site.certificates.bindAsEventListener(this,1,true));
					Event.observe($$('div#Certificates a.iso')[0],'mouseout',Site.certificates.bindAsEventListener(this,1,false));
				}
				if ($$('div#Certificates a.microsoft').length > 0) {
					Event.observe($$('div#Certificates a.microsoft')[0],'mouseover',Site.certificates.bindAsEventListener(this,2,true));
					Event.observe($$('div#Certificates a.microsoft')[0],'mouseout',Site.certificates.bindAsEventListener(this,2,false));
				}
				if ($$('div#Certificates a.oracle').length > 0) {
					Event.observe($$('div#Certificates a.oracle')[0],'mouseover',Site.certificates.bindAsEventListener(this,3,true));
					Event.observe($$('div#Certificates a.oracle')[0],'mouseout',Site.certificates.bindAsEventListener(this,3,false));
				}
				
				if (document.all) {
				var divs = document.getElementsByTagName('div');
				var span = null;
				for (var i=0; i<divs.length; i++) {
					if (divs[i].className.indexOf('nexonBox')>=0) {
						span = divs[i].getElementsByTagName('span');
						getDimension(divs[i]);
						for (var j=0; j<span.length; j++) {
							if (span[j].className == 'tr') {
								span[j].style.left = String(divs[i]._width-12) + 'px';
							}
							if (span[j].className == 'br') {
								span[j].style.left = String(divs[i]._width-12) + 'px';
								span[j].style.top = String(divs[i]._height-12) + 'px';
							}
							if (span[j].className == 'bl') {
								span[j].style.top = String(divs[i]._height-12) + 'px';
							}
						}
					}
				}
				}

			}
		}
	};
}();

var Galery = function (){
	
	var object 			= false;
	var images 			= 0;
	var currentImage	= 0;
	var pages 			= 0;
	var currentPage		= 1;
	
	return {
		
		load: function(_id){
			if(jQuery){
				object = _id;
				images =jQ('#'+object+' div.thumbnails div.slider a').length;
				jQ('#'+object+' div.thumbnails div.slider').css({width:  eval(images * 130)});
				jQ('#'+object+' div.thumbnails div.slider a').each(function(i,s){
					s.onclick = function(){
						Galery.show(i);
						return false;					
					}
				});
				// Semantic error				
				// pages = (Math.floor(images / 4) % 4 == 0)?Math.floor(images / 4):Math.floor(images / 4)+1;
				pages = (images % 4 == 0?images / 4:Math.floor(images / 4)+1);
				pager = '<span class="prev" onclick="Galery.page.previous();">&laquo;</span>';
				for(var i = 1;i<=pages;i++ ){
					pager += '<span class="page" onclick="Galery.page.go('+i+');">'+i+'</span>';
				}
				pager += '<span class="next" onclick="Galery.page.next();">&raquo;</span>';
				jQ('#'+object+' div.pager').html(pager);				
				jQ('#'+object+' div.pager span.page').eq(currentPage-1).addClass('on');
				
				jQ('div#Galery div.next').mouseover(function(e){
					jQ(this).find('span').show();
					jQ(e).stop();
				}).mouseout(function(e){
					jQ(this).find('span').hide();
					jQ(e).stop();
				});
				jQ('div#Galery div.prev').mouseover(function(e){
					jQ(this).find('span').show();
					jQ(e).stop();
				}).mouseout(function(e){
					jQ(this).find('span').hide();
					jQ(e).stop();
				});
				jQ('div#Galery div.prev span').click(function(){
					Galery.previous();
				});
				jQ('div#Galery div.next span').click(function(){
					Galery.next();
				});
				this.show(0);
			} else {
				return false;
			}
		},
		show: function(  _i ){			
			if(jQ('#'+object+' div.thumbnails div.slider a').eq(_i).find('span').text().length > 0){
				jQ('#'+object+' div.caption span').text(jQ('#'+object+' div.thumbnails div.slider a').eq(_i).find('span').text());
				jQ('#'+object+' div.caption div.bg').css('height',jQ('#'+object+' div.caption')[0].offsetHeight);
			}			
			jQ('img#GaleryImage').attr('src',jQ('#'+object+' div.thumbnails div.slider a').eq(_i).attr('href'));
			page = ((_i+1) % 4 == 0)?Math.floor((_i+1) / 4):Math.floor((_i+1) / 4)+1;
			if(page != currentPage)
				this.page.go(page);
			
			currentImage = _i;
		},
		previous: function(){
			if(currentImage > 0){
				this.show(currentImage-1);
			}
		},
		next: function(){
			if(currentImage < images){
				this.show(currentImage+1);
			}
		},		
		page: {
			previous: function(){			
				if(currentPage != 1){
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).removeClass('on');
					jQ('#'+object+' div.thumbnails div.slider').animate({
						marginLeft: eval(parseInt(jQ('#'+object+' div.thumbnails div.slider').css('marginLeft'),10)+518)
					},800);
					currentPage--;
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).addClass('on');
				}
			},
			next: function(){
				if(currentPage != pages){
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).removeClass('on');
					jQ('#'+object+' div.thumbnails div.slider').animate({
						marginLeft: eval(parseInt(jQ('#'+object+' div.thumbnails div.slider').css('marginLeft'),10)-518)
					},800);
					currentPage++; 
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).addClass('on');
				}
			},	
			go: function(_p){
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).removeClass('on');
					jQ('#'+object+' div.thumbnails div.slider').animate({
						marginLeft: eval((_p-1)*-518)
					},800);		
					currentPage = _p; 	
					jQ('#'+object+' div.pager span.page').eq(currentPage-1).addClass('on');			
			}
		}
	};	
}();

function show_nexon_tortenelem() {
	showpic("swf/nexon_tortenelem_v6_small.swf", 821, 377, "Nexon t&ouml;rt&eacute;nelem", this);
}

function show_nexon_tortenelem_en() {
	showpic("swf/nexon_tortenelem_en.swf", 821, 377, "Nexon history", this);
}



/* object relative and absolute dimensions and position */
function getDimension(obj) {
	obj._x = obj.offsetLeft;
	obj._y = obj.offsetTop;
	obj._width = obj.offsetWidth;
	obj._height = obj.offsetHeight;
	return {_x: obj._x, _y: obj._y, _width: obj._width, _height: obj._height};
}

function browserDimensions() {
	return {
		_width: document.documentElement.clientWidth,
		_height: document.documentElement.clientHeight,
		width: document.documentElement.scrollWidth,
		height: document.documentElement.scrollHeight,
		scrolltop: document.documentElement.scrollTop
	}
}
/* /object relative and absolute dimensions and position */



/* show picture in popup */
var popup = null;
function showpic(pic, w, h, label, obj) {
	if (obj) {
		obj.blur();
	}
	if ((popup) && (!popup.closed)) {
		popup.close();
	}
	popup = window.open('','popup','directories=0,location=0,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,width='+String(w)+',height='+String(h)+',left='+String(Math.floor((screen.width-w)/2))+',top='+String(Math.floor((screen.height-h)/2)-22));
	with (popup.document) {
		open('text/html');
		writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
		writeln('<html xmlns="http://www.w3.org/1999/xhtml">');
		writeln('<head>');
		writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		writeln('<title>' + ((label != '') ? label : '') + '</title>');
		writeln('<style>');
		writeln('html, body {margin: 0px; padding: 0px; width: 100%; height: 100%; background: #000000; border: none 0px; overflow: hidden;}');
		writeln('body {position: relative; display: block;}');
		writeln('a, img, object {position: absolute; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; border: none 0px;}');
		writeln('</style>');
		writeln('</head>');
		writeln('<body>');
		if (String(pic).indexOf('.swf') >= 0) {
			writeln('<object type="application/x-shockwave-flash" data="'+pic+'"><param name="movie" value="'+pic+'" /></object>');
		} else {
			writeln('<img src="'+pic+'" alt="" />');
		}
		writeln('<a href="javascript:;" onclick="self.close(); return false;"></a>');
		writeln('</body>');
		writeln('</html>');
		close();
	}
	popup.focus();
}
/* /show picture in popup */



function berszamfejtoNaptarOpen(link) {
	window.open(link,'naptar','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=575,height=692');
}

function tbNaptarOpen(link) {
	window.open(link,'naptar','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=600');
}

function setsearchvalue(obj) {
	if (obj.value == obj.title) {
			obj.value = '';
		} else if (obj.value == '') {
			obj.value = obj.title;
		}
}


jQ(document).ready(function(){
	jQ(".certification").fadeOut(0)
	jQ(".cert.adp").on("mouseover", function(){
		jQ(".certification.adp").fadeIn(100)
	})
	jQ(".cert.ms").on("mouseover", function(){
		jQ(".certification.ms").fadeIn(100)
	})
	jQ(".cert.oracle").on("mouseover", function(){
		jQ(".certification.oracle").fadeIn(100)
	})
	jQ(".cert.iso").on("mouseover", function(){
		jQ(".certification.iso").fadeIn(100)
	})
	jQ(".cert.iso2").on("mouseover", function(){
		jQ(".certification.iso2").fadeIn(100)
	})
	jQ(".cert").on("mouseout", function(){
		jQ(".certification").fadeOut(100)
	})
	
	
	jQ( ".cbrbgroup input" ).button();
	
})





