
	//	Create the initial jQuery object
	$.root = $(document)

	$.root.ready(function() {

        //  SlideDeck clone thing
        if (document.getElementById('slidedeck')) {

            $('#slidedeck a.trigger').bind('click', function (event) {
                event.preventDefault();

                var link = $(this);

                if (link.parent().hasClass('active')) {
                    return false;
                }

                if (!$.root.find('html').hasClass('cssanimations')) {
                    $('#slidedeck li.active').animate({width: 35}, 250, 'swing');

                    link.parent().animate({width: 760}, 250, 'swing');
                }

                link.parent().addClass('active').siblings().removeClass('active');
            });

        }



        // Map for property details
        if (document.getElementById('property_map')) {

            var lat = $('#property_lat').html(),
                lng = $('#property_lng').html();

            $("#property_map").gMap({
                markers: [{
                    latitude: lat,
                    longitude: lng 
                }],
                scrollwheel: false,
                controls: [
                    'GSmallZoomControl3D'
                ],
                zoom: 14,
                icon: {
                    image: "/img/design/map_marker.png",
                    shadow: false,
                    iconsize: [25, 39],
                    shadowsize: false,
                    iconanchor: [12, 34],
                    infowindowanchor: [8, 2]
                }
            });

        }



        //  Property landing list filters
        if (document.getElementById('landing_filters')) {

            $('p.max_price_rent').hide();

            $('input[name=buy_or_rent]').bind('change', function () {
                show = $('.checks input:checked').val();
                hide = show === 'rent' ? 'buy' : 'rent';

                $('p.max_price_' + show).show();
                $('p.max_price_' + hide).hide();
            });

        }



        // Office map on contact page
        if (document.getElementById('office_map')) {

            var olat    = $('#office_lat').html(),
                olng    = $('#office_lng').html(),
                address = $('dl.contact_details dd:last').html();
            
            $("#office_map").gMap({
                markers: [{
                    latitude: olat,
                    longitude: olng,
                    html: '<p>' + address + '</p>',
                    popup: false
                }],
                scrollwheel: false,
                controls: [
                    'GLargeMapControl3D'
                ],
                zoom: 14,
                icon: {
                    image: "/img/design/map_marker.png",
                    shadow: false,
                    iconsize: [25, 39],
                    shadowsize: false,
                    iconanchor: [12, 34],
                    infowindowanchor: [8, 2]
                }
            });

        }



        // Multipics gallery
        $('.multi_thumbs li a').click( function() {

            var link    = $(this),
                fullSrc = $(this).attr('href'),
                img     = document.createElement('img');

            $('#multi_master_pic').hide();

            $(img).load(function() {
                $('#multi_master_pic').attr('src', fullSrc).fadeIn('fast');

                $('.multi_thumbs li a').removeClass('active');

                link.addClass('active');
            }).attr('src', fullSrc);

            return false;

        });

	});



    (function ($) {
        var cache = [];

        $.preLoadImages = function() {
            var args_len = arguments.length;

            for (var i = args_len; i -= 1;) {
                var cacheImage = document.createElement('img');

                cacheImage.src = arguments[i];
                cache.push(cacheImage);
            }
        }
    })(jQuery);

