var cg_defaultColor = "#351f11";
var cg_mouseoverColor = "#eee";

// keep track of current selected ID
var currentCity = 'cities_all';
var currentFeature = 'features_all';
var currentHood = 'hoods_all';
var currentTag = 'tags_all';

function getCurrentCityGuideCityId() {
	var l_sId = currentCity.replace('cities_', '');
	return l_sId == 'all' ? -1 : l_sId;
}

function getCurrentCityGuideFeatureId() {
	var l_sId = currentFeature.replace('features_', '');
	return l_sId == 'all' ? -1 : l_sId;
}

function getCurrentCityGuideHoodId() {
	var l_sId = currentHood.replace('hoods_', '');
	return l_sId == 'all' ? -1 : l_sId;
}

function getCurrentCityGuideTagId() {
	var l_sId = currentTag.replace('tags_', '');
	return l_sId == 'all' ? -1 : l_sId;
}

function changeCityGuidePage(p_nPageNumber) {
	LxtvAjax.getPagedCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId(), p_nPageNumber);
}

$(document).ready(function(){
						   
	// init jscrollpane plugin
	$('#scrollbox_cities, #scrollbox_features, #scrollbox_hoods, #scrollbox_tags').jScrollPane({ showArrows:true, scrollbarWidth:14, scrollbarMargin:0 });
	
	resetAllBoxes();
	
	// style defaults/all
	$('#cities_all, #features_all, #hoods_all, #tags_all').css("color","white");
	$('#cities_all, #features_all, #hoods_all, #tags_all').css("background-color",cg_defaultColor);
	
	
	//CITIES
	$('#scrollbox_cities a').mouseover(function(){
		if ($(this).attr("id") != currentCity) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentCity) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentCity) {
			resetCities();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentCity = $(this).attr("id");
			updateListing(this);
			updateHoods();
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId());
			$('#scrollbox_hoods').jScrollPane({ showArrows:true, scrollbarWidth:14, scrollbarMargin:0 }); //re-initializes neighborhoods scrollpane to reflect changed content
		}
		return false;
	});
	
	//FEATURES
	$('#scrollbox_features a').mouseover(function(){
		if ($(this).attr("id") != currentFeature) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentFeature) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentFeature) {
			resetFeatures();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentFeature = $(this).attr("id");
			updateListing(this);
			updateFeatureTags();
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId());

			$('#scrollbox_tags').jScrollPane({ showArrows:true, scrollbarWidth:14, scrollbarMargin:0 }); // re-initializes tags scrollpane to reflect changed content

		}
		return false;
	});

	//HOODS
	$('#scrollbox_hoods a').mouseover(function(){
		if ($(this).attr("id") != currentHood) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentHood) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentHood) {
			resetHoods();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentHood = $(this).attr("id");
			updateListing(this);
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId());
		}
		return false;
	});

	//TAGS
	$('#scrollbox_tags a').mouseover(function(){
		if ($(this).attr("id") != currentTag) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentTag) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentTag) {
			resetTags();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentTag = $(this).attr("id");
			updateListing(this);
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId());
		}
		return false;
	});

});


function updateListing(e) {
	//alert( $(e).attr("id") );
}


function resetAllBoxes() {
	resetCities();
	resetFeatures();
	resetHoods();
	resetTags();
}


