$(document).ready(function(){ 
	//INITIALISE IE6 PNG HANDLING
	$(document).pngFix();
	$('.hide').hide();
	
	// HACK MUSIC
	$('#nav_music').click(function(event) {
		event.preventDefault();
		window.open('http://www.chassispants.com');
	});
	
	// MAIN NAVIGATION CODE
	$(".nav_link").each(function(index) {
		var n = index + 1;
		var t = $(this).attr('alt');
		$(this).html('<span class="normal">' + n + '</span>');
		$(this).append('<span class="over">' + t + '</span>');
	});
	
	$('.over').hide();
	
	//NAVIGATION TEXT SWAP ON ROLLOVER
	$(".nav_link").bind("mouseenter",function(){
		$('.normal',this).hide();
		$('.over',this).show();
    }).bind("mouseleave",function(){
		var n = $(this).attr('rel');
		var o = $('.normal',this);
		$('.over',this).fadeOut(200, function () {
			o.show();
		});
	});
	
	//LOGO ROLLOVER
	$("#logo").bind("mouseenter",function(){
		$("#logo").attr({"src" : "http://www.maggiegodwin.com/img/logo2.gif"});
    }).bind("mouseleave",function(){
		$("#logo").attr({"src" : "http://www.maggiegodwin.com/img/logo.gif"});
		$("#logo").css({'display' : 'none'});
		$("#logo").fadeIn(200);
	});

	//SUB NAV
	$("#prev_item").bind("mouseenter",function(){
			$("#prev_item_img").attr({"src" : "http://www.maggiegodwin.com/img/prev.gif"});
		}).bind("mouseleave",function(){
			$("#prev_item_img").attr({"src" : "http://www.maggiegodwin.com/img/dot.gif"});
	});
	
	$("#next_item").bind("mouseenter",function(){
			$("#next_item_img").attr({"src" : "http://www.maggiegodwin.com/img/next.gif"});
		}).bind("mouseleave",function(){
			$("#next_item_img").attr({"src" : "http://www.maggiegodwin.com/img/dot.gif"});
	});
	
	//COPYRIGHT ROLLOVER
	var copyright = $("#footer .hide");
	
	$("#footer").bind("mouseenter",function(){
		$(this).children().hide();
		$(copyright).show();
    }).bind("mouseleave",function(){
		$(this).children().fadeIn(200);
		$(copyright).hide();
	});
	
	//Lightbox rollover
	var alt;
	var hlink;
	$('.thumb').bind("mouseenter",function(){
		alt = $('.lightbox_image', this).attr('alt');
		// insert new html element with alt tag at text inside
		$('a', this).append('<p class="thumb_over">' + alt + '</>');
		var outerh = $(this).height();
		var innerh = $('.thumb_over', this).height();
		var top = (outerh - innerh) / 2;
		top = Math.round(top);
		$('.thumb_over').css('margin-top', top);
		$('.lightbox_image', this).hide();
	}).bind("mouseleave",function(){
		$('.thumb_over').detach();
		$('.lightbox_image', this).fadeIn(200, function () {
		});
		
	});	
	
});

function verticalCentering() {
	var h = $('.V').height();
	var img_h = $('.V img').height();
	if (img_h < h) {
		var nh = Math.round((h - img_h)/2);
		$('.V').css('padding-top',nh);
	}
}
