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();
		});
var szNormal = 248, szSmall  = 152, szFull   = 441;
var kwicks = $$("#kwicks .kwick");
var fx = new Fx.Elements(kwicks, {wait: false, duration: 400, transition: Fx.Transitions.Quint.easeInOut});
kwicks.each(function(kwick, i) {
	kwick.addEvent("mouseenter", function(event) {
		var o = {};
		o[i] = {width: [kwick.getStyle("width").toInt(), szFull]}
		kwicks.each(function(other, j) {
			if(i != j) {
				var w = other.getStyle("width").toInt();
				if(w != szSmall) o[j] = {width: [w, szSmall]};
			}
		});
		fx.start(o);
	});
});

$("kwicks").addEvent("mouseleave", function(event) {
	var o = {};
	kwicks.each(function(kwick, i) {
		o[i] = {width: [kwick.getStyle("width").toInt(), szNormal]}
	});
	fx.start(o);
});

$("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();
	/*alert(url1);
	alert(url2);
	
	* The simple way for an Ajax request, use onRequest/onComplete/onFailure
	* to do add your own Ajax depended code. update: $("classificacao")
	*/ 
	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();
	/*alert(url2);
	
	* The simple way for an Ajax request, use onRequest/onComplete/onFailure
	* to do add your own Ajax depended code. update: $("classificacao")
	*/ 
	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();	
		}
});

//var goSwimming = swimming.pass($('janela')).periodical(2100);
//	goSwimming();
});

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;
	}
};

//function swimming(swimbox){
//	var floatingFX = new Fx.Styles(swimbox, {duration: 2000, transition: Fx.Transitions.backInOut});
//	var swimX = swimbox.getStyle('width').toInt();
//	var swimY = swimbox.getStyle('height').toInt();
//	var maxX = $('outerbox').getStyle('width').toInt()-swimX;
//	var maxY = $('outerbox').getStyle('height').toInt()-swimY;
//	var currentX = swimbox.getStyle('left').toInt();
//	var currentY = swimbox.getStyle('top').toInt();
//	var aimingX = Math.random()*maxX-currentX;
//	var aimingY = Math.random()*maxY-currentY;
//	var vectorlength = Math.sqrt(aimingX*aimingX+aimingY*aimingY);
//	var swimFactor = Math.random();
//	var targetX = Math.round(swimFactor*swimX*(aimingX/vectorlength)+currentX);
//	var targetY = Math.round(swimFactor*swimY*(aimingY/vectorlength)+currentY);
//		floatingFX.start({
//    	'left': [currentX, targetX],
//    	'top': [currentY, targetY],
//		'opacity': 0.6+Math.random()*0.4
//		});
//	}