jQuery(document).ready(function () {

    // Globals
    $(':checkbox').after('<a class="checkboxCustom"><!-- --></a>');
    $(':radio').after('<a class="radioCustom"><!-- --></a>');


    // Background transition
    $('.mainback').cycle({
        fx: 'fade',
        random: 1,
        speed: 1000,
        timeout: 6000
    });

    // Sliders

    if ($('.main-tab ul').length > 0) {
        $('a.openCol').mouseover(function () {
            if ($(this).attr('class') != 'active') {
                $('.main-tab ul li a').removeClass('active').addClass('openCol');
                $(this).addClass('active');
                $(this).removeClass('openCol');
                //alert('click!');
                var osl = $(this).attr('btn');
                $('.sliders .col').slideUp(300);
                $('.sliders #sl' + osl).slideDown(200);
            };
        });
        //$('#sl1').bind('mouseout', function () { $('#sl1').slideUp(300); });
    };

    // Search
    $('.tabs a').click(function () {
        $('.tabs a').removeClass('active');
        $(this).addClass('active');
    });

    $('label').click(function () {
        if ($(this).prev().prev().attr('checked') == true) {
            $(this).prev().prev().removeAttr('checked');
            $(this).prev().removeClass('checked');
        } else {
            $(this).prev().prev().attr('checked', true);
            $(this).prev().addClass('checked');
        }
    });

    // Search Results
    $('ul.pageinfo li').append('&nbsp;-&nbsp;');
    var lastChild = $(".lastLi").text().split("-")[0];
    $('.lastLi').html('<a href="#">' + lastChild + '</a>');

    // Search Agent
    $('#agentSearch').focus(function () {
        $(this).val('');
    });
    $('#agentSearch').blur(function () {
        if ($(this).val() == '') {
            $(this).val('Agent Name');
        }
    });

    // Agent Details
    $('.agent-details-menu a').click(function () {
        $(this).parent().find('a').removeClass('active');
        $(this).addClass('active');
    });

    // Neighborhood
    $('.neighborhood .rgt .read-more').click(function () {
        $(this).fadeOut(400, function () { $(this).detach() });
        $('.hiddenText').slideDown(500);
    });

    // Sale detail > Gallery
    $('.ad-image-frame').cycle({
        fx: 'fade',
        pager: '.ad-gallery .ad-nav',
        pagerAnchorBuilder: function (idx, slide) {
            slide = $(slide);
            return '<a href="#"><img src="' + slide.find('img').attr('src') + '"/></a>';
        },
        speed: 1000,
        timeout: 0
    });
    $('.ad-gallery .ad-nav').append('<div class="clearfix"><!-- clearfix --></div>');

    $('.listing-details .section .top .nav a.map').click(function () {
        $('.listing-details .section .top .nav a').removeClass('active');
        $(this).addClass('active');

        $('.detail-page .listing-details .section .top .nav select').fadeOut(300);
        $('.detail-page .listing-details .section .Gmap .results-list').slideUp(700);

    });
    $('.listing-details .section .top .nav a.poi').click(function () {
        $('.listing-details .section .top .nav a').removeClass('active');
        $(this).addClass('active');

        $('.detail-page .listing-details .section .top .nav select').fadeIn(300);
        $('.detail-page .listing-details .section .Gmap .results-list').slideDown(700);
    });

    /*---------- Lightbox ----------*/
    $('.lightbox, .closeBtn').click(function () {
        $('.lightboxBlock').fadeOut(170);
        $('.lightboxBlock').fadeOut(200, function () {
            $('.lightbox, .lightboxBlock').detach();
        });
    });


});      // END


var POIdetailLsc;
var POIMap = {
init: function() {
	this.googleMapInit();
},
latitude: 40.7834345,
longitude: -73.9662495,
zoom: 14,
googleMapInit: function() {
	if (typeof(GBrowserIsCompatible) != 'function')
		return;
	try {
		if (GBrowserIsCompatible()) {
			var bounds = new GLatLngBounds();
			POIdetailLsc = new google.maps.LocalSearch({
				suppressZoomToBounds : true,
				suppressInitialResultSelection : true, // Hides results list from view until user has selected a POI
				resultList : document.getElementById("poi-local-search-results"), // Div for results from google local to load in to
				linkTarget : GSearch.LINK_TARGET_BLANK, // Sets all outbound links to open in a new window
				searchFormHint : " " // Default text to enter in the google local search bar
			});
			var map = new GMap2(document.getElementById('poi_map_canvas'));
			map.addControl(new GSmallMapControl());
			map.addControl(POIdetailLsc);
			map.setCenter(new GLatLng(this.latitude, this.longitude), this.zoom);
			if (this.latitude != 0 && this.longitude != 0) {
				var point = new GLatLng(this.latitude, this.longitude);
				var marker = new GMarker(point);
				map.addOverlay(marker);
			}
			POIdetailLsc.execute('Restaurants');
		}
	}
	catch(e) {
		alert(e.message);
	}
}
};



