


$(document).ready( function() {

	// Scrolling background
	// 2011-03-23 appears IE7 runs it faster than IE8 !
	// 2011-03-19 made to sroll horizontal, not vertical
	// height of background image in pixels
	var img1width = 1234;
	var img2width = 1795;
	var offset = 0; var offset2 = 0;
	var speed  = 0.4; var speed2 = 1;
	if( typeof IE_FOUND != 'undefined' ) {  var speed = 1; var speed2 = 5; } // 
	
	// DEBUG var test = typeof IE_FOUND;
	// DEBUG $('body').append(' '+speed+' <br>'+speed2+'<br>'+test);
	
	// get the current minute/hour of the day
	var now = new Date();
	var hour = now.getHours();
	var minute = now.getMinutes();
	var second = now.getSeconds();
	
	// work out how far through the day we are as a percentage - e.g. 6pm = 75%
	// var hourpercent = hour / 24 * 100;
	// var minutepercent = minute / 60 / 24 * 100;
	// var percentofday = Math.round(hourpercent + minutepercent);
	// calculate which pixel row to start graphic from based on how far through the day we are
 	// var offset = img1width / 100 * percentofday;
	// graphic starts at approx 6am, so adjust offset by 1/4
	// var offset = offset - (img1width / 4);

	function where_in_hour() {
		var now = new Date();
		var hour = now.getHours();
		var minute = now.getMinutes();
		var second = now.getSeconds();
		var ms = now.getMilliseconds();
		// now.getTime() returns the number of milliseconds since 01.01.1970.
		// var minutepercent = minute / 60 / 24 * 100;
	
		// total milliseconds point in hour
		var total = (minute * 60) * 1000;
		total = total + (second * 1000);
		total = total + ms;
	
		return total;
	}



	function scrollbackground() {

		// decrease the offset by 1, or if its less than 1 increase it by the background height minus 1
   		offset = (offset < 1) ? offset + (img1width - speed) : offset - speed;
		pos = Math.round(offset);
		// apply the background position
   		$('#header').css("background-position", " " + pos + "px 78px"  ); //+ " 55px"
		//$('#debug').html( "time:"+where_in_hour() + " offset:" + pos + "px" );
   		// call self to continue animation
   		setTimeout(function() {
			scrollbackground();
			}, 0
		);

   	}

	function scrollbackgroundBody() {

		// decrease the offset by 1, or if its less than 1 increase it by the background height minus 1
   		offset2 = (offset2 < 1) ? offset2 + (img2width - speed2) : offset2 - speed2;
		pos = Math.round(offset2);
		// apply the background position
   		$('#experiment').css("background-position", " " + pos + "px " + "55px"  ); //65px

   		// call self to continue animation
   		setTimeout(function() {
			scrollbackgroundBody();
			}, 0
		);

   	}

    
	// Start the animation
	scrollbackground();


scrollbackgroundBody();





	
	
	// ***
	// Fully clickable divs
	// ***
	
/*	$("div.clickable").click(
	function()
	{
	    window.location = $("a", this).attr("href");
	    return false;
	});*/

	// ***
	// Leading image expander
	// ***

/*	$('.leading').hover(
		function() {
			if ($('img', this).height() > 300) {
				$(this).animate({
					height: $('img', this).height()
				}, 300, 'swing');
			}
		},
		function() {
			$(this).animate({
				height: "300px"
			}, 200);
		}	
	);	*/

    
/*	var validationdelay = delaytimer();
	
	$('#contact-name, #contact-email, #contact-comments').bind('keyup', function() {
		validationdelay(validatecontact, 500);
	});*/
	
/*	validatecontact();*/
	
/*	$('#contact-form').bind('submit', function() {
		var valid = validatecontact(); 
		if (!valid) {
			if (!validname) {
				alert('Please enter your name.');
				return false;
			}
			if (!validemail) {
				alert('Please enter a valid email address.');
				return false;
			}
			if (!validcomments) {
				alert('Please enter some comments.');
				return false;
			}
		}
	})*/
	
	// light_rounded / dark_rounded / light_square / dark_square
	
/*	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'dark_rounded' 
	});
			
	$('#foliothumbs').cycle();
*/
	
});   /* END DOCUMENT READY */



/*var blank = new Image();
blank.src = '/img/blank.gif';

$(document).ready(function() {
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
	 // get all pngs on page
	 $('img[src$=.png]').each(function() {
	   if (!this.complete) {
	     this.onload = function() { fixPng(this) };
	   } else {
	     fixPng(this);
	   }
	 });
	}
});*/

/*function fixPng(png) {
	// get src
	var src = png.src;
	// set width and height
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	// replace by blank image
	png.onload = function() { };
	png.src = blank.src;
	// set filter (display original image)
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}*/
	
