var albumsAdded = 0;

//--------------------------------------------------------------------------------------------------------------------

function footer_red()
	{
	parent.footerframe.document.body.style.backgroundColor = "rgb(200,50,0)";
	}

//--------------------------------------------------------------------------------------------------------------------

function footer_grey()
	{
	parent.footerframe.document.body.style.backgroundColor = "rgb(90,90,90)";
	}

//--------------------------------------------------------------------------------------------------------------------

function update_footer(mode)
	{
	// make sure footer frame exists and page is loaded
	if (self == parent) return;
	if (!parent.footerframe) return;
	if (!parent.footerframe.document) return;
	var cartDiv = parent.footerframe.document.getElementById("cartstatus");
	
	if (!cartDiv) return;
	
	// how many albums were added?
	var albumsAdded = 0;
	var qStr = location.search;
	var qArr = qStr.split("added=");
	if (qArr.length == 2) albumsAdded = parseInt(qArr[1]);
	
	// determine language of footer
	var language = "";
	var footerURL = parent.footerframe.location.href;
	if (footerURL.indexOf("english-footer") != -1) language = "english";
	else if (footerURL.indexOf("german-footer") != -1) language = "german";
	else if (footerURL.indexOf("french-footer") != -1) language = "french";
	else if (footerURL.indexOf("italian-footer") != -1) language = "italian";
	else if (footerURL.indexOf("spanish-footer") != -1) language = "spanish";
	
	//display shopping cart information
	var divHTML = "";
	var htmlSpacer = " &nbsp; &nbsp; &nbsp; &nbsp; ";
	if (cartItems <= 0)
		{
		if (language == "english") divHTML = "Your shopping cart is empty.";
		else if (language == "german") divHTML = "Ihr Warenkorb ist leer.";
		else if (language == "french") divHTML = "Votre panier est vide.";
		else if (language == "italian") divHTML = "Il Suo carrello &egrave; vuoto.";
		else if (language == "spanish") divHTML = "Su carrito est&aacute; vac&iacute;o.";
		}
	else
		{
		if (language == "english")
			{
			if (albumsAdded == 1 && mode != "cart") divHTML += 'Album has been added' + htmlSpacer;
			else if (albumsAdded > 1) divHTML += albumsAdded + ' Albums have been added' + htmlSpacer;
			divHTML += 'Your shopping cart contains ' + cartItems;
			if (cartItems == 1) divHTML += ' album';
			else divHTML += ' albums';
			divHTML += htmlSpacer + '<a href="output.php?template=english-shoppingcart.php&content=Shop-Texte%2FWarenkorb_englisch.php" ';
			divHTML += 'target="contentframe" hidefocus><span>Show shopping cart &raquo;</span></a>';
			}
		else if (language == "german")
			{
			if (albumsAdded == 1 && mode != "cart") divHTML += 'Album hinzugef&uuml;gt' + htmlSpacer;
			else if (albumsAdded > 1) divHTML += albumsAdded + ' Alben hinzugef&uuml;gt' + htmlSpacer;
			divHTML += 'Ihr Warenkorb enth&auml;lt ' + cartItems;
			if (cartItems == 1) divHTML += ' Album';
			else divHTML += ' Alben';
			divHTML += htmlSpacer + '<a href="output.php?template=german-shoppingcart.php&content=Shop-Texte%2FWarenkorb_deutsch.php" ';
			divHTML += 'target="contentframe" hidefocus><span>Warenkorb anzeigen &raquo;</span></a>';
			}
		else if (language == "french")
			{
			if (albumsAdded == 1 && mode != "cart") divHTML += ' album a &eacute;t&eacute; ajout&eacute;' + htmlSpacer;
			else if (albumsAdded > 1) divHTML += albumsAdded + ' albums ont &eacute;t&eacute; ajout&eacute;s' + htmlSpacer;
			divHTML += 'Votre panier contient ' + cartItems;
			if (cartItems == 1) divHTML += ' album';
			else divHTML += ' albums';
			divHTML += htmlSpacer + '<a href="output.php?template=french-shoppingcart.php&content=Shop-Texte%2FWarenkorb_franzoesisch.php" ';
			divHTML += 'target="contentframe" hidefocus><span>Votre panier &raquo;</span></a>';
			}
		else if (language == "italian")
			{
			if (albumsAdded == 1 && mode != "cart") divHTML += 'Aggiungere l&#34articolo' + htmlSpacer;
			else if (albumsAdded > 1) divHTML += albumsAdded + ' Aggiungere l&#34articolo' + htmlSpacer;
			divHTML += 'Il Suo carrello contiene ' + cartItems;
			if (cartItems == 1) divHTML += ' articolo';
			else divHTML += ' articoli';
			divHTML += htmlSpacer + '<a href="output.php?template=italian-shoppingcart.php&content=Shop-Texte%2FWarenkorb_italienisch.php" ';
			divHTML += 'target="contentframe" hidefocus><span>Visualizza il carrello &raquo;</span></a>';
			}
		else if (language == "spanish")
			{
			if (albumsAdded == 1 && mode != "cart") divHTML += 'Album has been added' + htmlSpacer;
			else if (albumsAdded > 1) divHTML += albumsAdded + ' Albums have been added' + htmlSpacer;
			divHTML += 'Your shopping cart contains ' + cartItems;
			if (cartItems == 1) divHTML += ' album';
			else divHTML += ' albums';
			divHTML += htmlSpacer + '<a href="output.php?template=spanish-shoppingcart.php&content=Shop-Texte%2FWarenkorb_spanisch.php" ';
			divHTML += 'target="contentframe" hidefocus><span>Show shopping cart &raquo;</span></a>';
			}
		}
	cartDiv.innerHTML = divHTML;
	
	// activate the checkout button of the shopping cart if applicable or reload page (Opera)
	if (parent && parent.contentframe && parent.contentframe.document.getElementById("checkoutButton")) parent.contentframe.document.getElementById("checkoutButton").style.display = "inline";
	if (parent && parent.contentframe && parent.contentframe.document.getElementById("checkoutWait")) parent.contentframe.document.getElementById("checkoutWait").style.display = "none";
	
	// show or hide the cart symbol in the headerframe
	update_cartlogo();
		
	// make the footer frame blink
	if (!parent.footerframe.document.body.style || albumsAdded <= 0 || mode == "cart") return;
	this.setTimeout ("footer_red()", 100); 
	this.setTimeout ("footer_grey()", 300); 
	this.setTimeout ("footer_red()", 500); 
	this.setTimeout ("footer_grey()", 700); 
	this.setTimeout ("footer_red()", 900); 
	this.setTimeout ("footer_grey()", 1100); 
	}

