﻿

Cufon.replace('span.btnfilter', { fontFamily: 'dinbold', textShadow: '#333 1px 1px' });

$(document).ready(function () {

    $('div.jqreplace').jqTransform({ imgPath: 'scripts/img/' });

    $('#adv').toggle(function () {
        $('#advsearchbox').animate({ height: '283px' }, 300);
        $('#advsearchbox').addClass('advopen');
    },
    function () {
        $('#advsearchbox').animate({ height: '43px' }, 300);
        $('#advsearchbox').removeClass('advopen');
    });

    $('#searchbox input.search').keypress(function (e) {
        if (e.which == 13) {
            var postbk = $('#searchbox a.searchBtn').attr('href');
            eval(postbk);
            return false;
        }
    });

    $('#pricefilter span.hilite').click(function () {
        location.href = $(this).parent('a').attr('href');
    });


    $('#dadvptype .jqTransformSelectWrapper li a').click(function () {
        if (parseInt($('#dadvptype select').val()) == 0) { $('#dadvminp').show(); $('#dadvmaxp').show(); }
        else { $('#dadvminp').hide(); $('#dadvmaxp').hide(); }
    });

    $('#btnAdvSearch').click(function () {
        //formulate query
        var $context = $('#advsearchbox');
        var beds = $('select.advbedrooms', $context).val();
        var ptype = $('select.advptype', $context).val();
        var loc = $('select.advlocation', $context).val();
        var min = $('select.advminprice', $context).val();
        var max = $('select.advmaxprice', $context).val();

        var search_url = '/advanced-search.aspx?b=' + beds + '&l=' + loc + '&min=' + min + '&max=' + max + '&t=' + ptype;
        location.href = search_url;
    });


    //    // Sub navigation animation
    //    $(function () {
    //        $('ul.hide').hide();
    //        $("li.hidenav").find('a:first').attr('href', '#');
    //        $("li.hidenav").click(function () {
    //            $(this).children('ul.hide').animate({ height: 'toggle' }, 300);
    //            return false;
    //        });

    //        $('li.hidenav li.selected').parent('ul.hide').show();
    //    });


    // Sub navigation animation

    $('ul.hide').hide();

    $("li.hidenav ").each(function () {
        $("a:first", $(this)).click(function () {
            var el = $(this).parent('li').find('ul.hide');
            $('ul.xopen').not(el).removeClass('xopen').slideUp();
            if (!el.hasClass('xopen')) el.addClass('xopen').slideDown();
            return false;
        });
    });

    $('li.hidenav li.selected').parent('ul.hide').addClass('xopen').show();

    //Gallery load
    $(".gallery img.thumb").one("load", function () {
        $(this).fadeIn(1000);
    }).each(function () {
        if (this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
            $(this).trigger("load");
        }
    });

    //Gallery Animation
    $("img.thumb").click(function () {
        var id = $(this).parent('a').attr("id").substring(1);
        var img = new Image();
        $(img).load(function () {
            $('.main div').empty()
                    .append(img)
                    .hide()
                    .fadeIn(500);
        }).attr('src', $(this).attr('rel'))
            .attr('id', 'i' + id);
        return false;
    });

    $('.main div').click(function () {
        var id = $('.main div img').attr("id").substring(1);
        var $a = $('#a' + id);
        if ($a.next('a.a-thumb').length > 0) {
            $a.next('a.a-thumb').children('img').click();
        }
        else {
            $('.gallery a.a-thumb:first').children('img').click();
        }

        return false;
    });

    //check all parishes
    $('#check-parish').click(function () {
        $(this).parents('#td-parishes').find(':checkbox').not(this).attr('checked', this.checked);
    });
    
    if($('#dSituation').length > 0)
    {
        $('#dSituation select').change(function(){
            var sv = parseInt($(this).val());
            if(sv == 3){
                $('#dRentMin, #dRentMax, #dRentExtras').show();
                $('#dSaleMin, #dSaleMax').hide();
            } else {
                $('#dRentMin, #dRentMax, #dRentExtras').hide();
                $('#dSaleMin, #dSaleMax').show();
            }
        });
    }    

    DD_belatedPNG.fix('.hilite img, .uo, #toprow, #footer, #adv, #footer img, .hotProp');

    $('a.top').click(function () {
        $('html, body').animate({ scrollTop: '0px' }, 300);
        return false;
    });


});

function historyBack() {
    history.back();
}

