$(document).ready(function(){

// alert("alive");

// -Current-

switchDelay = 100;
fadeDuration = 450;
fromNovMenu = 0;
fromShoMenu = 0;
hovTextArr = ['#hov_nl_sho','#hov_nl_bio','#hov_nl_con','#hov_nl_lin','#hov_nl_blo','#hov_nl_nov'];
	
// Hide elements.

	// $(".ulFNB").hide();


// Home link in header

	// THANKS TO http://weblog.intunet.co.uk/blog-article/jquery-tutorial/
	$('.dTI,#dH').hover(function() {
		$(this).css('cursor','pointer');
	}, function() {	
		$(this).css('cursor','auto');
	});

	$(".dTI,#dH").click(function(){
		
		window.location = "index.php";

	});

// Click event bubble-propagation test
/*
	$("*", document.body).click(function(){
				
		theid = $(this).attr("id");
		theclass = $(this).attr("class");
		alert("The id of this element is " + theid + " and the class: "+ theclass);	

	});
*/

// Reset all by clicking main img 

	$("#dMI").click(function(){
		
		// alert("getting it");
		resetAll();

	});


// Link click on images

	$(".dHovNL").click(function(){
	
		// alert("yep");
		url = $(this).children("a.aHovNL").attr("href");
		// $(this).children("a.aHovNL").hide();
		window.location = url;

	});



// Main link hover effects

$("#nl_lin,#nl_blo,#nl_con,#nl_bio,#nl_nov,#nl_sho").hover(function(){

		// Hover over
		

		// 0. Get hooks for all things
	
		theText = "#hov_" + $(this).attr("id");
		if ( theText == "#hov_nl_nov" || theText == "#hov_nl_sho" ) {		

			// alert("Its a menu");

			theMenu = theText.replace("hov_nl_", "m_");
			theBackground = theMenu + "_bk";
			
			// alert(theBackground);
		
		}

		// 1. Make things disappear

			// cycle through all icons except this one, hide them

		for ( i=0; i<=hovTextArr.length; i++ )
		{
			if (hovTextArr[i] != theText) {
				
				// alert(hovTextArr[i]);
				$(hovTextArr[i]).hide();

				t = hovTextArr[i];

				// If icons have associated menus, hide them, except if this one				

				if (t == "#hov_nl_sho") 
				{
					// alert("Hiding shorts");
					$("#m_sho, #m_sho_bk").hide();	
				}

				if (t == "#hov_nl_nov") 
				{
					// alert("Hiding novs");
					$("#m_nov, #m_nov_bk").hide();	
				}
			}
		}


		// 2. Make things appear
	
		$(theText).fadeIn(fadeDuration);

		if ( theText == "#hov_nl_nov" || theText == "#hov_nl_sho" ) {			

			$(theMenu).fadeIn(fadeDuration);
			$(theBackground).css('filter', 'alpha(opacity=60)'); // For IE, bless it.
			$(theBackground).fadeIn(fadeDuration);

		}

		



	},
	function(){

		// resetTimer = setTimeout ( "resetAll()", switchDelay );

	});


// Red text on hover images (multiple)

	
// Blanket hyperlink function to avoid errors caused by hovering straight onto text from image. Long story, no time!

hc = "#cc2211";
lc = "#333333";

	$("a").hover(function(){

		// Hover over

			$(this).css("color",hc);
		
	},
	function(){

		// Hover out

			$(this).css("color", lc);

	});


// Nav images 

	$(".aNavImgLinkup").hover(function(){

		// Hover over

			$(this).next().children("a").css("color", hc);
		
	},
	function(){

		// Hover out

			$(this).next().children("a").css("color", lc);

	});


// Links page images 
	

	$(".aLinksImgLinkup").hover(function(){

		// Hover over

			$(this).parent().next().children("a").css("color", hc);
		
	},
	function(){

		// Hover out

			$(this).parent().next().children("a").css("color", lc);

	});

// Submit and clear buttons 


	$(".iButton").hover(function(){

		// Hover over

			$(this).next().children("a").css("color", hc);
		
	},
	function(){

		// Hover out

			$(this).next().children("a").css("color", lc);

	});

	$(".afButton").hover(function(){

		// Hover over

			$(this).parent().next().children("a").css("color", hc);
		
	},
	function(){

		// Hover out

			$(this).parent().next().children("a").css("color", lc);

	});

// Contact form field clear on focus

	$(".inF").focus(function(){
		
		text = $(this).val();

		if ( text == "Your name goes here" || text == "you@yourdomain.yoursuffix" || text == "Please type your message here" )
		{
			$(this).val('');
		}
	});



// Submit and clear text function

	$("#aSub").click(function(){

		// alert("Caught");
		$("form").submit();
		return false;

	});

	$("#aClr,#imgClear").click(function(){

		// alert("Caught");
		// $("form").css({background:"yellow", border:"3px red solid"});
		$("form input, form textarea").val('');
		return false;

	});


// Imperial Cartographae refresh

	$("#dImperialCartographaeRefresh").hover(function(){

		$(this).css('cursor','pointer');

	}, function() {	

		$(this).css('cursor','auto');

	});


	$("#dMoL,#dImperialCartographaeRefresh").click(function(){

		location.reload();			
	});

	

	// Contact Dimitri

	once = false;
	
	$("#hiddenEmail").click(function(){

		if (!once) {
			$("#showEmailWhenClick").before("<p><b>Dimitri can be contacted on:</b></p>")
						.css({ 
							width:"221px",
							height:"22px" 
						})
						.css("background-image", "url(images/template/dp.png)")
						.after("<br>")
						.fadeIn(5000);
			once = true;
		}

		return false;

      	}, function(){

      			
	});

}); // Document ready function



function resetAll() {

	for ( i=0; i<=hovTextArr.length; i++ )
	{
				
		// alert(hovTextArr[i]);
		$(hovTextArr[i]).hide();

		t = hovTextArr[i];

		// If icons have associated menus, hide them, except if this one				

		if (t == "#hov_nl_sho") 
		{
			// alert("Hiding shorts");
			$("#m_sho, #m_sho_bk").hide();	
		}

		if (t == "#hov_nl_nov") 
		{
			// alert("Hiding novs");
			$("#m_nov, #m_nov_bk").hide();	
		}
	}

}
