/*
 *
 * 
 * 
 */
function ws_Being() {
	var me = this;
	
	me.currentKmlObject;
	me.divContainerHeader = ".Right-Panel-Header";
	me.divContainer = ".Right-Panel-Container";
	me.divContainerNews = "#Right-Panel-News";
	me.divContainerOneRiot = "#Right-Panel-OneRiot";
	
	me.ghelpers = new GEHelpers(ge);
	
//	me.getNews("http://sports.yahoo.com/oly/rss.xml");
//	me.getOneRiot('2010 Olympics');
}

ws_Being.prototype.getTickets = function() {
	if (this.currentKmlObject) {
		ge.getFeatures().removeChild(this.currentKmlObject);
		this.currentKmlObject = null;
	} else {
		google.earth.fetchKml(ge, LIB_URL + 'kml/event_centers.kml', this.kmlLoaded);
		moveCamera(49.6280, -123.0092, 110000, 30, 70);
	}
};

ws_Being.prototype.getNews = function(result) {
	$(this.divContainerHeader).html('<div id="header-text"> News </div>');
	$(this.divContainer).append('<div id="Right-Panel-News"></div>');

	if(typeof result == 'string') {
	} else {
		if (result.error || result.entries.length <= 0) {
			$(this.divContainerNews).html('No Results Found');
			return;
		}
	}

	var feed = new google.feeds.Feed(result);
	feed.load(function(result) {
		if (!result.error) {
			var container = document.getElementById("Right-Panel-News");
			
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				
				var newsContent = '<div class="news-title"> <a href="'+entry['link']+'" target="_blank">'+entry['title']+'</a> </div>'
								+ '<div class="news-publish">'+entry['publishedDate']+'</div>'
								+ '<div class="news-content">'+entry['contentSnippet']+'</div>';
				
				$(control.divContainerNews).append(newsContent);				
			}
		}
	});
};

ws_Being.prototype.kmlLoaded = function(kmlObject) {
	if(!kmlObject) {
		setTimeout(function() {
			alert('Bad or null KML.');
		}, 0);
		return;
	}

	ge.getFeatures().appendChild(kmlObject);
	control.currentKmlObject = kmlObject;
};

ws_Being.prototype.getOneRiot = function(query) {
	$(this.divContainerHeader).html('');
	$(this.divContainer).html('');
	
	var me = this;
	
	$(this.divContainerHeader).html('<div id="header-text">Information</div>');
	$(this.divContainer).append('<div id="Right-Panel-OneRiot"></div>');
	
	$.ajax({
		url: "http://openapi.oneriot.com/search?appId=waterstone01&version=1.1&q="+query,
		dataType: "jsonp",
		jsonpCallback: com_oneriot_search_results
	});
};

function com_oneriot_search_results(data) {
	if(data.totalResults) {
		if(data.featuredResultList) {
			var entry = data.featuredResultList[0];
			var featHtml	= '<div class="oneriot-featured-title"><a href="'+entry.redirectUrl+'" target="_blank">'+entry.title+'</a></div>'
							+ '<div class="oneriot-featured-snippet">'+entry.snippet+'</div>';
			$(control.divContainerOneRiot).html(featHtml);
		}

		if(data.resultList) {
			var count=0;
			if(data.resultList.length > 4) {
				count=4;
			} else {
				count=1;
			}
	
			for(var i=0; i<count; i++) {
				var entry = data.resultList[i];
				var html 	= '<div class="oneriot-title"><a href="'+entry.redirectUrl+'" target="_blank">'+entry.title+'</a></div>'
							+ '<div class="oneriot-snippet">'+entry.snippet+'</div>';
				$(control.divContainerOneRiot).append(html);
			}
		}
	}
}

/*
 * 
 * 
 * 
 */
$(document).ready(function() {
	$("#tickets").hover(
			function() {
				if(!y_arts)
					$(this).attr("src", "images/navigation/left-BeingThere/tickets_hov.jpg");
			},
			function() {
				if(!y_arts)
					$(this).attr("src", "images/navigation/left-BeingThere/tickets.jpg");
			}
		).toggle(
			function() {
				$(this).attr("src", "images/navigation/left-BeingThere/tickets_ov.jpg");
				
				yelpCamera('arts');
				// control.getOneRiot('vancouver entertainment');
			},
			function() {
				$(this).attr("src", "images/navigation/left-BeingThere/tickets_hov.jpg");

				yelpCamera('arts');
			}
	);
	$("#hotels").hover(
			function() {
				if(!y_hotels)
					$(this).attr("src", "images/navigation/left-BeingThere/hotels_hov.jpg");
			},
			function() {
				if(!y_hotels)
					$(this).attr("src", "images/navigation/left-BeingThere/hotels.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/hotels_ov.jpg");
					
					yelpCamera('hotels');
					// control.getOneRiot('vancouver hotels');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/hotels_hov.jpg");

					yelpCamera('hotels');
				}
	);
	$("#dining").hover(
			function() {
				if(!y_restaurants)
					$(this).attr("src", "images/navigation/left-BeingThere/dinning_hov.jpg");
			},
			function() {
				if(!y_restaurants)
					$(this).attr("src", "images/navigation/left-BeingThere/dinning.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/dinning_ov.jpg");
					
					yelpCamera('restaurants');
					// control.getOneRiot('vancouver dining');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/dinning_hov.jpg");

					yelpCamera('restaurants');
				}
	);
	$("#coffee").hover(
			function() {
				if(!y_coffee)
					$(this).attr("src", "images/navigation/left-BeingThere/coffee_hov.jpg");
			},
			function() {
				if(!y_coffee)
					$(this).attr("src", "images/navigation/left-BeingThere/coffee.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/coffee_ov.jpg");
					
					yelpCamera('coffee');
					// control.getOneRiot('vancouver coffee');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/coffee_hov.jpg");

					yelpCamera('coffee');
				}
	);
	$("#shopping").hover(
			function() {
				if(!y_shopping)
					$(this).attr("src", "images/navigation/left-BeingThere/shopping_hov.jpg");
			},
			function() {
				if(!y_shopping)
					$(this).attr("src", "images/navigation/left-BeingThere/shopping.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/shopping_ov.jpg");
					
					yelpCamera('shopping');
					// control.getOneRiot('vancouver shopping');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/shopping_hov.jpg");

					yelpCamera('shopping');
				}
	);
	$("#banks").hover(
			function() {
				if(!y_banks)
					$(this).attr("src", "images/navigation/left-BeingThere/banks_hov.jpg");
			},
			function() {
				if(!y_banks)
					$(this).attr("src", "images/navigation/left-BeingThere/banks.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/banks_ov.jpg");
					
					yelpCamera('banks');
					// control.getOneRiot('vancouver banks');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/banks_hov.jpg");

					yelpCamera('banks');
				}
	);
	$("#hospitals").hover(
			function() {
				if(!y_hospitals)
					$(this).attr("src", "images/navigation/left-BeingThere/hospital_hov.jpg");
			},
			function() {
				if(!y_hospitals)
					$(this).attr("src", "images/navigation/left-BeingThere/hospital.jpg");
			}
		).toggle(
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/hospital_ov.jpg");
					
					yelpCamera('hospitals');
					// control.getOneRiot('vancouver hospitals');
				},
				function() {
					$(this).attr("src", "images/navigation/left-BeingThere/hospital_hov.jpg");

					yelpCamera('hospitals');
				}
	);
});


