$(document).ready(function() {
    $isIE6 = false;
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        $isIE6 = true;
    }

    $('body').removeClass('noJS');

    $footerHeight = $(window).height() - $('#footer').position().bottom;
    if (!$.browser.msie) {
        $('#footer').css({ 'minHeight': $footerHeight });
    }

    var $scrollerWindow = $('#content');
    var $speed = 2500;

    $('#nav li a').hover(function() {
        $(this).fadeTo('fast', 1);
    },
	function() {
	    $(this).fadeTo('fast', 1);
	});

    $('#logo').hover(function() {
        $(this).fadeTo('fast', 1);
    },
	function() {
	    $(this).fadeTo('fast', 1);
	});

    function gotohome() {
        $scrollerWindow.stop().scrollTo($('#home'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(0px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(0px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(0px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_about");
        $('#prevControl').addClass("noScroll");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'home']);
        return false;
    }

    function gotoabout() {
        $scrollerWindow.stop().scrollTo($('#about'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-940px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-1100px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-1300px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_exhibitors");
        $('#prevControl').addClass("goto_home");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'about']);
        return false;
    }

    function gotoexhibitors() {
        $scrollerWindow.stop().scrollTo($('#exhibitors'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-1880px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-2200px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-2600px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_gallery");
        $('#prevControl').addClass("goto_about");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'exhibitors']);
        return false;
    }

    function gotogallery() {
        $scrollerWindow.stop().scrollTo($('#gallery'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-2820px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-3300px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-3900px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_fashion");
        $('#prevControl').addClass("goto_exhibitors");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'gallery']);
        return false;
    }


    function gotofashion() {
        $scrollerWindow.stop().scrollTo($('#fashion'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-3760px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-4400px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-5200px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_oakfield");
        $('#prevControl').addClass("goto_gallery");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'fashion']);
        return false;
    }

    function gotooakfield() {
        $scrollerWindow.stop().scrollTo($('#oakfield'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-4700px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-5500px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-6500px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("goto_contact");
        $('#prevControl').addClass("goto_fashion");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'oakfield']);
        return false;
    }


    function gotocontact() {
        $scrollerWindow.stop().scrollTo($('#contact'), $speed, { axis: 'x', offset: { left: 0, top: 0} });
        $('h1').stop().animate({ backgroundPosition: '(-5640px 0px)' }, $speed);
        $('#title2').stop().animate({ backgroundPosition: '(-6600px 0px)' }, $speed + 300);
        $('#title3').stop().animate({ backgroundPosition: '(-7800px 0px)' }, $speed + 600);
        $('#nextControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#prevControl').removeClass("noScroll goto_home goto_about goto_exhibitors goto_gallery goto_fashion goto_oakfield goto_contact");
        $('#nextControl').addClass("noScroll");
        $('#prevControl').addClass("goto_oakfield");
        $('h1');
        _gaq.push(['_trackEvent', 'Nav', 'contact']);
        return false;
    }

    function noScroll() {
        return false;
    }

    $('.goto_home').live("click", gotohome);
    $('.goto_about').live("click", gotoabout);
    $('.goto_exhibitors').live("click", gotoexhibitors);
    $('.goto_gallery').live("click", gotogallery);
    $('.goto_fashion').live("click", gotofashion);
    $('.goto_oakfield').live("click", gotooakfield);
    $('.goto_contact').live("click", gotocontact);
    $('.noScroll').live("click", noScroll);

    $('.back').click(function() {
        $('.homeDetail:visible').fadeOut('normal', function() {
            $('#homeMain').fadeIn();
        });
        return false;
    }
	);

    $('#FlowersLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#flowers').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'flowers']);
        return false;
    }
	);

    $('#FootwearLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Footwear').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Footwear']);
        return false;
    }
	);

    $('#HairLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Hair').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Hair']);
        return false;
    }
	);

    $('#HealthLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Health').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Health']);
        return false;
    }
	);

    $('#EventPlannersLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#EventPlanners').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'EventPlanners']);
        return false;
    }
	);

    $('#CakesLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Cakes').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Cakes']);
        return false;
    }
	);

    $('#AccomodationLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Accomodation').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Accomodation']);
        return false;
    }
	);

    $('#CoutureLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Couture').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Couture']);
        return false;
    }
	);
	
	$('#DanceStudioLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#DanceStudio').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'DanceStudio']);
        return false;
    }
	);
	
	$('#DecorLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Decor').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Decor']);
        return false;
    }
	);
	
		$('#HiringLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Hiring').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Hiring']);
        return false;
    }
	);
		
		$('#JewelleryLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Jewellery').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Jewellery']);
        return false;
    }
	);
		
	$('#PhotographyLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Photography').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Photography']);
        return false;
    }
	);
	
	$('#VideographyLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Videography').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Videography']);
        return false;
    }
	);
	
	$('#MusicLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Music').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Music']);
        return false;
    }
	);
	
	$('#MagazineLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Magazine').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Magazine']);
        return false;
    }
	);
	
	$('#StationaryLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Stationary').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Stationary']);
        return false;
    }
	);
	
	$('#LimousineLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Limousine').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Limousine']);
        return false;
    }
	);
	
	$('#LegalLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#Legal').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Legal']);
        return false;
    }
	);
	
	$('#honeymoonLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#honeymoon').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'honeymoon']);
        return false;
    }
	);
	
	$('#OakfieldFarmLink').click(function() {
        $('#webMain').fadeOut('normal', function() {
            $('#OakfieldFarm').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'OakfieldFarm']);
        return false;
    }
	);

    $('.back').click(function() {
        $('.webDetail:visible').fadeOut('normal', function() {
            $('#webMain').fadeIn();
        });
        return false;
    }
	);


    $('.back').click(function() {
        $('.OakDetail:visible').fadeOut('normal', function() {
            $('#OakMain').fadeIn();
        });
        return false;
    }
	);
		
	$('#GardensLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Gardens').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Gardens']);
        return false;
    }
	);
		
	$('#ChapelLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Chapel').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Chapel']);
        return false;
    }
	);
	
	$('#ConservatoryLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Conservatory').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Conservatory']);
        return false;
    }
	);
	
	$('#SummerhouseLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Summerhouse').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Summerhouse']);
        return false;
    }
	);
	
	$('#HomesteadLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Homestead').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Homestead']);
        return false;
    }
	);
	
	$('#DairyLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Dairy').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Dairy']);
        return false;
    }
	);
	
	
	$('#DressingLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#Dressing').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'Dressing']);
        return false;
    }
	);
	
	$('#BridalSuitesLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#BridalSuites').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'BridalSuites']);
        return false;
    }
	);
	
	$('#GuestHouseLink').click(function() {
        $('#OakMain').fadeOut('normal', function() {
            $('#GuestHouse').fadeIn();
        });
        _gaq.push(['_trackEvent', 'WebThumbs', 'GuestHouse']);
        return false;
    }
	);
	
    $("#submit").click(function() {
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var emailFromVal = $("#emailFrom").val();
        if (emailFromVal == '') {
            $("#emailFrom").addClass("error");
            hasError = true;
        } else if (!emailReg.test(emailFromVal)) {
            $("#emailFrom").addClass("error");
            hasError = true;
        }
        else {
            $("#emailFrom").removeClass("error");
        }

        var nameVal = $("#emailName").val();
        if (nameVal == '') {
            $("#emailName").addClass("error");
            hasError = true;
        }
        else {
            $("#emailName").removeClass("error");
        }

        var messageVal = $("#emailMessage").val();
        if (messageVal == '') {
            $("#emailMessage").addClass("error");
            hasError = true;
        }
        else {
            $("#emailMessage").removeClass("error");
        }


        if (hasError == false) {
            $(this).hide();
            $("#myForm").fadeOut("fast", function() {
                $("#myForm").before('<img src="images/loading.gif" alt="Loading" id="loadingImage" />');
            });

            $.post("sendemail.php",
				{ emailFrom: emailFromVal, emailName: nameVal, emailMessage: messageVal },
					function(data) {
					    $("#loadingImage").fadeOut("fast", function() {
					        $("#loadingImage").before('<p>Your message has been sent. Cheers!</p>');
					    });
					}
				 );
        }

        return false;
    });

});
