// JavaScript Document

//General Overlay Collection
var overlays;

overlays = new OverlayCollection('overlays',20);
//Settings
overlays.useLabels = true;
overlays.labelType= 'Numeric';
overlays.even = false;
overlays.catIcons = false;


overlays.getIconStyle = function(placemark){
	var iconstyle = 'other';
	if(this.catIcons == false)
		return 'default';
	switch (parseInt(placemark.catid)){
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6: 
		case 21:
			iconstyle = 'hotel';
			break;
		case 8: 
		case 18:
		case 22:
			iconstyle = 'dining';
			break;
		case 9:
		case 19:
		case 23:
			iconstyle = 'shopping';
			break;
		case 10: 
		case 20:
			iconstyle = 'nightlife';
			break;
		default:
			iconstyle = 'other';
			break;
	}
	return iconstyle;
}

overlays.hidePlacemarkListingsContainer = function(){
	var container = $P('placemarkContainer');
	var list = $P('placemarkList');
	if(container == null)
		container = list;
		
	if(container != null){
		container.style.display = 'none';
	}
}

overlays.showPlacemarkListingsContainer= function(){
	var container = $P('placemarkContainer');
	var list = $P('placemarkList');
	if(container == null)
		container = list;
		
	if(container != null){
		container.style.display = '';
	}
}

//Clear Placemarks
overlays.clearPlacemarkListings = function(){
	var list = $P('placemarkList');
	this.hidePlacemarkListingsContainer();	
	if(list != null){
		list.innerHTML = '';
	}
}

//Show Placemarks
overlays.showPlacemarkListings = function(){
	this.clearPlacemarkListings();

	if(this.length > 0){
		$P('placemarkList').innerHTML = '';
		var t = document.createElement('TABLE');
		t.id = 'placemarkTable';
		t.cellPadding = '0';
		t.cellSpacing = '0';
		t.border = '0';
		t.width='100%';
		var tb = document.createElement('TBODY');
		tb.id = 'placemarkTBody';
		t.appendChild(tb);
		
		var placemarks = this.getPage(this.currPage);
		var tr = null;
		for (var i = 0; i < placemarks.length; i++){
			if(i % 2 == 0){
				tr = document.createElement('TR');
			}
			var td = document.createElement('TD');
			td.vAlign = 'top';
			td.align='center';
			td.width='50%';
			var str = this.addToList(placemarks[i]);
			td.innerHTML = str;
			tr.appendChild(td);
			if(i %2 == 1){
				tb.appendChild(tr);
				tr = null;
			}
		}
		if (tr != null)
			tb.appendChild(tr);
		$P('placemarkList').appendChild(t);
		this.showPlacemarkListingsContainer();
	}

	this.showPaging();
}


//Show Placemarks
overlays.markPlacemarkListings = function(){
	if(this.length > 0){
		var placemarks = this.getPage(this.currPage);
		for (var i = 0; i < placemarks.length; i++){
			var spot = $P('placemark_' + placemarks[i].prikey);
			if(spot != null) spot.innerHTML = parsePlacemarkData('<a href="javascript:goToPlacemark(placemark:prikey);" title="View On Map">View On Map</a><img src="placemark:sm_iconimage" width="19" height="18" align="absmiddle" style="float: none; height: 18px; margin: 0 3px; width: 19px;">', placemarks[i]);
		}
	}
}

//Clear Placemarks
overlays.unmarkPlacemarkListings = function(){
	if(this.length > 0){
		var placemarks = this.getPage(this.currPage);
		for (var i = 0; i < placemarks.length; i++){
				var spot = $P('placemark_' + placemarks[i].prikey);
			if(spot != null){				
				spot.innerHTML = '';
			}
		}
	}
}

overlays.addToList = function(placemark){
	var list = $P('placemarkList');
	var str = '';
	if(list != null){
		var d= document.createElement('div');
		str = parsePlacemarkData('<div class=\"Explorer_Listing"><div class="mapListingTop"></div><img src="placemark:iconimage" align="left"><a href="javascript:goToPlacemark(placemark:prikey)" class="explorerListingTitle">placemark:name</a><br><div class="explorerListingAddress">placemark:address</div><br><div class=\"explorerListingDescription\"></div><div class="Explorer_ListingLinks" style="background-image: none; background-color: #00adef; width: 100%;"><a title="View On Map" href="javascript:goToPlacemark(placemark:prikey);">View On Map</a><a title="More Information"  href="../listings/index.cfm?action=display&amp;listingID=placemark:prikey&amp;menuID=21&amp;hit=1">More Info</a><span id="itin_placemark:prikey"><a title="Add to Itinerary" href="javascript:itin_add(placemark:prikey);">Add to Itinerary</a></span></div><div class="mapListingBottom"></div></div>',placemark);
		overlays.even = !overlays.even;
	}
	return str;
}

