/*** My code  ***/
var geocoder = null;
var map = null;
var mapdemo = null;
var infowindow = new google.maps.InfoWindow();
var markersArray = [];
var site_uri = "http://www.tanquecheio.com.br";
var position = new google.maps.LatLng(-23.5367834, -46.5755327);  //nearby sao paulo
var loadPostos = false;
var mapPainel = null;
var toolbar = null;
var store = null;
var list_mode = false;
var search = null;
var user_login = null;
/********************************************************************/
Ext.gesture.Manager.onMouseEventOld = Ext.gesture.Manager.onMouseEvent;
Ext.gesture.Manager.onMouseEvent = function(e) {
	var target = e.target;
	while (target) {
		if (Ext.fly(target) && Ext.fly(target).hasCls('x-map')) {
		return;
	}
	target = target.parentNode;
}
this.onMouseEventOld.apply(this, arguments);
};


Ext.setup({
    tabletStartupScreen: site_uri+'/img/tablet_startup.png',
    phoneStartupScreen: site_uri+'/img/phone_startup.png',
    icon: site_uri+'/img/icon.png',
    glossOnIcon: false,
    onReady: function() {
		//Tracking Marker Image
        image = new google.maps.MarkerImage(
            '/img/person_yellow.png',
            new google.maps.Size(32, 31),
            new google.maps.Point(0,0),
            new google.maps.Point(16, 31)
          ),
        /*shadow = new google.maps.MarkerImage(
            'shadow.png',
            new google.maps.Size(64, 52),
            new google.maps.Point(0,0),
            new google.maps.Point(-5, 42)
          ),*/

            trackingButton = Ext.create({
               xtype   : 'button',
               iconMask: true,
               iconCls : 'locate'
            } ),

            toolbar = new Ext.Toolbar({
                    dock: 'top',
                    xtype: 'toolbar',
                    ui : 'light',
                    defaults: {
                        iconMask: true
                    },
                    items : [
                    {
                      position : position,
                      iconCls  : 'home',
                      handler : function(){
                      //disable tracking
                          //trackingButton.ownerCt.setActive(trackingButton, false);
                          //mapdemo.map.panTo(this.position);
						  mapMode();
						  clearOverlays();
						  placeMarker(position);
                      }
                    },{
                   		xtype : 'segmentedbutton',
                   		allowMultiple : true,
		                   listeners : {
		                       toggle : function(buttons, button, active){
								  mapMode();
		                          if(button.iconCls == 'maps' ){
		                              mapdemo.traffic[active ? 'show' : 'hide']();
		                          }else if(button.iconCls == 'locate'){
									  // Ao clicar no tracking... alert(position.lat() + ',' + position.lng()) ;
									  loadPostos = true;
									  loadData(position,false);
		                              mapdemo.geo[active ? 'resumeUpdates' : 'suspendUpdates']();
		                          }
		                       }
		                   },
		                   items : [
		                        trackingButton,
		                            {
		                                   iconMask: true,
		                                   iconCls: 'maps'
		                                }
		                   ]
                	},
					{
                      position : position,
                      iconCls  : 'search',
                      handler: function(btn){
					     search.showBy(btn);
					  }
					},
					{
                      position : position,
                      iconCls  : 'user',
                      handler: function(btn){
					     user_login.showBy(btn);
					  }
                    },
					{
					  	text: 'Lista',
				        ui: 'forward',
						//iconCls  : 'more',
				        handler: function(btn){
							//var txt = "User tapped the '" + btn.text + "' button.";
						    //Ext.getCmp('mappanel').body.dom.innerHTML = txt;
							changeToListPanel(12);
						}
                    }]
                });
			// popup
			search = new Ext.Panel({
			    floating: true,
	            centered: true,
	            modal: true,
	            width: 200,
	            height: 200,
	            styleHtmlContent: true,
	            html: 'Endereco:<input id="address" type="textbox" value="Rua Tuiuti, Sao Paulo"><br><!--select size="1" id="combustivel" name="combustivel"><option selected value="12">Gasolina</option><option value="29">Etanol</option><option value="34">Diesel</option><option value="15">GNV</option><option value="36">GLP</option></select--><br>Proximos + baratos<INPUT TYPE="CHECKBOX" NAME="barato" id="barato"><BR>',
	            dockedItems: [{
	                xtype: 'toolbar',
	                title: '',
	                items: [{
	                    xtype: 'spacer'
	                },{
	                    text: 'Enviar',
	                    handler: function(){
	                        processar();
							search.hide();
	                    }
	                }]
	            }]
	        });
			user_login = new Ext.Panel({
			    floating: true,
	            centered: true,
	            modal: true,
	            width: 200,
	            height: 200,
	            styleHtmlContent: true,
	            html: 'E-mail:<input type="text" id="user"/><br>Senha:<input type="password" id="password"/>',
	            dockedItems: [{
	                xtype: 'toolbar',
	                title: '',
	                items: [{
	                    xtype: 'spacer'
	                },{
	                    text: 'Enviar',
	                    handler: function(){
	                        user_login.hide();
	
	                    }
	                }]
	            }]
	        });


        mapdemo = new Ext.Map({
	    // get updates
		geo:new Ext.util.GeoLocation({
		  autoUpdate:false,
		  timeout:2000,
		  listeners:{
		    locationupdate: function(geo) {
		      	center = new google.maps.LatLng(geo.latitude, geo.longitude);
				position = center;
				if(loadPostos){
					loadData(geo.latitude + ',' +geo.longitude,false); // Carrega posicao inicial
				}
		    },
		    locationerror: function(geo){
		      // Se nao achar localizacao fixa um ponto
		      /*var position = new google.maps.LatLng(-23.5367834, -46.5755327);  //Sao paulo
		      if (map.rendered)
		        map.update(position);
		      else
		        map.on('activate', map.onUpdate, map, {single: true, data: position});
			  */
		      //alert('got geo error');  
		      //loadData(position,false);        
		    }
		  }
		}),
	    //--end get updates.
            mapOptions : {
                center : new google.maps.LatLng(-23.5367834, -46.5755327),  //nearby sao paulo
                zoom : 12,
                mapTypeId : google.maps.MapTypeId.ROADMAP,
                navigationControl: true,
			    panControl: false,
			    zoomControl: false,
			    scaleControl: false,
			    mapTypeControl: false,
                navigationControlOptions: {
                        style: google.maps.NavigationControlStyle.DEFAULT
                    }
            },

            plugins : [
                new Ext.plugin.GMap.Tracker({
                        trackSuspended : true,   //suspend tracking initially
                        highAccuracy   : false,
                        marker : new google.maps.Marker({
                            position: position,
                            title : 'Minha Localização',
                            //shadow: shadow,
                            icon  : image
                          }),
						
                }),
                new Ext.plugin.GMap.Traffic({ hidden : true })
            ],

            listeners : {
                maprender : function(comp, mapa){
                    setTimeout( function(){ mapa.panTo (position); } , 1000);
					//loadData(position,false); // Carrega posicao inicial
					geocoder = new google.maps.Geocoder();
					google.maps.event.addListener(mapa, 'click', function(event) { // Ativa click no mapa.
						placeMarker(event.latLng);
					});
					
					map = mapa;
					if (Ext.is.Phone || Ext.is.iPad) {
						// load mobile adsense

					}else{
						// load desktop adsense
						var adUnitDiv = document.createElement('div');
						var adUnitOptions = {
					    	format: google.maps.adsense.AdFormat.BUTTON,
						    position: google.maps.ControlPosition.BOTTOM_RIGHT,
						    map: mapa,
						    visible: true,
						    publisherId: 'ca-pub-3386097717200517'
					    }
						adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
					}
                }
            }
        });

        mapPainel = new Ext.Panel({
			id: 'mappanel',
            fullscreen: true,
            dockedItems: [toolbar],
            items: [mapdemo]
        });
    }
});

