
refer = ""+escape(document.referrer);
//alert(refer)
timer = 0;
loadLayer = 1;
loadIn = 1;
priorOverlayPage = "";

var preLoad = new Image();
//preLoad.src = "/images/fuel-gauge3.png";
preLoad.src = "/images/contentBackground3.png";

var afterLoad = new Array('/images/car3.png',
'/images/map-pt2.png',
'/images/the_cables_best_pic-small.jpg',
'/images/guest-lounge-small.jpg'
);


//page = event.parameters.page ? '/?page=' + event.parameters.page : event.path;
page = document.location.hash;
if(page == "") page = document.location.pathname;
//alert(page)

$(document).ready(function()
{
$('#bookingFormButton').click(function()
{
    window.location.href = "#/booking-form.php";
})

$('#driverHealthButton').click(function()
{
    window.location.href = "#/driver-health-check.php";
})

$('#contactUsButton').click(function()
{
    window.location.href = "#/contact-us.php";
})

$('#linksToButton').click(function()
{
    window.location.href = "#/links-to-help.php";
})

$('#bookingFormButton div').hover(function()
{
    $('#bookingFormButton').css({'background-position': '0px 0px'}).addClass('cursor');
   // window.location.href = "#/contact-us.php";
}
,function()
{
    $('#bookingFormButton').css({'background-position': '0px -70px'}).removeClass('cursor');
});


$('#driverHealthButton div').hover(function()
{
    $('#driverHealthButton').css({'background-position': '-246px 0px'}).addClass('cursor');
   // window.location.href = "#/contact-us.php";
}
,function()
{
    $('#driverHealthButton').css({'background-position': '-246px -70px'}).removeClass('cursor');
});

$('#contactUsButton div').hover(function()
{
    $('#contactUsButton').css({'background-position': '-492px 0px'}).addClass('cursor');
   // window.location.href = "#/contact-us.php";
}
,function()
{
    $('#contactUsButton').css({'background-position': '-492px -70px'}).removeClass('cursor');
});

$('#linksToButton div').hover(function()
{
    $('#linksToButton').css({'background-position': '-738px 0px'}).addClass('cursor');
   // window.location.href = "#/contact-us.php";
}
,function()
{
    $('#linksToButton').css({'background-position': '-738px -70px'}).removeClass('cursor');
});



    window.$my =
    {
	// Initialize all the queries you want to use more than once
	overlay : $('#overlay'),
	content : $('#content'),
	contentCar : $('#contentCar'),
	main : $('#main'),
	fuelGauge : $('#fuelGauge'),
	navigationA : $('#navigation a')
    };

	$my.overlay.fadeTo(0, 0.97);
	$my.content.hide();
	$my.contentCar.hide();

	$("#areaLocator").click(function()
	{
	     s="na";c="na";j="na";
		var p = "" +escape("http://www.driving-test-doctors.co.uk/area-locator.php");
		var t=""+escape(document.title)
		s=screen.width;v=navigator.appName
		if (v != "Netscape") {c=screen.colorDepth}
		else {c=screen.pixelDepth}
		j=navigator.javaEnabled()

		NS2Ch=0
		if (navigator.appName == "Netscape" &&
		navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
		if (NS2Ch == 0)
		{
		    //var timeStamp = Math.round(new Date().getTime() / 1000);
		    var timeStamp = Number(new Date());
		    r="?vrefer="+refer+"&vurl="+p+"&vcolours="+c+"&vsize="+s+"&siteID=drivingdoctors&title=" + t + "&pr=" + timeStamp;
		    var myImage = new Image(1,1)
		    myImage.src = "/getmysiteseen.php" + r
		    refer = p;
		}
		_gaq.push(['_trackPageview', '/area-locator.php']);

	    $.ajax(
	    {
		url: "/ajax/area-locator.php",
		cache: false,
		error: function()
		{
		    alert("Connection lost. Please check your internet connection and try again.");
		},
		success: function(html)
		{
		    var height = $('#contentText').height() + 80;
		    $('#areaLocatorOverlay').html(html);
		    $('#contentAL').css({"height": height});
		    $('#areaLocatorOverlay').fadeTo('fast', 0.975);
		}
	    })
	})


	$("#ballPDF").click(function()
	{
	    s="na";c="na";j="na";
	    var p = "" +escape("http://www.driving-test-doctors.co.uk/index-page-pdf.php");
	    var t=""+escape(document.title)
	    s=screen.width;v=navigator.appName
	    if (v != "Netscape") {c=screen.colorDepth}
	    else {c=screen.pixelDepth}
	    j=navigator.javaEnabled()

	    NS2Ch=0
	    if (navigator.appName == "Netscape" &&
	    navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
	    if (NS2Ch == 0)
	    {
		var timeStamp = Number(new Date());
		r="?vrefer="+refer+"&vurl="+p+"&vcolours="+c+"&vsize="+s+"&siteID=drivingdoctors&title=Index-Page-PDF" + "&pr=" + timeStamp;;
		var myImage = new Image(1,1)
		myImage.src = "/getmysiteseen.php" + r
		refer = p;
	    }
	    _gaq.push(['_trackPageview', '/index-page-pdf.php']);
	})


	$("#pricesPDF").live('click', function(event)
	{
	    s="na";c="na";j="na";
	    var p = "" +escape("http://www.driving-test-doctors.co.uk/prices-pdf.php");
	    var t=""+escape(document.title)
	    s=screen.width;v=navigator.appName
	    if (v != "Netscape") {c=screen.colorDepth}
	    else {c=screen.pixelDepth}
	    j=navigator.javaEnabled()

	    NS2Ch=0
	    if (navigator.appName == "Netscape" &&
	    navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
	    if (NS2Ch == 0)
	    {
		var timeStamp = Number(new Date());
		r="?vrefer="+refer+"&vurl="+p+"&vcolours="+c+"&vsize="+s+"&siteID=drivingdoctors&title=Prices-PDF" + "&pr=" + timeStamp;
		var myImage = new Image(1,1)
		myImage.src = "/getmysiteseen.php" + r
		refer = p;
	    }
	    _gaq.push(['_trackPageview', '/prices-pdf.php']);
	})

	



	$('#areaLocatorOverlay').click(function()
	{
	    $('#areaLocatorOverlay').fadeTo('fast',0, function(){
		$('#areaLocatorOverlay').hide();

	
	    });
	})


	$.fn.repeat = function(speed, time)
	{
	  var $this = $(this);
	    $this.fadeTo(speed,0.01);
	    timer = setInterval(function()
	    {
		$this.fadeTo(speed,0.7, function(){$this.fadeTo(speed,0.01);});
	    }, time*1000);
	};

/*
// when the DOM is ready
$(function () {
  var img = new Image();
  //$('#fuelGaugeNeedleDiv').css('left','-1000px');
  $('#fuelGaugeNeedle').rotate({'angle' : 1, 'preservePosition' : '1'});
  //$('#fuelGaugeNeedle').hide();
  // wrap our new image in jQuery, then:
  $(img)
    // once the image has loaded, execute this code
    .load(function () {
      // set the image hidden by default
      $(this).hide();
      // with the holding div #loader, apply:
      $my.fuelGauge
        // then insert our image
        .append(this);

      // fade our image in to create a nice effect
		$(this).show(1, function()
		{
		    $('#fuelGaugeNeedleDiv').css('top','34px');
			
			    
			$('#fuelGaugeNeedle').delay(200).show(250, function()
			{
				
				var angle = 0;
				interval = (showLoadLayer) ? 45 : 1;

				loadingTimer = setInterval(function()
				{
					angle+=3;
					if(angle > 300 && angle < 310) alert("Still running");
					//$('#fuelGaugeNeedle').css({'opacity' : '0'});
					if(angle >= 129)
					{
						clearInterval(loadingTimer);
						$my.overlay.fadeTo(200, 0, function ()
						{
							$my.overlay.hide();
							$my.fuelGauge.hide();
						});
*/
    
						moretext(page);
						loadLayer = 0;

						// Load in other images
						for(var i in afterLoad)
						{
						    $.ajax(
						    {
							url: afterLoad[i],
							cache: true
						    })
						}
/*

					}
					//$('#fuelGaugeNeedle').animate({'rotate': angle });
					$('#fuelGaugeNeedle').rotate({'angle' : angle, 'preservePosition' : '1'});
					p = Math.round(angle / 129 * 100);
					$('#barGraph').css('width', p);
					$('#percentCounter').html(p);


					
				}, interval);
			});
	    })
	})
    // if there was an error loading the image, react accordingly
    .error(function () {
      // notify the user that the image could not be loaded
    })

    // *finally*, set the src attribute of the new image to our image
    .attr('src', '/images/fuel-gauge4.png');


});
*/


$.address.init(function(event)
{
    // Initializes plugin support for links
    $('a:not([href^=http])').address();
    //$('a').address();

    // Adds a simple hover effect
    $('a').hover(function()
    {
	buttonID = $(this).attr('id');
	imgID = buttonID.replace("_link", "");
	var fade = "#" + imgID;

	if(imgID)
	{
	    // if the element is currently being animated (to a fadeOut)...
	    if($(fade).is(":animated"))
	    {
		// ...take it's current opacity back up to 1
		 $(fade).stop();
		 $(fade).fadeTo(250, 1);
	    }
	    else
	    {
		// fade in quickly
		 $(fade).css({'opacity': '1'});
	    }
	}
    }
    ,function()
    {
	var currentPage = "";
	var theAddress = decodeURI(window.location);
	var currentAnchor = theAddress.indexOf("#");
	if (currentAnchor >= 0)
	{
	    currentPage = theAddress.substring(currentAnchor);
	}
	else
	{
	    currentPage = "#" + decodeURI(window.location.pathname);
	    if(currentPage == "#") currentPage = "#/index.php";
	    //currentPage = currentPage.replace(".php","")
	}

	buttonID = $(this).attr('id');
	imgID = buttonID.replace("_link", "");
	var fade = "#" + imgID;
	thisPage = "#" + $(this).attr('href');
	//thisPage = thisPage.replace(".php","")
	if(imgID)
	{
	    if($(fade).is(':animated'))
	    {
		$(fade).stop();
		$(fade).fadeTo(250, 0);
	    }
	    else
	    {
		// fade away slowly
		$(fade).css({'opacity': '0'});
	    }
	}

	mainDiv = fade + "_main";
	if(currentPage == thisPage)
	{
	    $(mainDiv).animate({'left': '0px'}, {duration: 1000});
	}
	else
	{
	    $(mainDiv).animate({'left': '10px'}, {duration: 1000});
	}
    }
);
})
.change(function(event)
{
    // Identifies the page selection
    page = event.parameters.page ? '/?page=' + event.parameters.page : event.path;

    var loadAjaxPage = 1;
    // Loads the page content and inserts it into the content area
    if(page == "/")
    {
	var theAddress = decodeURI(window.location.pathname);
	page = theAddress;
	//page = page.replace(".php","")

	// Don't reload this page
	loadAjaxPage = 0;

	$my.navigationA.each(function()
	{
	    buttonID = $(this).attr('id');
	    imgID = buttonID.replace("_link", "");
	    var mainDiv = "#" + imgID + "_main";
	    var roundaboutDiv = "#" + imgID;
	    var stopDiv = "#" + imgID + "Stop";

	    if($(this).attr('href') == ( page))
	    {
		$(mainDiv).css({'left': '0px'});
		$(stopDiv).delay(150).animate({'opacity': '1'}, {duration: 500});
	    }
	    else
	    {
		$(roundaboutDiv).css({'opacity': '0'});
		$(stopDiv).css({'opacity': '0'});
	    }
	});
    }

    // Only do the following if an AJAX request is required
    if(loadAjaxPage)
    {
	// Disable all links until the new page has loaded in
	$("#cover").fadeTo(0, 0.01).show();
	jQuery(window).scrollTop(0)
	loadAjaxPageFunc();
    }
});










	
	// prepare the form when the DOM is ready
	var options = {
		url: "/ajax/thank-you-process.php",
		type: "post",
		success:       showResponse  // post-submit callback

	};

	// bind form using 'ajaxForm'
	$('#submit-button').live('click',function(event){
	    event.preventDefault();

	    // Change the button to a spinner
	    jQuery('#submitButtonLayer').html("<img src='/images/ajax-loader.gif'>");
	    
	     var randomNum = Math.round(new Date().getTime() / 1000);
	    jQuery.ajax(
	    {
		type: "POST",
		async: true,
		url: "/ajax/thank-you-process.php?sid=" + randomNum,
		data: jQuery("form").serialize(),
		success: function(html)
		{
		    if(html == 0)
		    {
			    window.location.href = "#/thank-you.php";
		    }
		    else
		    {
			    alert(html);
			    // Change spinner back to button
			    jQuery('#submitButtonLayer').html("<input type='submit' name='submit-button' id='submit-button' value='Send'>");
		    }
		}
	    })
	});


	$('#bookingFormSubmit').live('click', function(event)
	{
	    // Submit data via AJAX
	    event.preventDefault();

	    // Change the button to a spinner
	    jQuery('#submitButtonLayer').html("<img src='/images/ajax-loader.gif'>");

	    var randomNum = Math.round(new Date().getTime() / 1000);
	    jQuery.ajax(
	    {
		type: "POST",
		async: true,
		url: "/ajax/booking-form-process.php?sid=" + randomNum,
		data: jQuery("form").serialize(),
		success: function(html)
		{

		    if(!isNaN(parseFloat(html)))
		    {
			$('#invoice').val(html);
			$('#bookingForm').submit();
			return false;
		    }
		    else
		    {
			alert(html)
			 // Change spinner back to button
			 jQuery('#submitButtonLayer').html("<input type='submit' name='submit-button' id='bookingFormSubmit' value='Proceed'>");
			return false;
		    }
		},
		error: function()
		{
		    alert("ERROR");
		    return false;
		}
	    })
	 });
});


// post-submit callback
function showResponse(responseText, statusText, xhr, $form)
{
	if(responseText == 0)
	{
		window.location.href = "#/thank-you.php";
	}
	else
	{
		alert(responseText);
	}
}






$(document).ready(function()
{
    $("body").delegate(".signPost","click", (function(event)
    {
	// Determine the tab to be opened
	var clicked = $(this).attr('id');
	var tabToOpen = clicked.replace(/Tab/,"");

	// Determine which tab is open
	if($("#theCables:visible").length)
	{
	    openTab = "#theCables";
	}
	else if($("#ellenHouse:visible").length)
	{
	    openTab = "#ellenHouse";
	}
	else if($("#daneCottage:visible").length)
	{
	    openTab = "#daneCottage";
	}
	$(openTab).slideUp(750, function()
	{
	    $('#' + tabToOpen).slideDown(1000);
	    linkClick("/accommodation-" + tabToOpen);
	});
    }));
});

function linkClick(page)
{
     s="na";c="na";j="na";
    var p = "" +escape("http://www.driving-test-doctors.co.uk"+ page);
    var t=""+escape(document.title)
    s=screen.width;v=navigator.appName
    if (v != "Netscape") {c=screen.colorDepth}
    else {c=screen.pixelDepth}
    j=navigator.javaEnabled()

    NS2Ch=0
    if (navigator.appName == "Netscape" &&
    navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
    if (NS2Ch == 0)
    {
	var timeStamp = Number(new Date());
	r="?vrefer="+refer+"&vurl="+p+"&vcolours="+c+"&vsize="+s+"&siteID=drivingdoctors&title=" + page + "&pr=" + timeStamp;
	var myImage = new Image(1,1)
	myImage.src = "/getmysiteseen.php" + r
	refer = p;
    }
    _gaq.push(['_trackPageview', page]);
}


function moretext(page)
{
    startHeight = $('#content').height() + 50;
    if(startHeight < 1070) startHeight = 1070;
    
    //($throbber = $('#throbber'));
    $dropCar = $('#dropCar');
    $dropCar.hide();
   // $('#digitTel img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'160px', 'margin-top':'100px'});
    $('#digitOne img').css({'opacity':'0','width':'180px', 'height':'120px', 'margin-left':'140px', 'margin-top':'-200px'});
    $('#digitTwo img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'-320px', 'margin-top':'200px'});
    $('#digitThree img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'100px', 'margin-top':'-200px'});
    $('#digitFour img').css({'opacity':'0','width':'180px', 'height':'220px', 'margin-left':'-180px', 'margin-top':'200px'});
    $('#digitFive img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'120px', 'margin-top':'-200px'});
    $('#digitSix img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'-320px', 'margin-top':'200px'});
    $('#digitSeven img').css({'opacity':'0','width':'80px', 'height':'220px', 'margin-left':'100px', 'margin-top':'-200px'});
    $('#digitEight img').css({'opacity':'0','width':'180px', 'height':'120px', 'margin-left':'100px', 'margin-top':'200px'});
    $('#digitNine img').css({'opacity':'0','width':'80px', 'height':'120px', 'margin-left':'-340px', 'margin-top':'-200px'});
    $('#digitTen img').css({'opacity':'0','width':'80px', 'height':'220px', 'margin-left':'100px', 'margin-top':'200px'});
    $('#digitEleven img').css({'opacity':'0','width':'180px', 'height':'120px', 'margin-left':'-380px', 'margin-top':'-200px'});

    $('#theCables').hide();
    $('#ellenHouse').hide();
    $('#daneCottage').hide();


    $my.main.animate({"height": startHeight}, 1000, 'linear',  function(){slideInContent(page)});
    $('#contentText').css({"height":startHeight - 50});
}


function test()
{
    var ele = document.getElementById("content");
    if(leftMar <= 0)
   {
	sliding = false;
	leftMar = 0;
	ele.setAttribute('style','left:0px');
	clearInterval(gh);
   }
   else
   {
	leftMar -= 10;
	if(leftMar < 0) leftMar = 0;
	var val = "left:" + leftMar + "px";
	ele.setAttribute('style',val);
   }
}

function slideInContent(page)
{
    var contentCar = $('#contentCar');
    var content = $('#content');

    contentCar.show('slide', {direction: "right"},1000, function()
    {
	content.show('slide', { direction: "right"},600, function()
	{
	    if(page == "/index.php" || page == "/")
	    {
		//$throbber.fadeTo(0,0.7);
		$dropCar.delay(250).show('slide', {direction: "up", easing: 'easeOutBounce'},2000);
		//$throbber.repeat (2000, 5);
	    }
	    else if(page == "/contact-us.php")
	    {
		//$('#digitTel img').delay(1000).animate({'opacity':'1',"height": '20px', "width": '35px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1000 });
		$('#digitOne img').delay(1400).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1500});
		$('#digitTwo img').delay(600).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1900});
		$('#digitThree img').delay(700).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1600});
		$('#digitFour img').delay(1300).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1400});
		$('#digitFive img').delay(1000).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1100});
		$('#digitSix img').delay(500).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1700});
		$('#digitSeven img').delay(1500).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1900});
		$('#digitEight img').delay(1100).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1200});
		$('#digitNine img').delay(800).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'0px'}, {duration: 1800});
		$('#digitTen img').delay(1200).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'-0px'}, {duration: 1000});
		$('#digitEleven img').delay(900).animate({'opacity':'1',"height": '15px', "width": '13px', 'margin-left':'0px', 'margin-top':'-0px'}, {duration: 1300});
	    }
	    else if(page == "/accommodation.php")
	    {
		var startHeight = $('#accomDesc').height();
		$('#theCables').css({"height":startHeight});
		$('#ellenHouse').css({"height":startHeight});
		$('#daneCottage').css({"height":startHeight});
		$('#theCables').delay(250).slideDown(1000);
		
		

	    }
	    $("#cover").hide(3);

	    s="na";c="na";j="na"
	    
	    var h = document.location.hash;
	    var queryString = escape(window.location.search);
	    if(h == "") h = document.location.pathname;
	    h = h.replace("#","");
	    
	    var p = "http://www.driving-test-doctors.co.uk" + h;
	   
	    p = p.replace("%23","");
	    //alert(p)
	    var t=""+escape(document.title)
	    s=screen.width;v=navigator.appName
	    if (v != "Netscape") {c=screen.colorDepth}
	    else {c=screen.pixelDepth}
	    j=navigator.javaEnabled()

	    NS2Ch=0
	    if (navigator.appName == "Netscape" &&
	    navigator.appVersion.charAt(0) == "2") {NS2Ch=1}
	    if (NS2Ch == 0)
	    {
		var timeStamp = Number(new Date());
		r="?vrefer="+refer+"&vurl="+p+queryString + "&vcolours="+c+"&vsize="+s+"&siteID=drivingdoctors&title=" + t + "&pr=" + timeStamp;
		var myImage = new Image(1,1)
		myImage.src = "/getmysiteseen.php" + r
		refer = p;
	    }
	    //_gaq.push(['_trackPageview', h]);
	    priorOverlayPage = h;

	})
  })
}


