window.scrollTo(0, 0)

jQuery(document).ready(function($) {

$("body").addClass("js"); // .js class


$("a.preview").children("img").css('opacity', '0.5');

$('a.preview .h2').each(function(){
	var height = $(this).height();
	var top = (100 - height) / 2;
	$(this).css("padding-top", top);
});


$("a.preview .inside").hover(function(){
	$(this).children(".slide").stop()
		.animate({'top' : '-150px'}, 300);
} , function() {
	$(this).children(".slide").stop()
		.animate({'top' : '0px'}, 300);
});


$('#dump').prependTo("#gap #contact");

var czone_start_height = '15px';
var gap_height = $("#gap #contact").height();
	var gap = ((gap_height * 1) + 95) + 'px';

$("#czone").height(czone_start_height);
$("#contact_btn").click(function(event){
	event.preventDefault();
	
	//var gap = '298px';
	if ($(this).hasClass("clicked")){
		$(this).removeClass("clicked");
		$("#czone").animate({'height' : czone_start_height }, 400);
	} else {
		$(this).addClass("clicked");
		$("#czone").animate({'height' : gap }, 300);
	}	
});
$("#c_close").click(function(){
	$("#contact_btn").removeClass("clicked");
	$("#czone").animate({'height' : czone_start_height }, 400);
});


$(".folio-nav span").css("opacity","0").css("display","block");

// hover next folio items.
$(".folio-nav a").hover(function(){
	$(this).siblings("span").stop().animate({'opacity' : 1 }, 300);
} , function() {
	$(this).siblings("span").stop().animate({'opacity' : 0 }, 300);
});


$(".next-nav a").hover(function(){
	$(".next-nav span").stop().animate({'opacity' : 1 }, 200);
});


$("#c_top").css("opacity", "0");
$("#c_close").css("opacity", "0");
$("#c_bot").css("opacity", "0");
$("#c_bot_shadow").css("opacity", "0");
$("#czone").css("opacity", "0");
$("#czone").css("overflow","hidden");



$("#contact input[type=text]").focus(function(){
	$("p.no-spam input[type=text]").val('17');	
});


var address = 'me' + '@' + 'dominic' + 'whittle' + '.com';
var mail = '<a href="' + 'mailto:' + address + '">' + address + '</a>';
$(".mail-link").html(mail);








// BEGIN GALLERY CODE
// -----------------------------------------------------------------------------------------------

// SETUP - First positions please!


// z-index levels
var z_top     = 99; // Top (used in transition)
var z_current = 98; // The displayed image
var z_initial = 97; // Initial z-index value

var gallery = "#gallery";

var current_img_class = "current_image";

$("#gallery .img").css("z-index", z_initial);
$("#img-1").addClass(current_img_class).css("z-index", z_current);

$(".gallery_navigation_button").css("opacity", '0.6');
$(".navigation_button").css("cursor", "pointer");

$(gallery).append('<div id="loading"></div>');
$('#loading').css("z-index", z_current);

// END SETUP




// NAV BTNS HOVERS
$('.gallery_navigation_button').hover(function() {
	$(this).stop().animate({ opacity: '1' }, 75, "swing");
} , function() {
	$(this).stop().animate({ opacity: '0.6' }, 200, "swing");
});



// NEXT & PREV CLICK
var total = $("#img_count").html();
$('.navigation_button').click(function(){
    var current = $('.'+current_img_class).attr('rel');
    
    var this_button = $(this).attr("id");
    //alert(this_button);
    
    if (this_button == "prev_btn"){
    	var btn = "prev_btn";
    	var num = ((current * 1) - 1 );
    	var img = '#img-' + ((current * 1) - 1 );
    	var img_before = '#img-' + ((current * 1) - 2 );
    	if ( ($(img).length > 0 ) == false ) { img = '#img-' + total; num = total; };
   	} else {
		var btn = "next_btn";
    	var num = ((current * 1) + 1 );
	    var img = '#img-' + ((current * 1) + 1 );
	    var img_after = '#img-' + ((current * 1) + 2 );
	    if ( ($(img).length > 0) == false ) { img = '#img-1'; num = '1'; };
    }
    
	if ( $(img).hasClass("current_image") == false ) {
	    // let's show the target
		$(img).css({"opacity" : "0", "z-index" : z_top});
        $(img).animate({ opacity: '1'}, 400, "linear", function() { // target image now visible
        	$('#img_number').html(num);
	    	$('.'+current_img_class).css("z-index", z_initial);
	    	$('.'+current_img_class).removeClass(current_img_class);
			$(img).addClass(current_img_class).css("z-index", z_current);
    	});
    	
		var img_after = '';
		var img_before = '';
    }
});


}); // ready(function) end





// REMOVE LOADING IMAGE when images are ready.
jQuery(window).bind("load", function() {
	jQuery("#c_top").animate({ opacity: '1' }, 300, "swing", function(){
		jQuery("#c_bot").animate({ opacity: '1' }, 300, "swing", function(){
			jQuery("#c_bot_shadow").animate({ opacity: '1' }, 300, "swing");
			jQuery("#czone").animate({ opacity: '1' }, 300, "swing");
			jQuery("#c_close").animate({ opacity: '1' }, 300, "swing");
		});		
	});
	
	jQuery("#loading").animate({ opacity: '0' }, 800, "swing", function(){
		jQuery("#loading").css("z-index", "96").css("background", "none");
	});

}); //end