/*** My code  ***/
function mapMode(){
	if (list_mode){
		mapPainel.removeAll();
		mapPainel.toggleColumn(0);
		mapPainel.toggleColumn(1);
		mapPainel.toggleColumn(2);
		mapPainel.toggleColumn(3);
//		mapPainel.toggleColumn(4);
//		mapPainel.toggleColumn(5);
//		mapPainel.toggleColumn(6);
		mapPainel = new Ext.Panel({
			id: 'mappanel',
            fullscreen: true,
            dockedItems: [toolbar],
            items: [mapdemo],
			colModel: [{}]
        });
		list_mode = false;
	}
	mapPainel.doLayout();
}

function loadList(combustivel){
	list_mode = true;
	var url_json = site_uri + "/list.php";
	
	if(combustivel == 0){
		combustivel = 12;
		if($('#combustivel') > 0){
			combustivel = $('#combustivel').val();
		}
	}
	url_json += "?geocode="+position+"&barato=false&combustivel="+combustivel;
	
	Ext.regModel('Postos', {
        fields: ['nome', 'endereco', 'nome_endereco',{name:'preco', type: 'float'},{name:'precogasolina', type: 'float'}, {name:'precoetanol', type: 'float'},{name:'ultima_atualizacao', type:'string'},{name:'distancia', type: 'string'},'geocode']
    });

	if(mapPainel.store == null){
    	store = new Ext.data.Store({
		    model : 'Postos',
		    proxy: {
		        type: 'ajax',
		        url : url_json, //'http://www.combustivel.me/home/map_json.php?geocode=(-23.548943,%20-46.638818000000015)&barato=false&combustivel=1',
		        reader: {
		            type: 'json',
		            root: 'collection'
		        }
		    },
		    autoLoad: false
		});
		mapPainel.store = store;
	}
	mapPainel.store.proxy.url = url_json;
	mapPainel.store.load();
	//mapPainel.refresh();
	//mapPainel.doLayout();
	//mapPainel.update();
	//Ext.StoreMgr.get('store').load()
}

