$(document).ready(function() {
    // Replace Text Header
    $("h1.img").each(function() {
        string = $(this).text();
        filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g, '');
        $(this).html('<img src="graphics/' + filename + '.gif" alt="' + string + '" title="' + string + '" />');
    });

    // Replace Page links for Ajax driven content
    $("a#open").attr("href", "#");
    $("a#termslink").attr("href", "#terms");
    $("a#privacylink").attr("href", "#privacy");
    $("a#accessibilitylink").attr("href", "#accessibility");
    

	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});

    $("#submitbutton").click(postContactForm);
    
    $("a[rel^='prettyPhoto']").prettyPhoto({
        showTitle: false, /* true/false */
        theme: 'dark_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
    });

});
function postContactForm() {
    var contactformcontents = $("#panel form").serialize();
    //alert(contactformcontents); return false;

    $.ajax({
        type: "POST",
        url: "ajax/enquirysender.asp",
        dataType: "application/x-www-form-urlencoded",
        data: contactformcontents,
        async: false,
        success: function(msg) {
        $("#formmessage").addClass("message");
        $("#formmessage").html(msg)
        .hide()
        .fadeIn(1000);
        }

    });
    return false;  
}
$(function() {
    $("#navigation").lavaLamp({
        fx: "backout",
        speed: 700,
        click: function(event, menuItem) {
            return false;
        }
    });
});

jQuery(function($) {
    $('#content').attr({ scrollTop: 0, scrollLeft: 0 });

    // Scroll initially if there's a hash (#something) in the url 
    $.localScroll.hash({
        target: '#content', //could be a selector or a jQuery object too.
        axis: 'yx', //the default is 'y'
        queue: true,
        duration: 1500
    });

    var $last = $([]); //save the last link

    $.localScroll({
        target: '#content', //could be a selector or a jQuery object too.
        axis: 'yx', //the default is 'y'
        queue: true,
        duration: 1000,
        hash: false,
        onBefore: function( e, anchor, $target ){//'this' is the clicked link
        //$("#navigation").html('<li title="home page" id="homelink"><a href="#home">home</a></li><li title="paris with a view" id="parislink"><a href="#parispanorama">paris with a view</a></li><li title="middleton granary"><a href="#suffolkpanorama" id="suffolklink">middleton granary</a></li>');
            $("#navigation li").removeClass('current');
			//if(anchor == "#parispanorama"){
			//$("#parislink").addClass('current');
			//}
			//if(anchor == "#suffolkpanorama"){
			//$#navigation li #suffolklink").addclass('current');
			//}
			if( this.blur )
				this.blur();//remove the awful outline
		},
        onAfter: function(anchor) {
        }
    });
});
