document.write('<div style="z-index: 3000;" style="hidden" class="jqmWindow jqmID1" id="dialog">&nbsp;</div>');


window.onload = function() {
	$("#dialog").jqm();
	
	//flash_anim();
	
	$('.ajaxForm').submit(function () {
		var target = this.target == false ? "dialog" : this.target;
		ajaxPostUpdate (this.id, this.action + (this.action.indexOf("?") == -1 ? "?" : "&") + "ajax=true", target, true);

		return false;
	});

	$('.ajaxLink').click(function () {
		var target = this.rel == false ? "dialog" : this.rel;
		ajaxGetUpdate (target, this.href + (this.href.indexOf("?") == -1 ? "?" : "&") + "ajax=true", true);

		return false;
	});
	validate();
}

$(document).ready(function () {
	windowHeight = $(window).height();
	windowWidth = $(window).width();
	$(".content").height(windowHeight - 255)
	$("#pane2").height(windowHeight - 255)
	
	
	if ( windowHeight <= 740) {
		$("#intro").height(740)
		$("body").css({'overflow-y':'scroll'});
		
	}else{
		$("#intro").height(windowHeight)
		$("body").css({'overflow-y':'hidden'});
		
	}
	if ( windowWidth <= 920) {
		$("#intro").width(920)
		$("body").css({'overflow-x':'scroll'});
		
	}else{
		$("#intro").width(windowWidth)
		$("body").css({'overflow-x':'hidden'});
		
	}
	//$('#pane2').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
	open_close();
	
	$(".noflash .hidden").css({'display':'block'});
	
});

$(window).resize(function() {
	windowHeight = $(window).height();
	windowWidth = $(window).width();
	$(".content").height(windowHeight - 255)
	$("#pane2").height(windowHeight - 255)
	if ( windowHeight <= 740) {
		$("#intro").height(740)
		$("body").css({'overflow-y':'scroll'});
		
	}else{
		$("#intro").height(windowHeight)
		$("body").css({'overflow-y':'hidden'});
		
	}
	if ( windowWidth <= 920) {
		$("#intro").width(920)
		$("body").css({'overflow-x':'scroll'});
		
	}else{
		$("#intro").width(windowWidth)
		$("body").css({'overflow-x':'hidden'});
		
	}
	//$('#pane2').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
});
function flash_anim() {
	$("#intro").css({'top':'-3000px'});
	/*$("#intro").animate({'opacity':0}, 1000, null, function(){
		
		
	});	*/	
}
function flash_close() {
	
	$("#intro").css({'top':'0'});
	//$("#intro").animate({'opacity': 1}, 1000, null);

}	
function open_close() {
	$(".open-close").each(function() {
		$(this).click(function(){
			$(this).toggleClass('open-close-2');
			$(this).next().slideToggle("fast");
		
		});
	});
	$(".winners .open-close").each(function() {
		$(this).toggleClass('open-close-2');
		$(this).next().slideToggle("fast");
	});
}
function regNext() {
	var fill=0
	var input=0
	var disclaimer = false
	$(".required input").each(function() {
		input ++
		if (this.value.length) {
			fill++
		}
	});
	$("#disclaimer").each( function() {
		if (this.checked == true ) {
			disclaimer = true
		}
	});
	if ( fill < input || disclaimer == false) {
		alert('Nem töltöttél ki minden kötelező mezőt!')
	}else{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = $('#email').val();
		if(reg.test(address) == false) {
			alert('Az e-mail cím formátuma nem megfelelő');
		} else {
			$(".regForm").css({'display':'none'});
			$(".quizForm").css({'display':'block'});
			window.location = "#top";
		}
	}
}

function regBack() {
	$(".quizForm").css({'display':'none'});
	$(".regForm").css({'display':'block'});
	window.location = "#top";
}	
function regDisclaimer() {
	$("#dialog").html($("#regDisclaimerDiv").html());
	$("#dialog").jqmShow();

	return false;
}
function saveBug() {
	$("#dialog").html($("#saveBugDiv").html());
	$("#dialog").jqmShow();

	return false;
}
function tooltip() {
	$(".infotool").mouseover(function(e){
		var Title = $(this).attr('name')
		$('body').append("<span class='tooltip'>"+Title+"</span>")
		$(".tooltip").css({"top":e.pageY+5, "left":e.pageX+20});
		$(".tooltip").fadeIn("fast");
		$('span.tooltip').css({'-moz-border-radius':'10px','-webkit-border-radius':'10px'});
		$(document).bind('mousemove', tooltip_position);
	}).mouseout(function(){
		
		$('.tooltip').remove();
		$(document).unbind('mousemove', tooltip_position);
		
	});
}
function tooltip_position(e) {
	$(".tooltip").css({"top":e.pageY+5, "left":e.pageX+20});
}


function imagetool() {
	$(".imagetool").mouseover(function(e){
		image = $(".hidden" , this).html()
		$('body').append("<span class='bodyimage'>"+image+"</span>")
		$(".bodyimage").css({"top":e.pageY-80, "left":e.pageX-250});
		$(".bodyimage").fadeIn("fast");
		$(document).bind('mousemove', imagetool_position);
	}).mouseout(function(){
		$('.bodyimage').remove();
		$(document).unbind('mousemove', imagetool_position);
		
	});
	
}
function imagetool_position(e) {
	$(".bodyimage").css({"top":e.pageY-80, "left":e.pageX-250});
}

function picRemove() {
	$('.bodyimage').remove();
	$(document).unbind('mousemove', imagetool_position);
}
function tabJump(tab) {
	$(".tabbed").each(function() {
		$(this).css({'display':'none'});
	});
	$("#"+tab).css({'display':'block'});
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function validate() {
	$('.content .main  form .textfield').css({'-moz-border-radius':'5px','-webkit-border-radius':'5px'});
	$('.content .main  form .button').css({'-moz-border-radius':'5px','-webkit-border-radius':'5px'});
	$('.content .main .rightcol .save').css({'-moz-border-radius':'5px','-webkit-border-radius':'5px'});
	$('.jqmWindow').css({'-moz-border-radius':'10px','-webkit-border-radius':'10px'});
	$('select').css({'-moz-border-radius':'5px','-webkit-border-radius':'5px'});
	$('.content .main .leftcol .codes-list').css({'overflow-y':'scroll'});
	$('#pane2').css({'overflow-y':'scroll','overflow-x':'hidden'});
	$('.content .main .fullcol .winner-list').css({'overflow-y':'scroll','overflow-x':'hidden'});
	$('.pDiv1').css({'opacity':'.5'});
	$('.pDiv2').css({'display':'block'});
	
}