function changeToListPanel(combustivel){
	loadList(combustivel)
	
	toolbarList = new Ext.Toolbar({
            dock: 'top',
            xtype: 'toolbar',
            ui : 'light',
            defaults: {
                iconMask: true
            },
            items : [
            {
			  	text: 'Mapa',
		        ui: 'back',
		        handler: function(btn){
					mapMode();
				}
            },{
              	text: 'Gasolina',
		        ui: 'action',
		        handler: function(btn){
					loadList(12);
				var el = btn.el;

				el.removeCls("x-button-action");
				//el.removeCls("x-button-confirm");
				//el.addCls("x-button-decline");
				el.addCls("x-button-confirm");
				}
            },{
              	text: 'Alcool',
		        ui: 'action',
		        handler: function(btn){
					loadList(29);
                                var el = btn.el;

                                el.removeCls("x-button-action");
                                //el.removeCls("x-button-confirm");
                                //el.addCls("x-button-decline");
                                el.addCls("x-button-confirm");

				}
            },{
              	text: 'GNV',
		        ui: 'action',
		        handler: function(btn){
					loadList(15);
                                var el = btn.el;

                                el.removeCls("x-button-action");
                                //el.removeCls("x-button-confirm");
                                //el.addCls("x-button-decline");
                                el.addCls("x-button-confirm");

				}
/*            },{
	            text: 'D.',
		        ui: 'action',
		        handler: function(btn){
					loadList(36);
				}*/
	        },{	
              	text: 'Busca',
		        ui: 'normal',
              	handler: function(btn){
			     search.showBy(btn);
			  	}
			}/*,{
              	text: 'Login',
		        ui: 'normal',
              	handler: function(btn){
			     user_login.showBy(btn);
			  	}
            }*/]
        });
	
	
	mapPainel = new Ext.ux.TouchGridPanel({
		fullscreen  : true,
		store       : store,
		multiSelect : false,
		dockedItems: [toolbarList],
		colModel    : [{
			header   : "Posto",
			mapping  : "nome_endereco",
			style    : "font-size:10px;",
			flex     : 3
		},{
			header   : "R$",
			mapping  : "preco",
			style    : "text-align: right;font-size:10px;",
			renderer : function(val) {
			    return val.toFixed(3);
			}
		},{
			header   : "Data",
			mapping  : "ultima_atualizacao",
			hidden   : false,
			style    : "text-align: right;font-size:10px;"
		},{
			header   : "Km",
			mapping  : "distancia",
			style    : "text-align: right;font-size:10px;",
			renderer : function(val) {
				var color = (val < 3) ? "00FF00" : "FF0000";
				return "<span style='color: #" + color + ";text-align: right;'> " + val + "</span>";
			}
		},{
			header   : "",
			mapping  : "geocode",
			hidden   : false,
			style    : "text-align:center;font-size:10px;",
			//cls      : "centered-cell",
			renderer : function(val) {
				var geocode = val.split(",");
				return '<img src="/img/gas_red.png" onclick="javascript: placeGasMarker(' +geocode[0]+ ',' +geocode[1]+ ');" />';
			}
		}],
		listeners: {
			beforeselect: function(dataview, nodes, selections) {
				console.log(selections);
			},
			containertap: function(dataview, e) {
				console.log(dataview);
			},
			itemdoubletap: function(dataview, index, el, e) {
				console.log(index);
			},
			itemswipe: function(dataview, index, el, e) {
				console.log(index);
			},
			itemtap: function(dataview, index, el, e) {
				console.log(index);
				//alert(index);
				//dataview.toggleColumn(index);
				//if (e.getTarget('div.button')) {
				        var posto = mapPainel.store.getAt(index);
						alert(posto.data.geocode);
				        //Cart.add(product);
				        //Cart.sync();
				//}
			},
			selectionchange: function(selectionModel, selections) {
				console.log(selections);
			}
		}
	});
}

