$(document).ready(function(){

	/* --- site search --- */$("#searchtxt").autocomplete("/suggest.php");
	/* --- left column animation --- */$('#contactContent').hide();$('a#newsToggle').click(function() {$('#newsContent').toggle(500);return false;});

    var contactWindow = $('#contactContent');
    var overlay = $('<div id="contactOverlay"></div>');
    var close = $('<span id="contactOverlayClose" title="Return to website">x</span>');

    close.hover(function(){
       $(this).stop().css({ color: '#fff', 'border-color': '#fff' });
    }, function(){
       $(this).stop().css({ color: '#555', 'border-color': '#555' });
    });
    close.trigger('mouseout');
    overlay.click(function(){
        close.triggerHandler('click');
    });
    close.click(function(event){
        contactWindow.hide();
        overlay.hide();
        $(window).unbind('scroll resize');
    });

    function initForm() {
        var form = $('#contactContent #col2 form');
        form.ajaxForm({
            target: '#contactContent #col2',
            success: function() {
                initForm();
            }
        });
        form.find('select#country').change(function(event){
            var postcode = $('#postcode');
            postcode = postcode.add(postcode.prev());

            if ($(this).val().toLowerCase() == 'australia') {
                postcode.show();
            } else {
                postcode.hide();
                postcode.val('');
            }
        }).triggerHandler('change');
        form.find('select#howfind').change(function(event){
            var other = $('#howfind_other');
            other = other.add(other.prev());
            if ($(this).val() == 'other') {
                other.show();
            } else {
                other.hide();
                other.val('');
            }
        }).triggerHandler('change');
    }

    initForm(contactWindow.find('form'));
    contactWindow.prepend(close, $('<h3 id="contactContentTitle">Contacts</h3>'));
    
	contactWindow.hide();
    overlay.hide();
    overlay.prependTo(document.body);

    $('#homepagemainright').css({cursor: 'pointer'});
    $('#homepagemainright').click(function(){
        $('#contactToggle').click();
    });

    $('#contactToggle').click(function(event){
        event.preventDefault();
        
        var DEFAULT_OFFSET = 10;
        var USE_FIXED_HACK = $.browser.msie && $.browser.version.split('.')[0] == '6';
        var windowWidth, windowHeight, windowOffset, contactWidth, contactHeight, centerHeight;

        windowWidth = $(window).width();
        windowHeight = $(window).height();
        windowOffset = $(window).scrollTop();
        contactWidth = $(contactWindow).width();
        contactHeight = $(contactWindow).height();

        centerHeight = (windowHeight / 2) - (contactHeight / 2) + windowOffset;
        centerHeight = centerHeight > 0 ? centerHeight : DEFAULT_OFFSET;

        contactWindow.fadeIn();
        contactWindow.css({
            left: (windowWidth / 2) - (contactWidth / 2),
            top: (windowHeight / 2) - (contactHeight / 2) + windowOffset
        });

        if (USE_FIXED_HACK) {
            overlay.css('top', windowOffset);
            $(window).bind('scroll', function() {
                overlay.css({
                    top: $(this).scrollTop()
                });
            });
        } else {
            overlay.css('position', 'fixed');
        }
        $(window).bind('resize', function() {
            overlay.width($(window).width());
            overlay.height($(window).height());
        });
        $(window).triggerHandler('scroll');
        $(window).triggerHandler('resize');

        overlay.hide().css('opacity', 0);
        overlay.show().animate({ opacity: 0.85 });
    });




//    $('#contactContent').

    $('#popup-overlay').prepend(document.body);


    width = $('#contactContent').width();

//	/* --- ajax form submit --- */
//	if ($('#htmlForm').length > 0) {
//		$('#htmlForm').ajaxForm({ // bind contact form using ajaxForm
//			// target identifies the element(s) to update with the server response
//			target: '#col2',
//			// success identifies the function to invoke when the server response
//			// has been received; here we apply a fade-in effect to the new content
//			success: function() {
//				$('#col2').fadeIn('slow');
//			}
//		});
//	}
//
//        if($('#howfind').length > 0) {
//           $('#howfind').change(function(){
//               if($(this).val()=='other') {
//                $('.notvisible').toggleClass('visible');
//                $('#howfind_other').focus();
//            }
//           });
//        }
//
//        if($('#mainImage').length > 0) {
//            $('#thumbnails a').trigger("click");
//        }
//
});


//function submit(formname) {
//	document.formname.submit();
//}