/*
overlays.showPaging = function(){
	var page = this.currPage;
	var numPages = this.numPages();
	var overlayCollection = this;

	//Clear Paging Links
	$P('paging_top').innerHTML = $P('paging_bottom').innerHTML  = '';

	//Show/Hide Paging Divs
	$P('paging_top').style.display = $P('paging_bottom').style.display = (numPages > 1 ? '' : 'none');

	for (var i = 1; i < numPages; i++){
		var pageidtop = 'page_top_' + i;
		var pageidbottom = 'page_bottom_' + i;
		//Output Regular pages
		if(i != page){
			var a1 = document.createElement('A');
			var a2 = document.createElement('A');

			a1.id  = pageidtop;
			a2.id = pageidbottom;
			a1.href = a2.href = '##page' + i;
			a1.innerHTML = a2.innerHTML = i;
			a1.className = a2.className = 'explorer_pagelink';
			a1.page_num = a2.page_num = i;
			var _this = this;
			Event.observe(
				a1,
				'click',
				function(){
					_this.map.showPlacemarks(overlayCollection,''+this.page_num+'')
				}
			);
			Event.observe(
				a2,
				'click',
				function(){
					_this.map.showPlacemarks(overlayCollection,''+this.page_num+'')
				}
			);
			
			$P('paging_top').appendChild(a1);
			$P('paging_bottom').appendChild(a2);

		}
		//Selected Page
		else{
			var s1 = document.createElement('SPAN');
			s1.id = pageidtop;
			var s2 = document.createElement('SPAN');
			s2.id = pageidbottom;
			s1.className = 'explorer_selpage';
			s2.className = 'explorer_selpage';
			s1.innerHTML = i;
			s2.innerHTML = i;
			
			$P('paging_top').appendChild(s1);
			$P('paging_bottom').appendChild(s2);			
		}
	}
}
*/

overlays.showPaging = function(){
	var page = this.currPage;
	var numPages = this.numPages();
	var overlayCollection = this;
	var pagingstr = '<div style=\"float: left; width: 95px; text-align: left; margin-left: 15px\">Page ' + this.currPage + ' of ' + numPages + '</div>';
	pagingstr += '<div style=\"float: right; text-align: right; width: 375px; margin-right: 15px\">';
	if(page > 1){
		pagingstr += '<a href="#" class=\"page_first\">First</a>';
		pagingstr += ' | <a href = "#" class=\"page_previous\">Previous</a>';
	}
	else{
		pagingstr += 'First';
		pagingstr += ' | Previous';
	}

	if(page < numPages){
		pagingstr += ' | <a href="#" class=\"page_next\">Next</a>';
		pagingstr += ' | <a href="#" class=\"page_last\">Last</a>';
	}
	else{
		pagingstr += ' | Next';
		pagingstr += ' | Last';
	}
	pagingstr += '</div>';

	$P('paging_top').innerHTML = pagingstr;
	$P('paging_bottom').innerHTML  = pagingstr;

	$P('paging_top_container').style.display = $P('paging_bottom_container').style.display = (numPages >= 1 ? '' : 'none');

	if(page > 1){
		var pagefirst = $$('.page_first');
		pagefirst.each(
			function(a){
				Event.observe(a,'click',function(e){
						overlayCollection.map.showPlacemarks(overlayCollection,1);
						Event.stop(e);
					}
				);
			}
		);

		var pageprevious = $$('.page_previous');
		pageprevious.each(
			function(a){
				Event.observe(a,'click',function(e){
						overlayCollection.map.showPlacemarks(overlayCollection,overlayCollection.currPage-1);
						Event.stop(e);
					}
				);
			}
		);
	}


	if(page < numPages){
		var pagenext = $$('.page_next');
		pagenext.each(
			function(a){
				Event.observe(a,'click',function(e){
						overlayCollection.map.showPlacemarks(overlayCollection,overlayCollection.currPage+1);
						Event.stop(e);
					}
				);
			}
		);


		var pagelast = $$('.page_last');
		pagelast.each(
			function(a){
				Event.observe(a,'click',function(e){
						overlayCollection.map.showPlacemarks(overlayCollection,overlayCollection.numPages());
						Event.stop(e);
					}
				);
			}
		);
	}



}

overlays.getInfoHTML = function(placemark){
	var addr = new Address();
	try{
		addr.loadFromObject(placemark);
	}
	catch(ex){
	}
	var str = new String();
	str = '<div class=\"infoWindowTitle\">placemark:name</div>';
	str += '<div class=\"infoWindowAddress\">' + addr.toHTMLString() + '</div>';
//	str += '<span onclick=\"svp();" class=\"fakelink\">Streetview</span>';
	str += '<ul class=\"infoWindowOptions\">';
	str += placemark.weburl.length > 0 ? '<li><a href=\"' + this.root +'/includes/redirects/webcount.cfm?listingID=placemark:prikey\" target=\"_blank\">Visit website</a></li>' : '';	
	str += '<li><a href=\"./index.cfm?action=display&listingid=placemark:prikey&hit=1">More Info</a></li>';
	str += '<li><a href=\"javascript:getDirections(placemark:prikey)">Directions</a></li>';
//	str += '<li><a href=\"javascript:directions.directionsFrom(placemark:prikey)\">Directions From Here</a></li>';
	str += '</ul">';
	if(placemark.distance){
			str += '<div class=\"infoWindowSection\">Distance: ' + placemark.distance.toFixed(1) + ' miles</div>';
	}

	return parsePlacemarkData(str,placemark);
}

overlays.updateBubble = function(args){
}