var locale = "en-US"; 			 // Default locale
var contentLoaded = "main_home"; // Default content
var itemCategory = "";			 // Used by includes/merchandise.php to get products by category
var itemSubcategory = "";		 // Used by includes/merchandise.php for additional filtering of items
// Default states of the left navigation menus. To have a menu be expanded upon initial load, change it to 1.
var isServicesMenuExpanded = 0;
var isMerchandiseMenuExpanded = 0;
var isInfoMenuExpanded = 0;
var isCroatiaMenuExpanded = 0;
var isMultimediaMenuExpanded = 0;
var isMiscMenuExpanded = 0;
var isLinksMenuExpanded = 0;

// This function is called every time index.php is hit
function bodyLoad() {
	bannerImage(); 		// Pull up a random image into banner_td
	document.getElementById('DidYouKnow_Label').innerHTML = "Did you know?";
	locale = "en-US";
	getNewLocaleContent();
	//switchLocaleToEN(); // Get English content by default
}

// Switches content to Croatian by changing the locale to "hr-HR", then calling getNewLocaleContent()
function switchLocaleToHR() {
	locale = "hr-HR";
	document.getElementById('switchLanguageButtonContainer_div').innerHTML = '<span><a href="#" onclick="javascript:switchLocaleToEN()"><img src="images/hr.png" alt="Click to change to English" /> Hrvatski</a></span>';
	document.getElementById('DidYouKnow_Label').innerHTML = "Jeste li znali?";
	getNewLocaleContent();
}

// Switches content to English by changing the locale to "en-US", then calling getNewLocaleContent()
function switchLocaleToEN() {
	locale = "en-US";
	document.getElementById('switchLanguageButtonContainer_div').innerHTML = '<span><a href="#" onclick="javascript:switchLocaleToHR()"><img src="images/us.gif" alt="Kliknite za promjeniti na Hrvatski" /> U.S. - English</a></span>';
	document.getElementById('DidYouKnow_Label').innerHTML = "Did you know?";
	getNewLocaleContent();
}

// Gets new content based on locale and which page is currently being viewed (by using the contentLoaded variable)
function getNewLocaleContent() {
	getContent('mainMenu','mainMenu');
	// A timeout is needed to allow the server-side php to generate a response to getContent()
	var waitTime = 1000;
	setTimeout("getContent('leftNav1','leftNav1_td')",waitTime);
	waitTime += 2000;
	setTimeout("getContent(contentLoaded, 'dynamicContent_td')",waitTime);
}

// Loads includes into the content TD
// pageFile is the file name (not including ".php")
// pageDescription is what will show in the title and breadcrumb
function getMainContent(content, pageDescription) {
	document.getElementById('thirdLevelLine_hx_id').innerHTML=pageDescription;
	document.title = "new york croats dot com [version 4]: " + pageDescription;
	// Remember which page the visitor. This is used for switching languages, so the visitor stays on the same page.
	contentLoaded = content;
// Tried to change the location bar text, but it actually redirected.  = bad
//	document.location.href = "http://www.newyorkcroats.com/index.php?content=" + x;
	getContent(content, 'dynamicContent_td'); // In responsexml.js
}

// Called by the left nav items under "merchandise". 
// itemSubcategory is any extra parameter needed for filtering
function getMerchandise(itemCat, itemSubcat) {
	itemCategory = itemCat;
	itemSubcategory = itemSubcat; // used in getContent() in responsexml.js
	getMainContent("merchandise", "merchandise &gt; " + itemCategory);
}

// Banner image randomization and placement
function bannerImage() {
	var randnum = Math.floor(Math.random() * 118);
	var image = "bannerimages/banner_" + randnum + ".jpg";
	document.getElementById('banner_td').innerHTML = "<img src='bannerimages/banner_" + randnum + ".jpg' border='0' height='170' width='758' alt='NY Croats Croatian' />";
}

