/**
 * DIGITAL NEIGHBORS JS file to deal with links, sidebar links, dropdown menu links
 * 
 * NOTE: This file will work on the preview server. Save it to a *.pack.js version for the live server
 * 
 */
/* Determine links for neighbors sections */	
/* Dynamic links to spill pages and / or other community news sections */
console.log('ready to load function : resendPageWithNewTopic');

function resendPageWithNewTopic(newTopic) { 
	var fullURL;
	fullURL = window.location.protocol + '//' + window.location.hostname + '/' + getThisCityAlias() + "/index-p2.html?topic=" + newTopic; 

	if (newTopic == 'events') {
    	window.open(fullURL, '_blank');
  	} else {
    	window.location.href = fullURL; 
	}
} 

console.log('ready to load function : resendPageWithNewLocation');

function resendPageWithNewLocation(newLocation) {
	var newCityURL = window.location.protocol + "//" + window.location.hostname + "/" + newLocation + "?topic=" + currentTopic;
	window.location.href = newCityURL;
}

console.log('ready to load function2 : jCarouselLite');
/* Slideshow in Header */
jQuery(function() {
	jQuery("#inside").css('display','inline');
    jQuery(".jcarousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		visible:3,
		speed:500,
		circular: true
    });
	jQuery("#inside").show();
});

// Testing this to see what happens when GBrowserIsCompatible() isn't available
//function safe_GBrowserIsCompatible(){return GBrowserIsCompatible();}

console.log('ready to load function: triggerRegion');

function triggerRegion() {
	/**** 
	This function is triggered when a user changes the option in the dropdown menu.
	
	When the primary dropdown menu changes, we want to send the user to the index-p2.html for 
	that corresponding city. (Topic = all-news)
	
	When the secondary dropdown menu changes, we want to make sure we're on the index-p2.html for
	that corresponding city (The main city that is selected when the secondary menu changes) with
	the region id tacked onto the end of the query string.
	
	i.e. http://www.miamiherald.com/[city-name]/index-p2.html?topic=[all-news or other topic]&region=[region ID here]
	****/
	
	/*** update kms 1-7-10
	Non-managed sections should go to index.html, not index-p2.html. All managed cities/regions should have class="m"
	Updated code to check if selected option has class "m" go to index-p2, otherwise index
	***/

	currentRegion = window.currentRegion || "";
	currentTopic = window.currentTopic || "";

	var sid = jQuery(this).attr('id');
	var opt = jQuery(this).find("option:selected").val();
	var current_url = window.location;
	var new_city = currentCity;
	var new_topic = "all-news";
	var new_region = currentRegion;
	var index_page = 'index.html';
	
	if (jQuery(this).find("option:selected").hasClass('m')) {index_page = 'index-p2.html';}
	
	/*** Keep the current topic if it exists; this dropdown just changes locations. If not, it is defaulted to 'all news'. ***/
	if (!currentTopic == "") { new_topic = currentTopic; }
	
	/*** Depending on which select box was changed, the variable 'opt' will either be a region or a city. ***/
	if (sid == "aroundtown-cityselect" || sid == "terrafly-cityselect") {
		new_city = opt;
		new_region = ""; // new city, reset the region
	} else if (sid == "aroundtown-submenu") {
		new_region = opt;
	} else {
		// Should never get this.
	}
		
	var redirect_url = "http://" + current_url.hostname + "/" + new_city + "/"+index_page+"?topic=" + new_topic;
	if (!new_region == "") { redirect_url += "&region=" + new_region; }
	
	window.location.href = redirect_url;
}
