/* **********************
   Event Handlers
   These are my custom event handlers to make my
   web application behave 
   ********************** */
function ajaxpesquisaimoveldetalhe(aoCodigo,aoImoCli,sSource) {
			this.aoData = [];
			aoData.push( { "name": "imocli", "value": aoImoCli });
			aoData.push( { "name": "codigo", "value": aoCodigo } );
			var jqxhr  = jQuery.ajax( {
				"dataType": 'json', 
				"url": sSource, 
				"data": aoData, 
				success: function(dados){
					var textToInsert = [];				
					var textToInsert1 = [];
					var textToInsert2 = [];
					var textToInsert3 = [];
					var i = 0;
					var x = 0;		
					var z = 0;
					botao='<input name="submit" src="/site/includes/qss/images/bt_voltar.gif" type="image" width="61" onclick="limpaareas()">';
					favorito="<input name='favorito' src='/site/includes/qss/images/favoritobempequeno.png' type='image' onclick='callfavorito(";
					favorito+='"'+aoCodigo+'","'+aoImoCli+'"' + ")'>";
//					favorito='<input name="button" src="/site/includes/qss/images/favoritopequeno.png" type="image" onclick="callfavorito()">';					
					// Atendimento Online					
					if (dados.loja == 1) {
					   botao1= "<a href=\"javascript:void(window.open('http://www.a3imoveis.com.br/livezilla/chat.php?intid=bW9pbmhvcw__&amp;hg=P1pvbmFTdWw_','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes')) \">";
					   botao1+='<img src="http://www.a3imoveis.com.br/livezilla/image.php?id=05&amp;type=inlay&amp;hg=P1pvbmFTdWw_" width="168" height="47" border="0" alt="Atendimento OnLine"></a>';						
					} else if (dados.loja == 2) {
					   botao1= "<a href=\"javascript:void(window.open('http://www.a3imoveis.com.br/livezilla/chat.php?intid=em9uYXN1bA__&amp;hg=P21vaW5ob3M_','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes')) \">";
					   botao1+='<img src="http://www.a3imoveis.com.br/livezilla/image.php?id=05&amp;type=inlay&amp;hg=P21vaW5ob3M_" width="168" height="47" border="0" alt="Atendimento OnLine"></a>';
					}   
					else {
					   botao1= "<a href=\"javascript:void(window.open('http://www.a3imoveis.com.br/livezilla/chat.php','','width=590,height=610,left=0,top=0,resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes')) \">";
					   botao1+='<img src="http://www.a3imoveis.com.br/livezilla/image.php?id=05&amp;type=inlay" width="168" height="47" border="0" alt="Atendimento OnLine"></a>';					   
					}	
					
					botao2 = '<div class="addthis_toolbox addthis_default_style addthis_32x32_style">';
					botao2 += '<a class="addthis_button_preferred_1"></a>';
					botao2 += '<a class="addthis_button_preferred_2"></a>';
					botao2 += '<a class="addthis_button_preferred_3"></a>';
					botao2 += '<a class="addthis_button_preferred_4"></a>';
					botao2 += '<a class="addthis_button_compact"></a>';
					botao2 += '<a class="addthis_counter addthis_bubble_style"></a></div>';
//					botao2 = '{module AddThis}';
					jQuery('#retornoid').append('<div id="livezilla_tracking" style="display:none"></div>');
					var script = document.createElement("script");
					script.type="text/javascript";
					var src = "http://www.a3imoveis.com.br/livezilla/server.php?request=track&output=jcrpt&nse="+Math.random();
					setTimeout("script.src=src;document.getElementById('livezilla_tracking').appendChild(script)",1);
					jQuery('#retornoid').append('<img src="http://www.a3imoveis.com.br/livezilla/server.php?request=track&amp;output=nojcrpt" width="0" height="0" style="visibility:hidden;" alt="">');
					// Fim Antedimento Online
					
//					lupa="<img src='/components/com_pesquisaimovel/assets/images/lupa.gif' width='31' height='19' border='0'>";
					// Escondendo as DIVs
					jQuery('#divpos2').hide();
					jQuery('#divpos3').hide();
	    			jQuery('#retornoid').empty();
	    			jQuery('#retornoid').append('<h1>Detalhe Imóvel - Código: ' + dados.codigo_imovel + '</h1><br>');
//	    			jQuery('#retornoid').append(botao+'<br>');
				    textToInsert[i++]  = '<h2>R$ ' + dados.preco_imovel +'</h2>';
				    textToInsert[i++]  = '<h3>' + dados.tipo_imovel + '</h5>';
				    textToInsert[i++] = '<h3>Bairro:' + dados.bairro + '</h5>';
	    			jQuery('#retornoid').append('<div class="divesquerda" id="divesquerda"></div>');
					jQuery('#divesquerda').append(textToInsert.join(''));
					textToInsert = [];
					i = 0;
		    		textToInsert[i++] = '<h2>' + dados.cidade + '</h2>';
				    textToInsert[i++] = '<h3>Área priv:' + dados.areaprivativa_imovel+'m2</h5>';
		    		textToInsert[i++] = '<h3>Área total:' + dados.areatotal_imovel+'m2</h5>';
	    			jQuery('#retornoid').append('<div class="divdireita" id="divdireita"></div>');
					jQuery('#divdireita').append(textToInsert.join(''));
	    			for (var a = 0; a <dados.qtd_fotos; a += 1) {
		  				textToInsert1[x++] = '<a href="'+dados.fotos_url[a]+'" title="'+dados.fotos_nome[a]+'"><img src="'+dados.fotos_url[a]+'" alt="'+dados.fotos_nome[a]+'" width="160" height="120"/></a>';
		  				textToInsert2[x++] = '<img src="'+dados.fotos_url[a]+'" alt="'+dados.fotos_nome[a]+'" title="'+dados.fotos_nome[a]+'"/>';
	    			}										
					// Initialize Tabela com dados
//				    jQuery('#detalheimovelajax').append('<tbody>' + textToInsert.join('') + '</tbody>');
				 // Initialize MakeScrollable -- É Somente descomentar para funcionar 
/*				    jQuery('#retornoid').append('<div id="makeMeScrollable"></div>');
				    jQuery('#makeMeScrollable').append('<div class="scrollingHotSpotLeft"></div>');
				    jQuery('#makeMeScrollable').append('<div class="scrollingHotSpotRight"></div>');				    
				    jQuery('#makeMeScrollable').append('<div class="scrollWrapper"></div>');				    
				    jQuery('.scrollWrapper').append('<div class="scrollableArea"></div>');	
				    jQuery('.scrollableArea').append(textToInsert1.join(''));
				    jQuery("div#makeMeScrollable").smoothDivScroll({
				    	autoScroll: "onstart" ,
						autoScrollDirection: "backandforth", 
						autoScrollStep: 1, 
						autoScrollInterval: 15,	 
						visibleHotSpots: "always"
					});		
				    jQuery("div#makeMeScrollable").smoothDivScroll('startAutoScroll');
				    jQuery("div#makeMeScrollable a").lightBox();
*/
				    textToInsert3[z++]  = dados.descricao_imovel+'<br><br>';
				    textToInsert3[z++]  = botao+'    '+favorito+'    '+botao1;
//				    textToInsert3[z++]  = '<p>'+botao1+'</p>';
				    textToInsert3[z++]  = botao2;				   
	    			jQuery('#retornoid').append('<div class="divdescesquerda" id="divdescesquerda"></div>');
					jQuery('#divdescesquerda').append('<div id="galleria"></div>');
				    jQuery('#galleria').append(textToInsert2.join(''));				    
				    jQuery('#galleria').galleria({width:500,height:400,fullscreenCrop:true});
	    			jQuery('#retornoid').append('<div class="divdescdireita" id="divdescdireita"></div>');
					jQuery('#divdescdireita').append(textToInsert3.join(''));
				    scroll(0,280);				    
				}
			});
}

function limpaareas() {
	jQuery('#retornoid').empty();
	jQuery('#divpos2').show();
	jQuery('#divpos3').show();	
	scroll(0,0);
}

function callfavorito(aoCodigo,aoImoCli) {	
	this.aoData = [];
	aoData.push( { "name": "imocli", "value": aoImoCli });
	aoData.push( { "name": "codigo", "value": aoCodigo });
	sSource = "http://www.a3imoveis.com.br/site/index.php?option=com_pesquisaimovel&format=raw&task=setaImovelFavorito";
	var jqxhr  = jQuery.ajax( {
		"dataType": 'json', 
		"url": sSource, 
		"data": aoData
	} ); 	
}