// Default Google News function
function LoadNewsBar() {
	var root = document.getElementById("newsBar");
	options = {
		largeResultSet : false,
		resultStyle : GSnewsBar.RESULT_STYLE_EXPANDED,
		title : "Other news about Croatia",
 		autoExecuteList : {
			cycleTime : GSnewsBar.CYCLE_TIME_SHORT,
            cycleMode : GSnewsBar.CYCLE_MODE_LINEAR,
            executeList : [ "Hrvatska" ]
        }
    };
	var newsBar = new GSnewsBar(root, options);
}

// Controlling visibility for left navigation. The names are self-explanatory.
function showServices() {
	isServicesMenuExpanded = 1;
	document.getElementById('servicesMenu_div').style.display = 'block';
	document.getElementById('servicesShowButton').style.display = 'none';
	document.getElementById('servicesHideButton').style.display = 'block';
}
function hideServices() {
	isServicesMenuExpanded = 0;
	document.getElementById('servicesMenu_div').style.display = 'none';
	document.getElementById('servicesShowButton').style.display = 'block';
	document.getElementById('servicesHideButton').style.display = 'none';
}
function showMerchandise() {
	isMerchandiseMenuExpanded = 1;
	document.getElementById('merchandiseMenu_div').style.display = 'block';
	document.getElementById('merchandiseShowButton').style.display = 'none';
	document.getElementById('merchandiseHideButton').style.display = 'block';
}
function hideMerchandise() {
	isMerchandiseMenuExpanded = 0;
	document.getElementById('merchandiseMenu_div').style.display = 'none';
	document.getElementById('merchandiseShowButton').style.display = 'block';
	document.getElementById('merchandiseHideButton').style.display = 'none';
}
function showInfo() {
	isInfoMenuExpanded = 1;
	document.getElementById('infoMenu_div').style.display = 'block';
	document.getElementById('infoShowButton').style.display = 'none';
	document.getElementById('infoHideButton').style.display = 'block';
}
function hideInfo() {
	isInfoMenuExpanded = 0;
	document.getElementById('infoMenu_div').style.display = 'none';
	document.getElementById('infoShowButton').style.display = 'block';
	document.getElementById('infoHideButton').style.display = 'none';
}
function showCroatia() {
	isCroatiaMenuExpanded = 1;
	document.getElementById('croatiaMenu_div').style.display = 'block';
	document.getElementById('CroatiaShowButton').style.display = 'none';
	document.getElementById('CroatiaHideButton').style.display = 'block';
}
function hideCroatia() {
	isCroatiaMenuExpanded = 0;
	document.getElementById('croatiaMenu_div').style.display = 'none';
	document.getElementById('CroatiaShowButton').style.display = 'block';
	document.getElementById('CroatiaHideButton').style.display = 'none';
}
function showMultimedia() {
	isMultimediaMenuExpanded = 1;
	document.getElementById('multimediaMenu_div').style.display = 'block';
	document.getElementById('multimediaShowButton').style.display = 'none';
	document.getElementById('multimediaHideButton').style.display = 'block';
}
function hideMultimedia() {
	isMultimediaMenuExpanded = 0;
	document.getElementById('multimediaMenu_div').style.display = 'none';
	document.getElementById('multimediaShowButton').style.display = 'block';
	document.getElementById('multimediaHideButton').style.display = 'none';
}
function showMisc() {
	isMiscMenuExpanded = 1;
	document.getElementById('miscMenu_div').style.display = 'block';
	document.getElementById('miscShowButton').style.display = 'none';
	document.getElementById('miscHideButton').style.display = 'block';
}
function hideMisc() {
	isMiscMenuExpanded = 0;
	document.getElementById('miscMenu_div').style.display = 'none';
	document.getElementById('miscShowButton').style.display = 'block';
	document.getElementById('miscHideButton').style.display = 'none';
}
function showLinks() {
	isLinksMenuExpanded = 1;
	document.getElementById('linksMenu_div').style.display = 'block';
	document.getElementById('linksShowButton').style.display = 'none';
	document.getElementById('linksHideButton').style.display = 'block';
}
function hideLinks() {
	isLinksMenuExpanded = 0;
	document.getElementById('linksMenu_div').style.display = 'none';
	document.getElementById('linksShowButton').style.display = 'block';
	document.getElementById('linksHideButton').style.display = 'none';
}