//--------------------------------------------------------------------------------------------------------------------

function toggle_language(langID)
	{
	// determine current language
	var thisPageUrl = self.location.href;
	if (thisPageUrl.indexOf("german") != -1) { oldLang1 = "german"; oldLang2 = "_deutsch"; oldLang3 = "D"; }
	else if (thisPageUrl.indexOf("english") != -1) { oldLang1 = "english"; oldLang2 = "_englisch"; oldLang3 = "E"; }
	else if (thisPageUrl.indexOf("french") != -1) { oldLang1 = "french"; oldLang2 = "_franzoesisch"; oldLang3 = "F"; }
	else if (thisPageUrl.indexOf("italian") != -1) { oldLang1 = "italian"; oldLang2 = "_italienisch"; oldLang3 = "I"; }
	else if (thisPageUrl.indexOf("spanish") != -1) { oldLang1 = "spanish"; oldLang2 = "_spanisch"; oldLang3 = "S"; }
	
	// determine new language
	if (langID == "d") { newLang1 = "german"; newLang2 = "_deutsch"; newLang3 = "D"; }
	else if (langID == "e") { newLang1 = "english"; newLang2 = "_englisch"; newLang3 = "E"; }
	else if (langID == "f") { newLang1 = "french"; newLang2 = "_franzoesisch"; newLang3 = "F"; }
	else if (langID == "i") { newLang1 = "italian"; newLang2 = "_italienisch"; newLang3 = "I"; }
	else if (langID == "s") { newLang1 = "spanish"; newLang2 = "_spanisch"; newLang3 = "S"; }
	
	// determine new content page
	var page = "";
	if (parent)
		{
		if (parent.contentframe)
			{
			if (parent.contentframe.location)
				{
				// delete treplace from the content query
				var thisContentPath = parent.contentframe.location.pathname;
				if (thisContentPath.indexOf("/preview/") == 0) thisContentPath = thisContentPath.substring(9); // special processing for preview version
				var thisContentQuery = parent.contentframe.location.search.substr(1);
				queryArray = thisContentQuery.split("&");
				for (i=0; i<queryArray.length; i++) if (queryArray[i].indexOf("treplace") == 0) queryArray = queryArray.slice(0,i).concat(queryArray.slice(i+1)); 
				thisContentQuery = queryArray.join("&");
				if (thisContentQuery.length > 0)
					{
					thisContentQuery = "?" + thisContentQuery;
					thisContentQuery = thisContentQuery.replace(/\s/g, "+");
				
					// refresh the search results on special pages
					if (thisContentQuery.indexOf("-search-results.php") != -1)
						{
						var oldQuery1 = "search" + oldLang3 + "+programm" + oldLang3;
						var newQuery1 = "search" + newLang3 + "+programm" + newLang3;
						var oldQuery2 = "instrumente" + oldLang3 + "+search" + oldLang3;
						var newQuery2 = "instrumente" + newLang3 + "+search" + newLang3;
						var oldQuery3 = "topicShort" + oldLang3 + "+topicLong" + oldLang3 + "+teaser" + oldLang3 + "+maintext" + oldLang3 + "+search" + oldLang3;
						var newQuery3 = "topicShort" + newLang3 + "+topicLong" + newLang3 + "+teaser" + newLang3 + "+maintext" + newLang3 + "+search" + newLang3;
						var oldQuery4 = "show" + oldLang3;
						var newQuery4 = "show" + newLang3;
						thisContentQuery = thisContentQuery.replace(oldQuery1, newQuery1);
						thisContentQuery = thisContentQuery.replace(oldQuery2, newQuery2);
						thisContentQuery = thisContentQuery.replace(oldQuery3, newQuery3);
						thisContentQuery = thisContentQuery.replace(oldQuery4, newQuery4);
						}
					if (thisContentQuery.indexOf("-news-archive.php") != -1)
						{
						var oldQuery1 = "show" + oldLang3;
						var newQuery1 = "show" + newLang3;
						var oldQuery2 = "topicShort" + oldLang3 + "+topicLong" + oldLang3 + "+teaser" + oldLang3 + "+maintext" + oldLang3 + "+search" + oldLang3 + "+textDownload" + oldLang3;
						var newQuery2 = "topicShort" + newLang3 + "+topicLong" + newLang3 + "+teaser" + newLang3 + "+maintext" + newLang3 + "+search" + newLang3 + "+textDownload" + newLang3;
						thisContentQuery = thisContentQuery.replace(oldQuery1, newQuery1);
						thisContentQuery = thisContentQuery.replace(oldQuery2, newQuery2);
						}
					}
				// put together the final URL
				var thisContentUrl = thisContentPath + thisContentQuery;
				// replace old language by new language
				thisContentUrl = thisContentUrl.replace(oldLang1,newLang1).replace(oldLang2,newLang2)
				// if content has no template add new treplace that replaces the standard template language
				if (thisContentQuery.length > 0 && thisContentQuery.indexOf("template=") == -1) thisContentUrl += "&treplace=english%2C" + newLang1;
				if (thisContentPath.indexOf("-execute-order.php") == -1) page = "&page=" + escape(thisContentUrl);
				}
			}
		}
	// load the new language
	top.location.replace("index.php?language=" + newLang1 + page);
	}

//------------------------------------------------------------------------------------------------------

function update_cartlogo()
	{
	if (parent == self) return;
	if (!parent.headerframe) return;
	if (!parent.hiddenframe) return;
	if (!parent.headerframe.document) return;
	if (!parent.hiddenframe.document) return;
	if (parent.hiddenframe.cartItems > 0) parent.headerframe.document.getElementById("cart").style.display = "inline";
	else parent.headerframe.document.getElementById("cart").style.display = "none";
	} 
