function saveMessage(){
	var nickname = document.getElementById("nickname").value;
	var message  = document.getElementById("message").value;
	
	if (nickname.length == 0)
	{
		alert("Nem adtál meg nicknevet");
		return false;
	}
	
	if (message.length < 3)
	{
		alert("Túl kevés az üzenet tartalma!");
		return false;
	}
	
	$.ajax({
	   	type: "POST",
	   	url:  "ajax.handler.php",
	   	data: "nickname="+nickname+"&message="+message+"&messagesend=1",
	   	success: function(msg){
	   	 msg = msg.replace(/^\s+|\s+$/g, "") ;
		 if (msg=="OK")
		 {
		 	alert("Az üzenet sikeresen hozzáadva!");
		 	window.location = 'index.php';
		 }
		 else
		 {
		 	alert(msg);
		 }
	   	}
 	});
 	
	return false;
}


function showMessageForm()
{
	var divBackground = document.getElementById("message_placeholder");
	var messageForm = document.getElementById("fixme");
	divBackground.style.display = "block";
	messageForm.style.display = "block";
	return false;
}

function hideMessageForm()
{
	var divBackground = document.getElementById("message_placeholder");
	var messageForm = document.getElementById("fixme");
	divBackground.style.display = "none";
	messageForm.style.display = "none";
	return false;
}

function getResultContent(resultId){
	
	$.ajax({
	   	type: "POST",
	   	url: "ajax.handler.php",
	   	data: "resultid="+resultId,
	   	success: function(msg){
	   		 $("div[@id=resultContent]").html(msg);
	   		 $("a[@id=resultContent_href]").click(closeResultContent);
	   	}
 	});
 	
	return false;
}
 
function fadeIn()
{
	$('img', this).fadeTo("fast", 0.5);
	return false;
}

function fadeOut()
{
	$('img', this).fadeTo("fast", 1);
	return false;
}

function showBigImage()
{
	var placeHolderDiv  = $("div[@id=hirekBigimage]").eq(0);
	var bigImage		= $("img", placeHolderDiv).eq(0);
	var selectedImageSrc= $("img", this).eq(0).attr("src").replace(/thumb/,"med");
	
	bigImage.attr({ src: selectedImageSrc, alt: "Hír kép" });
	placeHolderDiv.show("slow");
	
	return false;
}

function closeBigImage()
{
	var placeHolderDiv  = $("div[@id=hirekBigimage]").eq(0);
	placeHolderDiv.hide("slow");
	return false;
}

function showResultContent()
{	
	var placeHolderDiv  = $("div[@id=resultContent]").eq(0);
	var resultId  = $("input", this).eq(0).attr("value");
	
	getResultContent(resultId);
	
	placeHolderDiv.show("slow");
	
	return false;
}

function closeResultContent()
{
	var placeHolderDiv  = $("div[@id=resultContent]").eq(0);
	placeHolderDiv.hide("slow");
	return false;
}

function sendTeamForm()
{
	$("#selectTeam")[0].submit();
}

function sendResultForm()
{
	$("#selectYear")[0].submit();
}

function showPositionsDetails(element)
{
	var divID = this.id.replace("Href", "");
	var el = $("div[@id="+divID+"]").eq(0);
	
	el.show("slow");
	
	return false;
}

function closePositionsDetails(element)
{
	var divID = this.id.replace("Href", "");
	var el = $("div[@id="+divID+"]").eq(0);

	el.hide("slow");
	
	return false;
}

function overButton1BG(element)
{
	document.getElementById("newmsg").style.backgroundImage = "../images/aquabutton_red.png";
	return false;
}

function outButton1BG(element)
{
	//$(this).css("background-image", "images/aquabutton.png");
	document.getElementById("newmsg").style.backgroundImage = "../images/aquabutton.png";
	return false;
}

function overButton2BG(element)
{
	$(this).css("background-image", "images/aquabutton2_red.png");
	return false;
}

function outButton2BG(element)
{
	/*
	var selector = '"#'+this.id+'"';
	$(this).attr("src", "images/aquabutton2.png");
	return false;
	*/
}

var actualPage = 0;
var actualGallery = "";

