//GENERIC POPUPWINDOW CLASS
var GenericPopupWindow = Class.create();
GenericPopupWindow.default_width = 600;
GenericPopupWindow.default_height = 500;
GenericPopupWindow.scrolling = false;
GenericPopupWindow.prototype = {
	initialize: function( el ){
		this.el = el;
		this.winCount = 0;
		this.width = ( this.el.hasAttribute('win_width') ? this.el.attributes['win_width'].value : GenericPopupWindow.default_width );
		this.height = ( this.el.hasAttribute('win_height') ? this.el.attributes['win_height'].value : GenericPopupWindow.default_height );
		this.scrolling = ( this.el.hasAttribute('scrolling') ? this.el.attributes['scrolling'].value : GenericPopupWindow.scrolling );
		Event.observe( this.el, 'click', this.clicked.bindAsEventListener( this ) );
	},
	clicked: function( event ){
		if(this.scrolling == '1'){
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1,scrollbars=1");
		} else {
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1");
		}
		try{
			Event.stop( event );
		}catch( e ){
			//return false;
		}
	}
}
Event.observe(window, 'load', function() {
	
});


function formResetFunc(id){
	$(id).reset();
	return false
}
function commJumpMenu(){
	var element = $('comSearchSel').value;
	location.href = element;
}
function commAnchorMenu(){
	var element = $('comCountySel').value;
	location.href = '#' + element;
}
function commCMSJumpMenu(){
	var element = $('communityCMSjumpMenu').value;
	location.href = element;
}
function cdsGoTo(locationToGo){
	window.location = (locationToGo);
}

var propHub = null;
var openHub = null;
var propTrigger = null;
var openTrigger = null;
var iCount = 0;
function searchHubProp() {
	openTrigger.src = '/images/tab_searchHub-openhouse-off.gif';
	propTrigger.src = '/images/tab_searchHub-property-on.gif'
	if(propHub.visible()){
		openHub.hide();
	}else{
		openHub.hide();
		propHub.show();
	}	
}
function searchHubOpen() {
	openTrigger.src = '/images/tab_searchHub-openhouse-on.gif';
	propTrigger.src = '/images/tab_searchHub-property-off.gif'
	if(openHub.visible()){
		propHub.hide();
	}else{
		openHub.show();
		propHub.hide();
	}	
}
//fire off events when the page loades based on what prototyp we have!
if(parseFloat(Prototype.Version) >= 1.6){
	//if we have prototype 1.6 than we use this event because it's faster!
	document.observe("dom:loaded", function() {
		if($('comSearchSel')){$('comSearchSel').observe('change', commJumpMenu.bindAsEventListener(this));}
		if($('comCountySel')){$('comCountySel').observe('change', commAnchorMenu.bindAsEventListener(this));}
		if($('communityCMSjumpMenu')){$('communityCMSjumpMenu').observe('change', commCMSJumpMenu.bindAsEventListener(this));}
		$$( "a.PopupWin" ).each(function(el){new GenericPopupWindow(el);});
		
		//search hub stuff
		if(document.images){
			hubImages = new Image();
			hubArray = new Array();
			hubArray[0] = '/images/tab_searchHub-property-on.gif';
			hubArray[1] = '/images/tab_searchHub-openhouse-on.gif';
			hubArray[2] = '/images/tab_searchHub-property-off.gif';
			hubArray[3] = '/images/tab_searchHub-openhouse-off.gif';
			for(iCount=0; iCount < hubArray.length; iCount++){ 
				hubImages.src = hubArray[iCount];
			}
		}
		propHub = $('PropertyHub');
		openHub = $('OpenHouseHub');
		propTrigger = $('propertyHubTrigger');
		openTrigger = $('openHouseHubTrigger');
		if(propTrigger){ propTrigger.observe('click', searchHubProp.bindAsEventListener(this)); }
		if(openTrigger){ openTrigger.observe('click', searchHubOpen.bindAsEventListener(this)); }
	});
} else {
	Event.observe(window, 'load', function() {
		if($('comSearchSel')){$('comSearchSel').observe('change', commJumpMenu.bindAsEventListener(this));}
		if($('comCountySel')){$('comCountySel').observe('change', commAnchorMenu.bindAsEventListener(this));}
		if($('communityCMSjumpMenu')){$('communityCMSjumpMenu').observe('change', commCMSJumpMenu.bindAsEventListener(this));}
		$$( "a.PopupWin" ).each(function(el){new GenericPopupWindow(el);});
		
		//search hub stuff
		if(document.images){
			hubImages = new Image();
			hubArray = new Array();
			hubArray[0] = '/images/tab_searchHub-property-on.gif';
			hubArray[1] = '/images/tab_searchHub-openhouse-on.gif';
			hubArray[2] = '/images/tab_searchHub-property-off.gif';
			hubArray[3] = '/images/tab_searchHub-openhouse-off.gif';
			for(iCount=0; iCount < hubArray.length; iCount++){ 
				hubImages.src = hubArray[iCount];
			}
		}
		propHub = $('PropertyHub');
		openHub = $('OpenHouseHub');
		propTrigger = $('propertyHubTrigger');
		openTrigger = $('openHouseHubTrigger');
		if(propTrigger){ propTrigger.observe('click', searchHubProp.bindAsEventListener(this)); }
		if(openTrigger){ openTrigger.observe('click', searchHubOpen.bindAsEventListener(this)); }
		
	});
}