function updateHoods() {
	var l_sNeighborhoodList = '<li><a href="#" id="hoods_all"><span>all</span></a></li>';
	
	if ( getCurrentCityGuideCityId() == -1 ) {
		if ( g_aCityNeighborhoods.length > 0 ) {
			for ( var l_nCityId in g_aCityNeighborhoods ) {
				var l_aCityNeighborhoodIdAndNames = g_aCityNeighborhoods[l_nCityId];
				if ( l_aCityNeighborhoodIdAndNames != undefined && l_aCityNeighborhoodIdAndNames.length >= 1 ) {
					for ( var i=0; i<l_aCityNeighborhoodIdAndNames.length; i++) {
						l_sNeighborhoodList+= '<li><a href=\"#\" id=\"hoods_'+l_aCityNeighborhoodIdAndNames[i][0]+'\"><span>'+l_aCityNeighborhoodIdAndNames[i][1]+'</span></a></li>';
					}
				}
			}
		}
	}
	else {
		var l_aCityNeighborhoodIdAndNames = g_aCityNeighborhoods[getCurrentCityGuideCityId()];
		if ( l_aCityNeighborhoodIdAndNames != undefined && l_aCityNeighborhoodIdAndNames.length >= 1 ) {
			for ( var i=0; i<l_aCityNeighborhoodIdAndNames.length; i++) {
				l_sNeighborhoodList+= '<li><a href=\"#\" id=\"hoods_'+l_aCityNeighborhoodIdAndNames[i][0]+'\"><span>'+l_aCityNeighborhoodIdAndNames[i][1]+'</span></a></li>';
			}
		}
	}
	
	
	$('#scrollbox_hoods ul').html(l_sNeighborhoodList);
	
	currentHood = 'hoods_all';
	
	resetHoods();
	
	$('#hoods_all').css("color","white");
	$('#hoods_all').css("background-color",cg_defaultColor);
	
	$('#scrollbox_hoods a').mouseover(function(){
		if ($(this).attr("id") != currentHood) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentHood) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentHood) {
			resetHoods();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentHood = $(this).attr("id");
			updateListing(this);
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId(), 1);
		}
		return false;
	});
}


function updateFeatureTags() {
	var l_sFeatureTagList = '<li><a href="#" id="tags_all"><span>all</span></a></li>';
	
	if ( getCurrentCityGuideFeatureId() == -1 ) {
		if ( g_aFeatureTags.length > 0 ) {
			for ( var l_nFeatureId in g_aFeatureTags ) {
				var l_aFeatureTagIdAndNames = g_aFeatureTags[l_nFeatureId];
				if ( l_aFeatureTagIdAndNames != undefined && l_aFeatureTagIdAndNames.length >= 1 ) {
					for ( var i=0; i<l_aFeatureTagIdAndNames.length; i++) {
						l_sFeatureTagList+= '<li><a href=\"#\" id=\"tags_'+l_aFeatureTagIdAndNames[i][0]+'\"><span>'+l_aFeatureTagIdAndNames[i][1]+'</span></a></li>';
					}
				}
			}
		}
	}
	else {
		var l_aFeatureTagIdAndNames = g_aFeatureTags[getCurrentCityGuideFeatureId()];
		if ( l_aFeatureTagIdAndNames != undefined && l_aFeatureTagIdAndNames.length >= 1 ) {
			for ( var i=0; i<l_aFeatureTagIdAndNames.length; i++) {
				l_sFeatureTagList+= '<li><a href=\"#\" id=\"tags_'+l_aFeatureTagIdAndNames[i][0]+'\"><span>'+l_aFeatureTagIdAndNames[i][1]+'</span></a></li>';
			}
		}
	}
	
	
	$('#scrollbox_tags ul').html(l_sFeatureTagList);
	
	currentTag = 'tags_all';
	
	resetTags();
	
	$('#tags_all').css("color","white");
	$('#tags_all').css("background-color",cg_defaultColor);
	
	$('#scrollbox_tags a').mouseover(function(){
		if ($(this).attr("id") != currentTag) {
			$(this).css("background-color",cg_mouseoverColor);
		}
	}).mouseout(function(){
		if ($(this).attr("id") != currentTag) {
			$(this).css("background-color","white");
		}
	}).click(function(){
		if ($(this).attr("id") != currentTag) {
			resetTags();
			$(this).css("color","white");
			$(this).css("background-color",cg_defaultColor);
			currentTag = $(this).attr("id");
			updateListing(this);
			LxtvAjax.getCityGuideContent(getCurrentCityGuideCityId(), getCurrentCityGuideFeatureId(), getCurrentCityGuideHoodId(), getCurrentCityGuideTagId(), 1);
		}
		return false;
	});
}


function resetCities() {
	$('#city_guide #scrollbox_cities a').css("color",cg_defaultColor);
	$('#city_guide #scrollbox_cities a').css("background-color","white");
}


function resetFeatures() {
	$('#city_guide #scrollbox_features a').css("color",cg_defaultColor);
	$('#city_guide #scrollbox_features a').css("background-color","white");
}


function resetHoods() {
	$('#city_guide #scrollbox_hoods a').css("color",cg_defaultColor);
	$('#city_guide #scrollbox_hoods a').css("background-color","white");
}


function resetTags() {
	$('#city_guide #scrollbox_tags a').css("color",cg_defaultColor);
	$('#city_guide #scrollbox_tags a').css("background-color","white");
}

