$(function() {

	// alert("wtf");

	// wipe text ifJavascriptDisabled = false i.e. if this runs
		$("#ifJavascriptDisabled").hide();

	// On tin:
	centerAlignContent();

	// align on resize
	$(window).resize(function() {
					// alert("good");
		 			centerAlignContent();
	});
	
	// Slow blink-in
	var x=300;
	$(".effSlowBlink, .imgFilmStrip, .imgGallery").hide();
	$(".effSlowBlink, .imgFilmStrip, .imgGallery").fadeIn(1000);
	
	// Slow blink onhover gallery-type images 
	$(".effSlowBlink, .imgFilmStrip, .imgGallery").mouseover(function() { 
									$(this).fadeOut(x, function() {
														$(this).fadeIn(x);
																  });
	});	

/*
// Jquery lightbox activation
	$(".aGallery").lightBox();

// Hide huge ones
	$(".imgHugeGallery").hide();
	$(".aHugeGallery").lightBox();
*/

// Hover red over caption link
	$(".aGallery").hover(
		function() {
			// Hover on
				$(this).children(".pGalleryCaption").addClass("textRed");
		},
		function() {
			// Hover off
				$(this).children(".pGalleryCaption").removeClass("textRed");
		}
	);

// Hover red text over transparent images
	$(".aImageTransparent").hover(
		function() {
			// mouseover
			$(this).parent().next().next().children(".aButtonText:first").addClass("textRed"); // find out how to add pseudoclass, then uncomment a:link and a:visited decls in cssBasics - without which the current code doesnt work.		
		}, 
		function(){
			// mouseoff
			$(this).parent().next().next().children(".aButtonText:first").removeClass("textRed");
	});


// Grey out background
	$(".divContentBoundary").append("<div class=\"opaqueBackground\"></div>");
	var h = $(".divContentBoundary").css("height");
	var w = $(".divContentBoundary").css("width");	

	$(".opaqueBackground").css("height", h);
	$(".opaqueBackground").css("width", w);

// Activate development feedback functionality
	$(".underConstruction, .opaqueBackground").show();

// Hide the message box
	$(".ucHideShow, .ucClose").click(function(){	
		$(".underConstruction, .opaqueBackground").hide();
	});

// Hover colour change on uc box close button
	$(".ucClose").hover(function(){
		// mouseover
			$(this).children().children("a.ucHideShow").css({color:"#999999"}).children(".spSubMessage").css({color:"#999999"}); // quick and dirty!! the shame....
			
	},function(){
		// mouseoff
			$(this).children().children("a.ucHideShow").css({color:"#666666"}).children(".spSubMessage").css({color:"#666666"});
	});

// "Download currently unavailable" functionality
	$(".aDownload").click(function(){
		// position box - giving up for the moment. Using page-specific CSS sheets.
			// get Download position 
			// var div = $(".divDownload");
			
			//	var divW = div.offsetWidth;
			//	var divH = div.offsetHeight;	

			// alert("divW - "+divW+",  divH - "+divH);
			// cuT = divH;
			// alert(cuT);
 			// $(".divCurrentlyUnavailable").css("top", cuT);

		// if link 
			url = this.href;
		// ..ends in #	
			if (url.indexOf("#") != "-1") {
				// display box
				$(".divCurrentlyUnavailable").fadeIn(1000);
			}

		// disable link
			return false;	
	});

	$(".aCurrentlyUnavailable").click(function(){
		// if link 
			url = this.href;
		// ..ends in #	
			if (url.indexOf("#") != "-1") {
				// close box
				$(".divCurrentlyUnavailable").fadeOut(1000);
			}
		//
			else {
				// follow hyperlink
				window.location = url;
			}

		// disable link
			return false;	
	});

}); // document ready function

function centerAlignContent() {
		
	// Set the Div
	var div = getElem("divContentBoundary");
	
	// Get screen dimensions
	// ppk I love you http://www.quirksmode.org/js/doctypes.html
	// For standards compatibility mode doctype (even though mine is in transitional):
	// Separate IE 6...
	if (document.documentElement && document.documentElement.clientHeight) {
		clientH = document.documentElement.clientHeight;	
	}
	// ...from IE 5....
	else if (document.body) {
		clientH = document.body.clientHeight;
	}
	// ... and finally from everyone else (I dont care that its the same as above - its the principle)
	else {
		clientH = document.body.clientHeight;
	}	
	
	// Same again for width
	if (document.documentElement && document.documentElement.clientWidth) {
		clientW = document.documentElement.clientWidth;	
	}
	else if (document.body) {
		clientW = document.body.clientWidth;
	}
	else {
		clientW = document.body.clientWidth;
	}

	// Get div dimensions
	var divW = div.offsetWidth;

	// Calculate "Left"
	var divLeft = (clientW/2) - (divW/2);
	
	// Assign if screen clientW > Somepx - define?
	var somePx = 800;
	if (clientW > somePx) {
//			$("#divContentBoundary, .divBackground").css("left", divLeft);
			$(".divBackground").css("left", divLeft);
			$("#divContentBoundary").css("left", divLeft);
	}
	
	// alert("clientW = "+clientW+"");
	// alert("divW = "+divW+"");
	// alert("divLeft = "+divLeft+"");
}

function getElem(el) {
  var elem = document.getElementById(el);
  return elem;
}


function makedraggable() {
	if ($(".divposTopLogo, .divposNavBar").Draggable) {
		// $(".divposTopLogo, .divposNavBar").addClass("tempGreyBackground");
		$(".divposTopLogo, .divposNavBar").Draggable (	
			{
				zIndex: 2000,
				opacity: 0.7
			}
		);
	}
}