var HotelPoint = new Array();
var IpPoint = new Array();
var structureLink = new Array();
var imageMarker = "/images_fortravel/iconMini.png";
var imageMarkerOver = "/images_fortravel/iconMini.png";
var imageMarkerIp = "/images_fortravel/ip.gif";

function printImgStructureList(portal){
	var searchHotel = $("#hotel_consigliati"); 
    var myprev = $(".structure_img",searchHotel);
    if (myprev.length > 0) {
    	myprev.each(function(i){
	        var myImg = this;
			myImgId = this.id;
			imgLink = 	structureImg[myImgId];
			var img = new Image();
			
			var structLink = structureLink[myImgId];
			var anchor = $( "<a></a>" ).attr({
				"href": structLink
			});
			
			$(img).load(function (){
				anchor.append( this );
				$(this).hide();
				var alink = $(myImg).parent();
				$(myImg).removeClass('img_structure').html(anchor);
				$(this).fadeIn(700);
			})
			.error(function(){
				noimage = "/images_fortravel/no_preview_mini.jpg";
				$(img).attr('src',noimage);
			})
			.attr('src',imgLink);
        });
    }
}

function loadIpMap() {
	var $name = "",
		$rating = "",
		$photo = "",
		$description = "";
	
	var markerBounds = new google.maps.LatLngBounds();  
    var myOptions = {
      zoom: 11,
      backgroundColor: '#ffffff',
      mapTypeId: google.maps.MapTypeId.HYBRID //ROADMAP - SATELLITE - HYBRID - TERRAIN 
    };
    var maps = new google.maps.Map(document.getElementById("googlemap"), myOptions);
	
	for (i=0; i<HotelPoint.length; i++){
		if ((HotelPoint[i]['lat'] != 0) && (HotelPoint[i]['lon'] != 0 )) {
			var myLatLng = new google.maps.LatLng(HotelPoint[i]['lat'], HotelPoint[i]['lon']);
			markerBounds.extend(myLatLng);
			
			var iWindowHTML = "";
			
			if ( HotelPoint[i]['title'] != "" && HotelPoint[i]['rating'] != "" && HotelPoint[i]['photo'] != "" && HotelPoint[i]['description'] != "" ) {
				iWindowHTML = '<div class="hotel"><h2>' + HotelPoint[i]['title'] + ' <img class="star" src="/images_fortravel/star' + HotelPoint[i]['rating'] + '.png"/></h2><div><img src="' + HotelPoint[i]['photo'] + '"/><p>' + HotelPoint[i]['description'] + '</p></div></div>';
			}
			
			if ( iWindowHTML != "" ) {
				var marker = new google.maps.Marker({
					position: myLatLng,
					map: maps,
					icon: imageMarker,
					zIndex: i,
					mydiv: iWindowHTML
				});
				google.maps.event.addListener( marker, 'mouseover', function() {
					this.setZIndex( i );
					infoBox = new InfoBox({
						latlng: this.position,
						map: maps,
						html: this.mydiv,
						offsetV: -135,
						offsetH: -100,
						height: 90,
						width: 220
					});
				});
				google.maps.event.addListener( marker, 'mouseout', function() {
					this.setZIndex( i );
					infoBox.setMap( null );
				});
			}
			else {
				var marker = new google.maps.Marker({
					position: myLatLng,
					map: maps,
					icon: imageMarker,
					title: HotelPoint[i]['title'],
					zIndex: i
				});
				google.maps.event.addListener(marker, 'mouseout', function() {
					this.setZIndex(i);
					this.setIcon(imageMarker);
				});
				google.maps.event.addListener(marker, 'mouseover', function() {
					this.setZIndex(12);
					this.setIcon(imageMarkerOver);
				});
			}
		}
	}
	
	for (i=0; i<IpPoint.length; i++){
		if ((IpPoint[i]['lat'] != 0) && (IpPoint[i]['lon'] != 0 )) {
			var myLatLng = new google.maps.LatLng(IpPoint[i]['lat'], IpPoint[i]['lon']);
			
			if (HotelPoint.length == 0) {
				markerBounds.extend(myLatLng);
			}
			
			var marker = new google.maps.Marker({
				position: myLatLng,
				map: maps,
				icon: imageMarkerIp,
				title: IpPoint[i]['title'],
				zIndex: i
			});
			google.maps.event.addListener(marker, 'mouseout', function() {
				this.setZIndex(i);
				this.setIcon(imageMarkerIp);
			});
			google.maps.event.addListener(marker, 'mouseover', function() {
				this.setZIndex(12);
				this.setIcon(imageMarkerIp);
			});
		}
	}
	
	maps.fitBounds(markerBounds);
}

function showRecommendedLi(cssclass){
	
	$(cssclass).css('display','block');
	$('.allplaceslinkrecommended').css('display','none');
	
}

/**
 * funzione link per senza prima parte
 * @param stid
 * @param other
 * @return
 */
function goMinisiteLink(stid,other){
	url = minisite_link_url+'/minisite/minisite.php?stid='+stid+'&'+other;
	
	document.location.href = url;
}


function shadowRel(){
	
	$('.shadowbox').each(function(){
		params = $(this).attr('class').split('_');

		gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
		width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
		height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
		
		
		$(this).attr('rel', 'shadowbox'+gallery+width+height);
	});
    
}
