$(document).ready(function() {

function aHorgony(jelenlegi) {
	return jelenlegi.split('#')[1];
}

var alapcim = "ákos burg photography";
var pozicio = document.location.toString();
var horgony = aHorgony(pozicio);

if(((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/Android/i))) && !(navigator.userAgent.match(/iPad/i))) {
	//alert(navigator.userAgent);
	if (!horgony) {
		var horgony = "";
	}
	document.location = "http://www.akosburg.com/mobile/"+horgony;
}
if ((navigator.userAgent.match(/iPad/i))) {
	$(function() {	
		$("#main_container").scrollable({
			mousewheel: true,
			items: ".photos",
			circular: true,
			speed: 600,
		});
	});
	$("#takaro").remove();
} else {
	$(document).bind('mousemove', function(e){
		var x_hely_kepek = (((parseInt($(".photos").width()) - parseInt($(window).width()))) / parseInt($(window).width())) * parseInt(e.pageX);
		
		$('.photos').clearQueue();
		$('.photos').css("left", "-" + x_hely_kepek + "px");
/*
		$('.photos').animate({
		   left:  "-" + x_hely_kepek + "px",
		}, 100);
*/
		$("#eger").html(e.pageX);
	});
}

document.title = alapcim;

$(window).load(function() {
	//$(".scrollable").css("width", $(".photos").width()+"px");
});

var kozepre = ['categories', 'copyright', 'contact', 'about'];
$.each(kozepre, function(index, value) {
	$("#"+value).css("margin-left", "-"+(parseInt($(("#"+value)).width()) / 2)+"px");
});
/*
$("#categories").css("margin-left", "-"+(parseInt($("#categories").width()) / 2)+"px");
$("#copyright").css("margin-left", "-"+(parseInt($("#copyright").width()) / 2)+"px");
$("#contact").css("margin-left", "-"+(parseInt($("#contact").width()) / 2)+"px");
$("#about").css("margin-left", "-"+(parseInt($("#about").width()) / 2)+"px");
*/


var panelek = ["contact", "about"];

function ablak_befolyas(amelyik) {
	document.title = alapcim+" - " + amelyik;
	if (amelyik == "contact") {
		var amasik = "about";
	} else {
		var amasik = "contact";
	}
	if ($("#"+amasik).css("top") == "0px") {
		$("#"+amasik).animate({
			top: "-"+$("#"+amasik).height()+"px",
			opacity: 0,
		}, 750);
	}
	if ($("#"+amelyik).css("top") != "0px") {
		$("#"+amelyik).animate({
			top: "0px",
			opacity: 1,
		}, 750);
	} else {
		$("#"+amelyik).animate({
			top: "-"+$("#"+amelyik).height()+"px",
			opacity: 0,
		}, 750);
	}
}

function ablakok_bezaras() {
	$.each(panelek, function(index, value) {
		$("#"+value).animate({
			top: "-"+$("#"+value).height()+"px",
			opacity: 0,
		}, 750);
	});
}

function galeriaValtas(gomb, hello) {
	ablakok_bezaras();
	if (aHorgony(document.location.toString()) != gomb || hello == "bello") {
		document.title = alapcim+" - " + gomb;
		$('body').append('<div id="loader">loading...</div>');
		$("#loader").animate({
			opacity: 1,
		}, 500);
		var datastr = "mitis=galeria_kepek&nev="+gomb;
		$.ajax({
			type: "POST",
			url: "/tartalom/ajax.php",
			data: datastr,
			cache: false,
			success: function(html){
				$("#loader").animate({
					opacity: 0,
				}, 500, '', function() {
					$("#loader").remove();
				});
				$(".photos").animate({
					opacity: 0,
				}, 500, '', function(){
					$(".photos").html(html);
						$(".photos").animate({
							opacity: 1,
						}, 500);
						$(".photos").css("left", 0);
				});
			}
		});
	}
}

if (pozicio.match('#') && aHorgony(document.location.toString()) != "hello") {
	$("#minden").css("opacity", "1");
	if (jQuery.inArray(horgony, panelek) != "-1") {
		ablak_befolyas(horgony);
	} else if (jQuery.inArray(horgony, kategoriak) != "-1") {
		galeriaValtas(horgony, "bello");
	}
} else {
	$("#logo").animate({
		opacity: 1,
	}, 2000);
}

$("#about_link").click(function() {
	ablak_befolyas("about");
});

$("#contact_link").click(function() {
	ablak_befolyas("contact");
});

$(".window_close").click(function() {
	document.title = alapcim;
	ablakok_bezaras();
/*
	$.each(panelek, function(index, value) {
		$("#"+value).animate({
			top: "-"+$("#"+value).height()+"px",
			opacity: 0,
		}, 750);
	});
*/
});

$('.kategoria_link').live('click', function() {
	galeriaValtas($(this).attr("href").split('#')[1]);
});

$(window).click(function() {
	if ($("#minden").css("opacity") == "0") {
		document.location = "http://www.akosburg.com/#main";
		$("#logo").animate({
			opacity: 0,
			"z-index": 0,
		}, 500, '', function() {
			$("#minden").animate({
				opacity: 1,
			}, 1000);
		});
	}
});

$("#vissza").click(function() {
	//if ($("#minden").css("opacity") == "0") {
		document.location = "http://www.akosburg.com/#hello";
		$("#minden").animate({
			opacity: 0,
		}, 500, '', function() {
			$("#logo").animate({
				opacity: 1,
				"z-index": 10,
			}, 1000);
		});
	//}
});

});
