function displayWindow(theURL, winName, width, height, features) { //v3.1
    // Made by Eddie Traversa modified from Macromedia Code
    var windowName = winName;
    var window_width = width;
    var window_height = height;
    var newfeatures = features;
    var window_top = 0;
    var window_left = (screen.width - 500 - 20);
    var newWindow = window.open('' + theURL + '', '' + winName + '', 'width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',' + newfeatures + '');
    newWindow.focus();
}
$(document).ready(function() {
	$("#slideshow").css("overflow", "hidden");
	$("#prevbtn").hide();
	$("#nextbtn").hide();
	
	$("ul#slides") 
	.before('<div id="pager">')
	.cycle({
		fx: 'fade',
		timeoutFn: calculateTimeout,
		pause: 1,
		prev: '#prev',
		next: '#next',
		pager:  '#pager'
		});
	  	function calculateTimeout(currElement, nextElement, opts, isForward) {
		
		    var index = opts.currSlide;
		     return index == 0 ? 4000 : 5000;
		} 
  	$("#prev").hover(function() {
    	$("#prevbtn").fadeIn("slow");
  	},
  		function() {
    	$("#prevbtn").fadeOut("slow");
  	});
  	
  	$("#next").hover(function() {
    	$("#nextbtn").fadeIn("slow");
  	},
  		function() {
    	$("#nextbtn").fadeOut("slow");
  	});
	
	$(".radio").dgStyle();
	$(".checkbox").dgStyle();
	
});

$(function() {
	$( ".resizeHomeListing" ).aeImageResize({ height: 180, width: 225 });
	$("a.launchMap").fancybox();
	$("a.floorplans").fancybox();
	$("a.mailto").fancybox({type:'iframe', width: 410, height: 505, speedOut: 500, titleShow: false });

});

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function Search() {
    var q = new String();

    q = addQueryStringParam(q, 'listing', getQueryStringParamsForGroup('listing'));    
    q = addQueryStringParam(q, 'county', getQueryStringParamsForGroup('county'));
    q = addQueryStringParam(q, 'city',getQueryStringParamsForGroup('city'));
    q = addQueryStringParam(q, 'type', getQueryStringParamsForGroup('type'));
    q = addQueryStringParam(q, 'priceFrom',getQueryStringParamsForSelect('priceFrom'));
    q = addQueryStringParam(q, 'priceTo', getQueryStringParamsForSelect('priceTo'));
    q = addQueryStringParam(q, 'dateFrom', getQueryStringParamsForTextbox('dateFrom'));
    q = addQueryStringParam(q, 'dateTo', getQueryStringParamsForTextbox('dateTo'));
    q = addQueryStringParam(q, 'bed',getQueryStringParamsForGroup('bed'));
    q = addQueryStringParam(q, 'bath',getQueryStringParamsForGroup('bath'));
    q = addQueryStringParam(q, 'waterfront',getQueryStringParamsForCheckBox('waterfront'));
    q = addQueryStringParam(q, 'pool',getQueryStringParamsForCheckBox('pool'));
    q = addQueryStringParam(q, 'garage', getQueryStringParamsForCheckBox('garage'));
    q = addQueryStringParam(q, 'pets', getQueryStringParamsForCheckBox('pets'));
    q = addQueryStringParam(q, 'sort',getQueryStringParamsForSelect('sort'));    

    window.location = '/property-listings/' + q;
}

function addQueryStringParam(query, paramName, paramValue) {
    if (paramValue != '') {
        if (query == '') 
        {
            query = '?';
        }
        else 
        {
            query = query + '&';
        }

        query= query.concat(paramName);
        query= query.concat('=');
        query = query.concat(paramValue);
    }

    return query;
}

function getQueryStringParamsForTextbox(id) {
    return escape($('#' + id).val());
}

function getQueryStringParamsForCheckBox(id) {
    if ($('#' + id).is(':checked')) {
        return '1';
    }
    else {
        return '';
    }
}

function getQueryStringParamsForSelect(id) {
    return $('#'+id + ' option:selected').val();
}

function getQueryStringParamsForGroup(group) {
    var checkedGroupItems = $('input[group=' + group + ']:checked');
    var ids = getCheckboxListVlaues(checkedGroupItems);
    return ids;
}

function getCheckboxListVlaues(checkBoxList) {
    var ids = new Array();

    checkBoxList.each(function (i) {
        ids[i] = $(this).val();
    });

    return ids;
}

function listToString(list) {
    var result = new String();

    $.each(list, function (i) {
        if (i != 0) {
            result = result.concat(',');
        }
        result = result.concat(list[i]);
    });

    return result;
}

function AlertList(name, list) {
    alert(name + listToString(list));
}

var Spot=new Class({
    Implements:Options,
    options:{
        cls:"w_spot"
    },
    initialize:function(b,a){
        this.setOptions(a);
        this._element=b;
        if(this._element){
            this.build()
            }
        },
build:function(){
    var a="."+this.options.cls;
    this._image=this._element.getElement(a+"_image");
    this._rollover=this._element.getElement(a+"_rollover");
    this.h=this._element.getSize().y;
    this.fx_rollover=new Fx.Morph(this._rollover,{
        duration:400,
        link:"cancel"
    });
    this._image.addEvents({
        mouseenter:this.roll_in.bind(this),
        mouseleave:this.roll_out.bind(this)
        })
    },
roll_in:function(){
    this._rollover.removeClass("inactive").addClass("active");
    this.fx_rollover.start({
        top:-2
    })
    },
roll_out:function(){
    this._rollover.removeClass("active").addClass("inactive");
    this.fx_rollover.start({
        top:this.h
        })
    }
});

window.addEvent('domready', function() {
$$(".w_spot").each(function(a){            
            new Spot(a)
            });
});
