$(document).ready(function(){
	
	$('.toplevel').click(function(){
		//$(this).siblings('ul').css('display','block'); 
	});
	
	$("a[rel=gallery]").colorbox({								
		maxWidth:"90%",
		maxHeight:"90%",
		scalePhotos: true
	});
		
	$('#slideshow').cycle({
		fx: 'fade',
		speed: 2000,
		timeout: 5000
	});	

	/* feedback */
	var $feedbackButton = $("a#feedbackButton");
	var $feedbackForm = $("#feedbackForm");
	var $preferredMethods = $(".preferredmethods", $feedbackForm);
	var $dobField = $(".dob", $feedbackForm);
			
	$feedbackButton.click(function() {		
		$feedbackForm.toggle();
	});

	$('#submitfeedback').click(function(){
		$.ajax({
			type: "POST",
			dataType: 'json',
			data: $("form").serialize(),
			url: "/feedback/",
			success: function(output){					
				if(typeof output.result != 'undefined'){
					if(output.result == 'success'){
						$feedbackForm.fadeOut();
						$("#message").html('<p>Thankyou.</p>').show().delay(2000).fadeOut();							
					} else {														
						$feedbackForm.fadeOut();		
						$("#message").html('<p>Sorry, an error has occurred.</p>').show().delay(2000).fadeOut();
					}
				}
			}
		});	
	});	
	/*
		$("form", $feedbackForm).ajaxForm(function() {
			$("> form", $feedbackForm).hide();
			$("> div", $feedbackForm).show();
			$feedbackForm.fadeOut(1000, function() {
				$("> form", $feedbackForm).show();
				$("> div", $feedbackForm).hide();
			});
		}); 
	*/
	
	$("input[type=button][value=Cancel]", $feedbackForm).click(function() { 
		$feedbackForm.hide();
	});

	$preferredMethods.toggle($("[name=contactme]", $feedbackForm).attr('checked'));		
	$("[name=contactme]", $feedbackForm).click(function() {
		$preferredMethods.toggle($(this).attr('checked'));
	});	

	$dobField.toggle($("[name=incmarketing]", $feedbackForm).attr('checked'));		
	$("[name=incmarketing]", $feedbackForm).click(function() {
		$dobField.toggle($(this).attr('checked'));
	});
	
	zIndexWorkaround();
	
});


function zIndexWorkaround()
{
    // If the browser is IE,
    if(isOldIE())
    {
		
        /*
        ** For each div with class menu (i.e.,
        ** the thing we want to be on top),
        */
        $("nav ul li ul").parents().each(function() {
            var p = $(this);
            var pos = p.css("position");
 
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
                /*
                ** Add the "on-top" class name when the
                ** mouse is hovering over it, and remove
                ** it when the mouse leaves.
                */
                p.hover(function() {
						$(this).addClass("on-top");							
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
		
    }
}

function isOldIE()
{
    if(navigator.userAgent.match(/MSIE [0-7]\.\d+/))  //IE 7 and below
        return true;
    return false;
}



