﻿var map;

$(document).ready(function() {
    $('#body .section .itemSearchModule form select').change(function() {
        if ($(this).val() != "") {
            $('#body .section .itemSearchModule form').attr('action', '/site/apartments/listing');
            $('#body .section .itemSearchModule form').submit();
        }
    });
    $('.popup').fancybox();

    var imgList = [];
    $('#body .section .cmsGallery ul li a').each(function(item) {
        var obj = {};
        obj.href = $(this).attr('href');
        imgList.push(obj);
    });

    $('#body .section .cmsGallery ul li a').click(function() {
        $('#body .section .cmsGallery .main').attr('href', $(this).attr('href'));
        $('#body .section .cmsGallery .main img').attr('src', $(this).find('img:first').attr('src'));
        return false;
    });

    $('#body .section .cmsGallery .main').fancybox({
        'itemArray': imgList
    });


    $('#body .section .galleryPopup').fancybox({
        'itemArray': imgList
    });

    if (jQuery.support.boxModel) {
        $('.threedtour').fancybox({
            'frameWidth': 773,
            'frameHeight': 521
        });

        $('.banner .cmsGallery ul a[href=/site/apartments/3d-tour?iframe]').each(function(index) {
            $(this).fancybox({
                'frameWidth': 773,
                'frameHeight': 521
            });
        });
    }
    else {
        $('.threedtour').fancybox({
            'frameWidth': 753,
            'frameHeight': 501
        });

        $('.banner .cmsGallery ul a[href=/site/apartments/3d-tour?iframe]').each(function(index) {
            $(this).fancybox({
                'frameWidth': 753,
                'frameHeight': 501
            });
        });
    }


    $('.banner .cmsGallery ul').cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 8000
    });

    $('.blank .cmsGallery .main div').flash({
        swf: $('.blank .cmsGallery ul a:first').attr('href'),
        width: 640,
        height: 480
    });

    $('.blank .cmsGallery ul a').click(function() {
        $('.blank .cmsGallery .main div').flash({
            swf: $(this).attr('href'),
            width: 640,
            height: 480
        });
        $('#fancy_title_main div', parent.document.body).text($(this).find('img:first').attr('alt'));
        return false;
    });

    if (location.href.indexOf('contact/map') != -1) {
        var point = new GLatLng(53.838247, -1.779528);
        map.addOverlay(new GMarker(point));
    }


});