function loadAjaxPageFunc()
{
    $('#areaLocatorOverlay').hide();
    randomNum = Math.round(new Date().getTime() / 1000);

    //page = page.replace(".php","");
    $.ajax(
    {
	url: "/ajax" + page + "?sid=" + randomNum,
	cache: false,
	timeout: 10000,
	error: function()
	{
	    loadIn = 1;
	    alert("Connection lost. Please check your internet connection and try again.");
	    $("#cover").hide(3);
	},
	success: function(html)
	{
	    if(html == "")
	    {
		alert("Connection lost. Please check your internet connection and try again.");
		$("#cover").hide(3);
	    }
	    else
	    {
		loadIn = 1;
		window.$my.dropCar = $('#dropCar');

		var firstSplit = new Array();
		firstSplit = html.split("-->", 2);
		var secondSplit = new Array();
		secondSplit = firstSplit[0].split("<\!--",2);

		document.title = secondSplit[1];


		if(loadLayer == 0)
		{

		    $('#dropCar').stop();

		    $my.contentCar.hide('slide', {direction: "left", easing: 'easeInBack'},500, function()
		    {
			$('#carTitle').html(secondSplit[1]);
			$my.content.hide('slide', {direction: "left"},300, function()
			{
			    $my.content.html(html);
			    moretext(page);
			});
		    });
		}
		else
		{
		    $my.content.html(html);
		}


		// Highlights the current page link
		$my.navigationA.each(function()
		{
		    buttonID = $(this).attr('id');
		    imgID = buttonID.replace("_link", "");

		    var mainDiv = "#" + imgID + "_main";
		    var roundaboutDiv = "#" + imgID;
		    var stopDiv = "#" + imgID + "Stop";

		    if($(this).attr('href') == (page))
		    {
			$(mainDiv).animate({'left': '0px'}, {duration: 500});
			$(stopDiv).delay(150).animate({'opacity': '1'}, {duration: 500});
		    }
		    else
		    {
			$(mainDiv).animate({'left': '10px'}, {duration: 500});
			$(stopDiv).animate({'opacity': '0'}, {duration: 500});
			$(roundaboutDiv).css({'opacity': '0'});
		    }
		})
	    }
	}
    })
}
