window.addEvent('domready', function() {
//									 ,{duration: 1000, transition: Fx.Transitions.expoIn}
//									 Quint.easeInOut Fx.Transitions.quadIn .Transitions.elasticOut
var mySlider = new Fx.Slide('conactado',{duration: 600, transition: Fx.Transitions.Quint.easeInOut}).hide();
	$('linklogin').addEvent('click', function() {
	mySlider.toggle();
	});
});
window.addEvent('load', function() {
$('tipo').addEvent('change', function(e) {
	e = new Event(e).stop();
	var url1 = '/imoveis/tipo.asp?tipo=' + $('tipo').getValue();
	var url2 = '/imoveis/bairro.asp?tipo=' + $('tipo').getValue()+'&classificacao=' + $('classificacao').getValue();
	onRequest:function(){
		$('classificacao').setHTML('Consultando...');
		$('bairro').setHTML('Consultando...');
		};
	var tipo = new Ajax(url1, {
		method: 'GET',
		onSuccess:function(){
		//needs the id of the select that needs to be updated and the html string
		var mySelect=new SelectBox('classificacao',this.response.text);
		mySelect.insertNewOptions();}
		});
		tipo.request();
	var bairro = new Ajax(url2, {
		method: 'GET',
		onSuccess:function(){
		//needs the id of the select that needs to be updated and the html string
		var mySelect2=new SelectBox('bairro',this.response.text);
		mySelect2.insertNewOptions();}
		});
		bairro.request();
	});

$('classificacao').addEvent('change', function(e) {
	e = new Event(e).stop();
	var url3 = '/imoveis/bairro.asp?tipo=' + $('tipo').getValue()+'&classificacao=' + $('classificacao').getValue();
	onRequest:function(){
		$('bairro').setHTML('Consultando...');};
	var bairro = new Ajax(url3, {
		method: 'GET',
		onSuccess:function(){
		//needs the id of the select that needs to be updated and the html string
		var mySelect3=new SelectBox('bairro',this.response.text);
		mySelect3.insertNewOptions();}
	});
	bairro.request();
	});

$("buscar").addEvent("click", function(e) {
	e = new Event(e).stop();
	var filtro = $("tipo").getValue();
	if (filtro == 0) {
		alert('Selecione o tipo!');
		$("tipo").focus();
		} else {
		$("formbusca").submit();	
		}
});
});

function SelectBox(selectIdIn,optionsHTMLIn){
	this.id=selectIdIn;					//the id of the select box
	this.optionsHTML=optionsHTMLIn;		//all the options in String format
	this.optionElements;				
	this.myElementHTML;					//every option in its own array section(<option></option>
	/*--Object methods--*/
	//inserts a single option
	this.insertNewOption=function(){
		//still empty but can be filled if pleased
	};
	//insert multiple options
	this.insertNewOptions=function(){
		//first split the html string
		this.splitSingleElements();

		//temporarily stored option element
		var tempOption;

		//store the elements in a aray
		this.optionElements=new Array();
		//delete the select box childeren
		$(this.id).empty();
		for(var i=0;i<this.myElementHTML.length-1;i++){
			this.optionElements[i]= new Element( 'option', {
			'value': this.getValue(i)
			});
			//set the text for the new option
			this.optionElements[i].setText(this.getText(i));
			//insert the new option into the selectbox
			this.optionElements[i].injectInside(this.id);	
		}
	};

	//show if the the string with options is passed for testing purposes
	this.getOptionsHTML=function(){
		alert(this.optionsHTML);
	};

	//splits every option and places it in its own array adress still a string though
	this.splitSingleElements=function(){

		//splits into array with the following accurance
		var seperator='<option';
		this.myElementHTML = this.optionsHTML.split(seperator);
		//needs to start with one because the first array value sucks ass
		for (var i = 1; i < this.myElementHTML.length; i++) 
		{
			this.myElementHTML[i-1]='<option'+this.myElementHTML[i];
			//alert(this.myElementHTML[i-1]);
		}
	};

	/*gets all the values from the options stored in a string more as a private function
	this is used in a loop so the arrayId will equal i*/
	this.getValue=function(arrayId){
		/*seperates where the double quotes are this means 
		*Note the values can not be pass with single quotes so value='1' will not work*/
		var seperator='"';
		//split the option html string into piecies in a temp var
		var tempString=this.myElementHTML[arrayId].split(seperator);

		//extract the value in the option tag which is the middle array value 1
		var elementValue=tempString[1];

		//alert(elementValue);
		return elementValue;
	};

	//gets the text for the option tag this is used in a loop so the arrayId will equal i
	this.getText=function(arrayId){
		//seperates the single option string into pieces... yeah i know again
		var seperator='>';
		var seperator2='<';
		//split the option html string into piecies in a temp var
		var tempString=this.myElementHTML[arrayId].split(seperator);
		//finally filter out the text whats in the option
		tempString=tempString[1].split(seperator2);

		//the element text
		var elementText=tempString[0];

		//alert(elementText);
		return elementText;
	}
};