function pageRight()
{
	actualPage++;
	
	$.ajax({
	   	type: "POST",
	   	url: "ajax.handler.php",
	   	data: "galleryid="+actualGallery+"&page="+actualPage,
	   	success: function(data){
	     data = eval('(' + data + ')');
	     
	     if (data.isLastPage)
	     {
	     	 $("div.jobbgomb")[0].style.display = "none";
	     }
	     else
	     {
	     	$("div.jobbgomb")[0].style.display = "block";
	     }
	     
	     if (actualPage > 1)
	     {
	     	$("div.balgomb")[0].style.display = "block";
	     }
	     
	     picture1 = $("img", $("a[@id=gallery_picture1]"));
	     picture2 = $("img", $("a[@id=gallery_picture2]"));
	     picture3 = $("img", $("a[@id=gallery_picture3]"));
	     picture4 = $("img", $("a[@id=gallery_picture4]"));
	     
	     picture1.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[0]);
	     picture2.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[1]);
	     picture3.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[2]);
	     picture4.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[3]);
	     
	     if (actualPage == 1)
	     {
	     	$("img", $("a[@id=galleryBigImage]")).attr("src", "images/arch/"+data.galleryDir+"/"+data.pictures[0]);
	     }
	     
	   	}
 	});
 	
	return false;
}

function pageLeft()
{
	actualPage--;
	
	$.ajax({
	   	type: "POST",
	   	url: "ajax.handler.php",
	   	data: "galleryid="+actualGallery+"&page="+actualPage,
	   	success: function(data){
	     data = eval('(' + data + ')');
	     
	     if (data.isFirstPage)
	     {
	     	 $("div.balgomb")[0].style.display = "none";
	     }
	     else
	     {
	     	$("div.balgomb")[0].style.display = "block";
	     }
	     
	     $("div.jobbgomb")[0].style.display = "block";
	     
	     picture1 = $("img", $("a[@id=gallery_picture1]"));
	     picture2 = $("img", $("a[@id=gallery_picture2]"));
	     picture3 = $("img", $("a[@id=gallery_picture3]"));
	     picture4 = $("img", $("a[@id=gallery_picture4]"));
	     
	     picture1.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[0]);
	     picture2.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[1]);
	     picture3.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[2]);
	     picture4.attr("src", "images/arch/"+data.galleryDir+"/tmb/"+data.pictures[3]);
	     
	   	}
 	});
 	
	return false;
}

function showGalleryBigImage()
{
	$("img", "a[@id=galleryBigImage]").attr("src", $("img", this)[0].src.replace("/tmb/", "/med/"));
	return false;
}

function openPopup(pictureLink)
{
	window.open($("img", this)[0].src.replace("/med", ""), "_blank");
	return false;
}

function openBlackBackground()
{
	actualPage = 0;
	
	$("div.gallery_placeholder")[0].style.display = "block";
	$("div.balgomb")[0].style.display = "none";
	
	actualGallery = this.id.replace("_gallery", "");
	
	$("img", $("a[@id=galleryBigImage]")).attr("src", "images/default_gallery_big.jpg");
	$("img", $("a[@id=gallery_picture1]")).attr("src", "images/default_gallery.jpg");
	$("img", $("a[@id=gallery_picture2]")).attr("src", "images/default_gallery.jpg");
	$("img", $("a[@id=gallery_picture3]")).attr("src", "images/default_gallery.jpg");
	$("img", $("a[@id=gallery_picture4]")).attr("src", "images/default_gallery.jpg");
	
	pageRight();
	
	return false;
}

function hideBlackBackground()
{
	$("div.gallery_placeholder")[0].style.display = "none";
	return false;
}

 $(document).ready(function(){
   $("input[@id=newmsg]").click(showMessageForm).mouseover(overButton1BG).mouseout(outButton1BG);
   $("a[@id=close_link]").click(hideMessageForm);
   $("input[@id=messagesend]").click(saveMessage).mouseover(overButton2BG).mouseout(outButton2BG);;
   $("a.menu_text").mouseover(fadeIn).mouseout(fadeOut);
   $("a[@id=newsPictureLink]").click(showBigImage)
   $("a.hirekBigimage_href").click(closeBigImage);
   $("#jumpMenu").change(sendTeamForm);
   $("#jumpMenu2").change(sendResultForm);
   $("a.positions_circle").click(showPositionsDetails);
   $("a.positions_circle").mouseout(closePositionsDetails);
   $("a.link3_1").click(showResultContent);
   $("a[@id=resultContent_href]").click(closeResultContent);
   
   $("a.gallery_link").click(showGalleryBigImage);
   $("a[@id=gallery_left_btn]").click(pageLeft);
   $("a[@id=gallery_right_btn]").click(pageRight);

   $("a[@id=galleryBigImage]").click(openPopup);
   $("a", $("div.picture_line")).click(openBlackBackground);
   $("a.close_link2").click(hideBlackBackground);
 });

