﻿// giZ on gizstyle.com jQuery implementation

$(window).load(function(){
	$(".welcome").fadeOut(1000, function() {
		$("#header_wrapper").fadeIn(1000);
		$("#wrapper").fadeIn(1000);
		$("#footer").fadeIn(1000);
		$("body");
	});
	
	$(".middle_image:not(:first)").hide();
	$(".description:not(:first)").hide();
	
	$('.flip_next').click(function() {
		$(".middle_image:visible").each(
			function(){
				$(this).hide();
				var next = $(this).next(".middle_image");
				if(next.hasClass("middle_image") == false) {
					next = $(".middle_image").first();
				}
				next.fadeIn("slow");
			}
		);
		$(".description:visible").each(
			function(){
				$(this).hide();
				var next = $(this).next(".description");
				if(next.hasClass("description") == false) {
					next = $(".description").first();
				}
				next.fadeIn("slow");
			}
		);
	});
	
	$('.flip_prev').click(function() {
		$(".middle_image:visible").each(
			function(){
				$(this).hide();
				var prev = $(this).prev(".middle_image");
				if(prev.hasClass("middle_image") == false) {
					prev = $(".middle_image").last();
				}
				prev.fadeIn("slow");
			}
		);
		$(".description:visible").each(
			function(){
				$(this).hide();
				var next = $(this).next(".description");
				if(next.hasClass("description") == false) {
					next = $(".description").first();
				}
				next.fadeIn("slow");
			}
		);
	});
});

$(document).ready(function(){
	var browserHeight = $(window).height() - 85;
	var imgHeight = $(window).height() - 185;
	var welcomePos = $(window).height() / 2 - 180;
	$(".welcome").css('top',''+welcomePos+'px');
	
	//MENU OVER FADE
	$(".folder a").mouseover(function(){
		$(this).animate({'color':'#ab0000'},1000);
	});
	$(".folder a").mouseout(function(){
		$(this).animate({'color':'#DADEC9'},1000);
	});
	
});

function load_thumb(source_thumb,source_link) {
	$(".flip-content").empty();
	$(".flip-content").append('<div class="load_photo" style="height:100px;"></div>');
	$(".flip-content").append('<a href="javascript:load_image(\''+source_link+'\')"><img src="'+source_thumb+'" alt="loading image" style="display:none;" class="thumb_image" /></a>');
	$(".flip-content").append('<a href="javascript:load_image(\''+source_link+'\')" class="flip_enlarge_78">enlarge</a>');
	$(".thumb_image").load(function(){
			$(".load_photo").fadeOut(500);
			$(".thumb_image").fadeIn(500);
		});
	};

function load_image(source_url) {
	$(".high-definition").empty();
	var browserHeight = $(window).height() - 110;
	var browserHeight_move = $(window).height();
	var browserWidth_move = $(window).width();
	var imgHeight = $(window).height() - 185;
	
	$(".high-definition").append('<div class="load_photo" style="height:'+imgHeight+'px;"></div>');
	$(".high-definition").append('<a href="javascript:close_image();" class="close_me">close</a>');
	$(".high-definition").append('<img class="hrimage" src="'+source_url+'" />');
	$(".high-definition").append('<img class="cloned_image" src="'+source_url+'" style="display:none;" />');
	$(".high-definition").append('<img class="preview_mouse" src="/upload/image.php'+source_url+'?height=120&amp;image='+source_url+'"/>');
	
	$(".preview_mouse").mousemove(function(e){
        var previewXpos = e.pageX - this.offsetLeft;
        var previewYpos = e.pageY - this.offsetTop;
		var zoomHeight = $(".cloned_image").height();
		var zoomWidth = $(".cloned_image").width();
		var preview_mouseHeight = $(".preview_mouse").height();
		var preview_mouseWidth = $(".preview_mouse").width();
		var browserHeight_follow = $(window).height() - 80;
		var browserWidth_follow = $(window).width();
		var x = e.pageX - this.offsetLeft;
		var y = e.pageY - this.offsetTop;
		var pageCx = x / preview_mouseWidth * (browserWidth_follow - zoomWidth);
		var pageCy = y / preview_mouseHeight * (browserHeight_follow - zoomHeight);
		
		$(".large").css('top',''+pageCy+'px');
		$(".large").css('left',''+pageCx+'px');
		
		/*
		$(".large").animate({
						top: ''+pageCy+'px',
						left: ''+pageCx+'px'
						}, 20);
		*/
	});
	
	$(".high-definition img").hide();
	$("#footer").fadeOut(1000);
	$("#case").fadeOut(1000, function() {
		$(".high-definition").animate({height: ""+browserHeight+"px"}, 1000);
		});
	
	$("body").removeClass("deco");
	
	$(".hrimage").load(function(){
	//	passo alla visione HD direttamente
		var zoomHeight = $(".cloned_image").height();
		var zoomWidth = $(".cloned_image").width();
		var zoomPosTop = (browserHeight_move - zoomHeight) / 2;
		var zoomPosLeft = (browserWidth_move - zoomWidth) / 2;
		$(".hrimage").css('position','absolute');
		$(".hrimage").css('width','auto');
		$(".hrimage").animate({
						top: ''+zoomPosTop+'px',
						left: ''+zoomPosLeft+'px'
						}, 1000);
		$(".hrimage").addClass("large");
		$(".preview_mouse").fadeIn(500);
		$(".hrimage").fadeIn(1000);
		$(".load_photo").fadeOut(500);
	});
	
	};
	
function enlarge_image() {
	var zoomHeight = $(".cloned_image").height();
	var zoomWidth = $(".cloned_image").width();
	var zoomPosTop = browserHeight_move - zoomHeight / 2;
	var zoomPosLeft = browserWidth_move - zoomWidth;
	$(".hrimage").animate({
					height: ''+zoomHeight+'px',
					top: ''+zoomPosTop+'px'
					}, 1000);
	$(".hrimage").animate({left: ''+zoomPosLeft+'px'}, 500);
	$(".hrimage").addClass("large");
	$(".preview_mouse").fadeIn(500);
	};
	
function close_image() {
	$(".high-definition").animate({height: "0px"}, 1000, function() {
		$("#case").fadeIn(1000);
		$("#footer").fadeIn(1000);
		$(".hrimage").removeClass("large");
		});
	$("body").addClass("deco");
	};
	
function resize_image() {
	var browserHeight = $(window).height() - 85;
	var imgHeight = $(window).height() - 185;
	$(".hrimage").css('height',''+imgHeight+'');
	var browserHeight_move = $(window).height();
	var browserWidth_move = $(window).width();
	var previewHeight = $(".hrimage").height();
	var previewWidth = $(".hrimage").width();
	var previewPosTop = (browserHeight_move - previewHeight - 80 ) / 2;
	var previewPosLeft = (browserWidth_move - previewWidth) / 2;
	$(".hrimage").css('top',''+previewPosTop+'px');
	$(".hrimage").css('left',''+previewPosLeft+'px');
	$(".hrimage").removeClass("large");
	$(".preview_mouse").fadeOut(500);
	};
	