var customIcons = {
  blue: {
    icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  refresh: {
    icon: '/img/gas_red.png',
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  old:{
	icon: '/img/gas_gray.png',
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_gray.png'
  }
};



function load(geocode) {
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(-23.5367834, -46.5755327);
	var myOptions = {
  		zoom: 3,
  		center: latlng,
  		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
	if (geocode != '' && geocode != null){
		loadData(geocode,false); 
	}
	
	google.maps.event.addListener(map, 'click', function(event) {
		placeMarker(event.latLng);
	});
	//loadData('-23.5367834,-46.5755327');          
}               

function placeMarker(location) {
	loadData(location,false);
	mapdemo.map.setCenter(location);
	geocoder.geocode({'latLng': location}, function(results, status) {
	    if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
          	marker = new google.maps.Marker({
              	position: location,
				icon:'/img/person_yellow.png',
              	map: mapdemo.map
          	});
			
          	infowindow.setContent(results[0].formatted_address);
          	infowindow.open(mapdemo.map, marker);
			bindInfoWindow(marker, mapdemo.map, infowindow, results[0].formatted_address);
        }
      } else {
        alert("Geocoder failed due to: " + status);
      }
    });	
}

function placeGasMarker(lat,lng) {
	clearOverlays();
	mapMode();
	var location = new google.maps.LatLng(
    parseFloat(lat),
    parseFloat(lng));
	//mapdemo.map.setCenter(location);
	geocoder.geocode({'latLng': location}, function(results, status) {
	    if (status == google.maps.GeocoderStatus.OK) {
        if (results[1]) {
          	marker = new google.maps.Marker({
              	position: location,
				icon:'/img/gas_red.png',
              	map: mapdemo.map
          	});
			
          	infowindow.setContent(results[0].formatted_address);
          	//infowindow.open(mapdemo.map, marker);
			bindInfoWindow(marker, mapdemo.map, infowindow, results[0].formatted_address);
        }
      } else {
        alert("Geocoder failed due to: " + status);
      }
    });	
	mapdemo.map.setZoom(15);   
}



function loadData(geocode,barato){
    //var infoWindow;
	var url = site_uri + "/map_json.php";
	var combustivel = 12;
	if($('#combustivel') > 0){
		combustivel = $('#combustivel').val();
	}
	url += "?geocode="+geocode+"&barato="+barato+"&combustivel="+combustivel;
	loadMsg('Carregando postos....');
	var count =0;
	$.getJSON(url,function(data) {
	    $.each(data.collection, function(i,posto){
			var type = posto.tipo;
	        var point = new google.maps.LatLng(
	        parseFloat(posto.lat),
	        parseFloat(posto.lng));
			// New Infowindow
			//infoWindow = createInfo("Auto Posto Avenida Brasil", "Av. Brasil, 250", "3", "2.53", "1.82", "1.96", "N/A", "Etanol", "Shell");
			//function createInfo(nome, endereco, nota, gasolina, etanol, diesel, gnv, melhorOpcao, bandeira) {
			var infoWindow = new google.maps.InfoWindow;
			infoWindow = createInfo(posto.nome, posto.endereco, "3", posto.precogasolina, posto.precoetanol, posto.precodiesel, posto.precognv, "Etanol", posto.bandeira,posto.ultima_atualizacao);
			
	
	
	        //var html = "<b>" + posto.nome + "</b> <br/>" + posto.endereco+"<br/>("+posto.ultima_atualizacao+")";
		    /*
			var infoHtml = 		  "<div class='geral'><div><img src='" + posto.bandeira + "'/></div>";
			infoHtml = infoHtml + "<div><h1 class='titulo'>" + posto.nome + "</h1></div>";
			infoHtml = infoHtml + "<div><h2 class='endereco'>" + posto.endereco+"</h2></div>";
			infoHtml = infoHtml + "<div><h2 class='avaliacao'>";
			infoHtml = infoHtml + "		<ul class='rating nostar'>";
			infoHtml = infoHtml + "			<li class='one'><a href='#' title='1 Star'>1</a></li>";
			infoHtml = infoHtml + "			<li class='two'><a href='#' title='2 Stars'>2</a></li>";
			infoHtml = infoHtml + "			<li class='three'><a href='#' title='3 Stars'>3</a></li>";
			infoHtml = infoHtml + "			<li class='four'><a href='#' title='4 Stars'>4</a></li>";
			infoHtml = infoHtml + "			<li class='five'><a href='#' title='5 Stars'>5</a></li>";
			infoHtml = infoHtml + "		</ul>";
			infoHtml = infoHtml + "</h2></div>";
			infoHtml = infoHtml + "<div><h2 class='precos'>G: "+posto.precogasolina+" |  E: "+posto.precoetanol+" | D: "+posto.precodiesel+" | GNV: "+posto.precognv+"</h2></div>";
			infoHtml = infoHtml + "<div class='img_bottom'>";
			infoHtml = infoHtml + "	<img src='/img/icone_facebook.png' width='20' height='20' />";
			infoHtml = infoHtml + "	<img src='/img/icone_twitter.png' width='20' height='20' />";
			infoHtml = infoHtml + "</div></div>";
			*/
	
	        var icon = customIcons[type] || {};
			var labelText = "---";
			if(posto.precogasolina !== '---' && posto.precoetanol !== '---'){
				labelText =  "G: "+posto.precogasolina+"<br/>A: "+posto.precoetanol;
			}
	
	        var marker = new MarkerWithLabel({
			    position: point,
		        draggable: false,
		        raiseOnDrag: false,
			    map: mapdemo.map,
				//icon: icon.icon,
				icon: posto.bandeira,
	        	shadow: icon.shadow,
			    labelContent: labelText,
			    labelAnchor: new google.maps.Point(22, 0),
			    labelClass: "labels", // the CSS class for the label
			    labelStyle: {opacity: 0.75}
			});
			markersArray.push(marker);
			
	        //bindInfoWindow(marker, mapdemo.map, infoWindow, infoHtml,posto.id);
			if(data.collection.length <= count){
				count++;
			}else{
				hideMsg();
			}
			
			//  Add Marker
			google.maps.event.addListener(marker, 'mousedown', function() {
				infoWindow.open(mapdemo.map, marker);
			});
			
			
	    });         
	  });
	mapdemo.map.setZoom(15);   
}
/*
Insere dados do banco no info window.
*/
function bindInfoWindow(marker, map, infoWindow, html,posto_id) {
	//google.maps.event.addListener(marker, 'click', function() { // click doesn't work in mobiles.
	google.maps.event.addListener(marker, 'mousedown', function() {
		var combustivel = 12;
		if($('#combustivel') > 0){
			combustivel = $('#combustivel').val();
		}
		var url = site_uri + "/preco_json.php";
		url += "?id="+posto_id+"&combustivel="+combustivel;
		var found = false;
    	/*$.getJSON(url,function(posto) {
				$.each(posto.precos, function(i,preco){
					html += "<p><font size=\"1\" face=\"arial\">"+preco.nome_produto+" R$ "+preco.preco_venda + '</font></p>';
		    	});
		        infoWindow.setContent(html);
			  	infoWindow.open(mapdemo.map, marker);
			 	found = true;
		});*/
		infoWindow.setContent(html);
	  	infoWindow.open(mapdemo.map, marker);
		found = true;
		if(!found){	
			infoWindow.setContent(html);
	  		infoWindow.open(mapdemo.map, marker);
		}
		});
	
}

function doNothing() {alert('aq');}

// Find location by address
function find_endereco(barato) {
	loadPostos = true;
	clearOverlays();
	// Desabilita tracking
	mapdemo.geo['suspendUpdates']();
	var address = document.getElementById("address").value;
   	geocoder.geocode( { 'address': address}, function(results, status) {
    	if (status == google.maps.GeocoderStatus.OK) {
	    	mapdemo.map.setCenter(results[0].geometry.location);
	       	//alert(results[0].geometry.location);
	       	var marker = new google.maps.Marker({
	        	map: mapdemo.map,
	 			icon:'/img/person_yellow.png',
	           	position: results[0].geometry.location
	       	});
			position = ''+ results[0].geometry.location;
			if (list_mode){
				loadList(0);
			}else{
				loadData(''+results[0].geometry.location,barato);
			}
	    } else {
	       alert("Nao foi possivel achar o endereço: " + status);
	    }
   });
 }

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
		try{
      		markersArray[i].setMap(null);
		}catch(err){}
    }
  }
}


