// JavaScript Document
var imgClicked = "1";
var elementHover = "99";
var img = 1;
var height = 1;
var blogContact = 0;
var blogAbout = 0;
var imgCache = 'x';
var holder = 1;
var holder2 = 1;
var imgPreload = 1;

	function photoLoader() {
		holder=1;
		$("#"+imgClicked).css({ opacity: 0.5 });
		$("#photoDisplay").attr('src', 'loader.gif');
		$("#photoDisplay").fadeIn(600);
		imgCache = document.createElement('image'+imgClicked);
		imgCache.src = 'photo/'+imgClicked+'.jpg';
		holder2 = parseInt(imgClicked);
		$("#photoDisplayLoader").attr('src', 'photo/'+imgClicked+'.jpg');
			$("#photoDisplayLoader").load(function() {
				if(holder==1){
					$("#photoDisplay").fadeOut(200, function()	{										 
						$("#photoDisplay").attr('src', 'photo/'+imgClicked+'.jpg');
						$("#photoDisplay").fadeIn(600);
							if(holder2==45){
								imgPreload=1;
								$("#photoDisplayLoader2").attr('src', 'photo/'+imgPreload+'.jpg');
							}else {
								imgPreload=holder2+1;
								$("#photoDisplayLoader2").attr('src', 'photo/'+imgPreload+'.jpg');
							}
					});
				holder=0;
				}
			});
	}


$('.photoThumb').click(function() {
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: 127}, 500 );
   $("#"+imgClicked).css({ opacity: 1 });
   imgClicked = $(this).attr("id");
   $("#photoDisplay").fadeOut(400, photoLoader);
   return false;
});

$('.photoThumb').hover(
	function() {
		elementHover = $(this).attr("id");
		$("#"+elementHover).css({ opacity: 0.5 });
	},
	function() {
		elementHover = $(this).attr("id");
		$("#"+elementHover).css({ opacity: 1 });
		$("#"+imgClicked).css({ opacity: 0.5 });
	}
);

$('.photoDisplayArea').hover(
	function() {
		$("#navLeft").css({ visibility: "visible" });
		$("#navRight").css({ visibility: "visible" });
	},
	function() {
		$("#navLeft").css({ visibility: "hidden" });
		$("#navRight").css({ visibility: "hidden" });
	}
);

$('#navLeft').hover(
	function() {
		$("#navLeft").css({ opacity: 0.85 });
	},
	function() {
		$("#navLeft").css({ opacity: 0.5 });
	}
);

$('#navRight').hover(
	function() {
		$("#navRight").css({ opacity: 0.85 });
	},
	function() {
		$("#navRight").css({ opacity: 0.5 });
	}
);


$('#navRight').click(function() {
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: 127}, 500 );
	$("#"+imgClicked).css({ opacity: 1 });
	var thumbVal = parseInt(imgClicked) + 1;
		if (imgClicked==45)
		{
		imgClicked = 1;
		}
		else
		{
		imgClicked = thumbVal;
		}
	$("#photoDisplay").fadeOut(400, photoLoader);
	return false;
});

$('#navLeft').click(function() {
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: 127}, 500 );
	$("#"+imgClicked).css({ opacity: 1 });
	var thumbVal = parseInt(imgClicked) - 1;
		if (imgClicked==1)
		{
		imgClicked = 45;
		}
		else
		{
		imgClicked = thumbVal;
		}
	$("#photoDisplay").fadeOut(400, photoLoader);
	return false;
});


//var img = document.getElementById('photoDisplay');
//var height = img.clientHeight;
//$("#navLeft").css('height',height);




$("#cinemaMenu").click(function(){
	$(".section1").animate({"top": "-=600px"}, 900,'easeInOutQuint', function() { 
			document.location.href = 'cinema.html'; 
	});									   
});

$("#photoMenu").click(function(){
	$(".section1").animate({"top": "-=600px"}, 900,'easeInOutQuint', function() { 
			document.location.href = 'photo.html'; 
	});									   
});

$("#aboutMenu").click(function(){
	$(".section1").animate({"top": "-=600px"}, 900,'easeInOutQuint', function() { 
			document.location.href = 'http://blog.ivaylogetov.com'; 
	});									   
});







$('.nav').click(function() {
   var elementClicked = $(this).attr("href");
   var destination = $(elementClicked).offset().top;
   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-10}, 500 );
   return false;
});

$('#aboutIvayloLink').click(function() {
	if (blogAbout==0){
		$("#aboutIvaylo").animate({height: '200px'}, 900);
		blogAbout = 1;
	} else {
		$("#aboutIvaylo").animate({height: '0px'}, 900);
		blogAbout = 0;
	}
});


$('#contactIvayloLink').click(function() {
	if (blogContact==0){
		$("#contactIvaylo").animate({height: '200px'}, 900);
		blogContact = 1;
	} else {
		$("#contactIvaylo").animate({height: '0px'}, 900);
		blogContact = 0;
	}
});


$(document).ready(function() {
						   

	$("#"+imgClicked).css({ opacity: 0.5 });
						   
	$("#navLeft").css({ opacity: 0.5 });
	$("#navRight").css({ opacity: 0.5 });
 
	$("#photoLink").click(function(){
		$("body").fadeOut(1000, redirectPagePhoto);
	});
	$("#aboutLink").click(function(){
		$("body").fadeOut(1000, redirectPageBlog);
	});
	$("#cinemaLink").click(function(){
		$("body").fadeOut(1000, redirectPageCinema);
	});
	$("#cinemaPageDiv").click(function(){
		$("body").fadeOut(1000, redirectPageMain);
	});
	$("#photoPageDiv").click(function(){
		$("body").fadeOut(1000, redirectPageMain);
	});
	$("#blogPageDiv").click(function(){
		$("body").fadeOut(1000, redirectPageMain);
	});
	
	
	

	function redirectPagePhoto() {
		document.location.href = 'http://www.ivaylogetov.com/photo.html';
	}
	function redirectPageBlog() {
		document.location.href = 'http://blog.ivaylogetov.com'; 
	}
	function redirectPageCinema() {
		document.location.href = 'http://www.ivaylogetov.com/cinema.html'; 
	}
	function redirectPageMain() {
		document.location.href = 'http://www.ivaylogetov.com/index.html'; 
	}
	
});



