$(function(){

	// ***
	// Scrolling background
	// ***
		
	// height of background image in pixels
	var backgroundheight = 4000;
	
	// get the current minute/hour of the day
	var now = new Date();
	var hour = now.getHours();
	var minute = now.getMinutes();
	
	// 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 rand = Math.random() * 999;
	//var rand2 = Math.random() * 4;
	//if (rand2>=0 && rand2<1) var percentofday = Math.round(hourpercent + minutepercent + rand);
	//else if (rand2>=1 && rand2<2) var percentofday = Math.round(hourpercent + minutepercent / rand);
	//else if (rand2>=2 && rand2<3) var percentofday = Math.round(hourpercent + minutepercent * rand);
	//else if (rand2>=3 && rand2<4) var percentofday = Math.round(hourpercent + minutepercent - rand);
	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 = backgroundheight / 100 * percentofday;

	// graphic starts at approx 6am, so adjust offset by 1/4
	var offset = offset - (backgroundheight / 4);

	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 + (backgroundheight - 1) : offset - 1;
		// apply the background position
   		$('body').css("background-position", "50% " + offset + "px");
   		// call self to continue animation
   		setTimeout(function() {
			scrollbackground();
			}, 1
		);
   	}
    
	// Start the animation
	scrollbackground();
	
	
	// ***
	// 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 blank = new Image();
blank.src = '/template/theme/youloveus/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')";
}
*/


jQuery(function() {
		// show a simple loading indicator
		var loader = jQuery('<div id="loader"><img src="images/loading.gif" alt="loading..." /></div>')
			.css({position: "absolute", top: "0", left: "0"})
			.appendTo("body")
			.hide();
		jQuery().ajaxStart(function() {
			loader.show();
		}).ajaxStop(function() {
			loader.hide();
		}).ajaxError(function(a, b, e) {
			throw e;
		});
		
		

		
  
		
		jQuery("#reset").click(function() {
			v.resetForm();
		});
	});

$(document).ready(function() {
						   
	$("#nav_sub_desp").stop().css('height','0')
	$("#nav_sub_desp").stop().hide();



	
	
	/*$("#services_b").hover(function () {
	$("#nav_sub1").animate( { height:"125px" }, { queue:false, duration:500 } )
	},
	function () {
			$("#nav_sub1").animate( { height:"0" }, { queue: false, duration:500 } )
	});*/
	
	

	$('#nav li:has(ul)').hover(
	//$('.nav_el').hover(
							   
		function(e)
		{
			//$("#nav_sub1").show();
			$("#nav_sub_desp").stop().animate( { height:"180px" }, { queue:false, duration:500 } )
			$(this).find('ul').stop().animate( { height:"180px" }, { queue:false, duration:500 } )
		},
		function(e)
		{
			//$(this).find('ul').stop().animate( { height:"0px" }, { queue:false, duration:500 } )
			$(this).find('ul').stop().css('height','0')
			$(this).find('ul').stop().hide();
			$("#nav_sub_desp").stop().animate( { height:"0px" }, { queue:false, duration:500 } )
		}
		
		
	);
	
  	
});

	


	
	