// New function to create info window
function createInfo(nome, endereco, nota, gasolina, etanol, diesel, gnv, melhorOpcao, bandeira,data_atualizacao) {
            var box = document.createElement("div");
            //box.style.cssText = "width:300px; height: 70px; padding: 10px; background:url('images/background.png') repeat;";
			box.style.cssText = "width:300px; height: 70px; padding: 5px;";

            var divImg = document.createElement("div");
            divImg.style.cssText = "float:left; width: 30px";
            var img = document.createElement("img");
            img.setAttribute("src", bandeira);
            img.setAttribute("title", "");
            img.setAttribute("alt", "");
            divImg.appendChild(img);
            box.appendChild(divImg);

            var divDescription = document.createElement("div");
            divDescription.style.cssText = "float:left; font-family:Calibri; font-size: 11px;";

            var divNome = document.createElement("div");
            divNome.style.cssText = "font-weight: bold;";
            divNome.innerHTML = nome;

            var divEnd = document.createElement("div");
            divEnd.innerHTML = endereco;

            //var divAvaliar = document.createElement("div");
            //divAvaliar.innerHTML = "Avaliar: " + nota;


            var divPreco = document.createElement("div");
            divPreco.innerHTML = "Gasolina: " + gasolina + "  Etanol: " + etanol + "  Diesel: " + diesel + "  GNV: " + gnv;

            var divOpcao = document.createElement("div");
            //divOpcao.innerHTML = "Aqui compensa abastecer: <b>" + melhorOpcao + "</b>";
divOpcao.innerHTML = "Aqui compensa abastecer: <b>" + melhorOpcao + "</b><br>Ult. Atualização: "+data_atualizacao;

			var divMidias = document.createElement("div");
			divMidias.innerHTML = "<a href=\"http://www.facebook.com/tanquecheio.com.br/\" target=\"_blank\"><img alt=\"\" src=\"/img/fb.png\" title=\"\" width=\"25\" height=\"25\"/></a> <a href=\"http://www.twitter.com/tanquecheio_br/\" target=\"_blank\"><img alt=\"\" src=\"/img/twitter.png\" title=\"\" width=\"25\" height=\"25\"/></a> <iframe src=\"//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.tanquecheio.com.br&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:450px; height:21px;\" allowTransparency=\"true\"></iframe>";

            divDescription.appendChild(divNome);
            divDescription.appendChild(divEnd);
            //divDescription.appendChild(divAvaliar);
            divDescription.appendChild(divPreco);
            divDescription.appendChild(divOpcao);
	    divDescription.appendChild(divMidias);
			
            box.appendChild(divDescription);

            var info = new google.maps.InfoWindow(
            {
                content: box
                //, disableAutoPan: true
			    //, maxWidth: 0
			    //, pixelOffset: new google.maps.Size(-140, 0)
			    //, zIndex: null
			    //, boxStyle: {
			      //  background: "url('images/tipbox.gif') no-repeat"
			      //, opacity: 0.75
			      //, width: "280px"
			   //}
			    //, closeBoxMargin: "10px 2px 2px 2px"
			    //, closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
			    //, infoBoxClearance: new google.maps.Size(1, 1)
			    //, isHidden: false
			    //, pane: "floatShadow"
			    //, enableEventPropagation: false
                , hasShadow : false, hasTail : false, cornerRadius : 5
			});


            return info;
        }




