/**
 * @author gharbusch
 */

/**
 * 
 * @param {Object} id
 * @param {Object} path_lang_obj
 */
var Page = Class.create({
	initialize: function(id, path_lang_obj)
	{
		this.id = id,
		this.paths = path_lang_obj || null 
	},
	
	getPath: function(lang)
	{
		return this.paths[lang];
	}
});

/**
 * Creates a Right-Content-Box
 * @param {String} path to the HTML-Snippet
 */
var rightColumnBox = Class.create({
	initialize: function(path)
	{
		this.path = path || '';
	},
	
	show: function()
	{
  	new Ajax.Request(this.path, {
  		method: 'get',
  		onSuccess: function(transport){
  			var right = $('TSW_mainContentRight');
				right.insert(transport.responseText);
  		}
  	});
  }
});

/**
 * Creates a Head-Banner
 * @param {String} path to the Image
 */
var headBanner = Class.create({
	initialize: function(path)
	{
		this.path = path || '/src/HeadBanner/HB_Profil.jpg';
	}
});

/**
 * Creates a Content-Banner
 * @param {String} path to the HTML-Snippet
 * @param {Number} height of the Image
 * @param {Bool} wide (default: false; true if the Banner stretches over two columns)
 */
var contentBanner = Class.create({
	initialize: function(path, height, wide)
	{
		this.path = path || '';
		this.height = height || 0;
		this.wide = wide || false;
	}
});

function loadContent() 
{	
	content.show();
};

/**
 * Creates a Page-Content
 * @param {String} path to the HTML-snippet
 * @param {Array} boxes_array - Right-Column-Boxes to show
 * @param {Object} headBanner_Obj - Head-Banner to show
 * @param {Object} contentBanner_Obj - Content-Banner to show
 */
var pageContent = Class.create({
	initialize: function(path, boxes_array, headBanner_Obj, contentBanner_Obj, scrollTo)
	{
		/* Variables */
		this.path = path || '';
		this.boxes_array = boxes_array || null;
		this.headBanner = headBanner_Obj || null;
		this.contentBanner = contentBanner_Obj || null;
		this.scrollTo = scrollTo || null;
	},
	
	/* methods */
	change: function()
	{
		Effect.Fade(
			'TSW_mainContentWrap', {
			afterFinish: loadContent
		});		
	},
	
	show: function()
	{
		this.showContentBanner();
		this.showBoxes();
		new Ajax.Request(this.path,
			{
				method: 'get',
				onSuccess: function(transport)
				{
					var child = $('TSW_mainContentLeft').childElements()[0];
					child.replace(transport.responseText);
					Effect.Appear('TSW_mainContentWrap', 
					{
						afterFinish: function() {
							if ( content.scrollTo != null )
								Effect.ScrollTo(content.scrollTo, { queue: 'end', duration: 0.5});
								// Effect.Highlight(content.scrollTo,{startColor: '#ffffcc', endColor: '#ffffff', restoreColor: false, queue: 'end'});
						} 
					});
				}
			}
		);
	},
	
	showBoxes: function()
	{
		var right = $('TSW_mainContentRight');
		right.childElements().each(
			function(item) 
			{
				// this noch bekannt
				item.remove();
			}, this
		);
		this.boxes_array.each(function(box) { box.show() });		
	},
	
	showContentBanner: function() 
	{
		if ( this.contentBanner == null ) 
		{
			$('TSW_mainContentWrap').setStyle({
				paddingTop: '0',
				backgroundImage: 'none'
			});
			$('TSW_mainContentLeft').setStyle({
				paddingTop: '30px',
				backgroundImage: 'none'
			});
		}
		else
		{
			if (this.contentBanner.wide)
			{
				$('TSW_mainContentLeft').setStyle({
					paddingTop: 0,
					backgroundImage: 'none'
				});
				$('TSW_mainContentWrap').setStyle({
					paddingTop: ''+(this.contentBanner.height+30)+'px',
					backgroundImage: 'url('+this.contentBanner.path+')'
				});
			}
			else
			{
				$('TSW_mainContentWrap').setStyle({
					paddingTop: 0,
					backgroundImage: 'none'
				});
				$('TSW_mainContentLeft').setStyle({
					paddingTop: ''+(this.contentBanner.height+30)+'px',
					backgroundImage: 'url('+this.contentBanner.path+')'
				});
			}
		}
	}
});

/**
 * Defines the relation between two (or more) 
 * corresponding contents of different languages
 * @param {Object} relation_obj
 */
var contentRelation = Class.create({
	initialize: function(relation_obj)
	{
		this.relation = relation_obj || null;
	},
	
	getContentNameByLang: function(lang)
	{
		return this.relation[lang];
	}
	
})
/**
 * Define the Pages-Array
 */
var pagesArray = new Array();

pagesArray[0] = new Page(0, {'de': '/DE/Pages/Profil/index.php',			'en': '/EN/Pages/Profile/index.php'});
pagesArray[1] = new Page(1, {'de': '/DE/Pages/Service/index.php', 		'en': '/EN/Pages/Service/index.php'});
pagesArray[2] = new Page(2, {'de': '/DE/Pages/Produkte/index.php', 		'en': '/EN/Pages/Products/index.php'});
pagesArray[3] = new Page(3, {'de': '/DE/Pages/Produktion/index.php',	'en': '/EN/Pages/Production/index.php'});
pagesArray[4] = new Page(4, {'de': '/DE/Pages/Kontakt/index.php', 		'en': '/EN/Pages/Contact/index.php'});
pagesArray[5] = new Page(5, {'de': '/DE/Pages/Sitemap/index.php', 		'en': '/EN/Pages/Sitemap/index.php'});
pagesArray[6] = new Page(6, {'de': '/DE/Pages/Partner/index.php', 		'en': '/EN/Pages/Partner/index.php'});

/**
 * Define the URL-Parameter-Array (will be filled in 'window.onload')
 */
var params = new Array();

/**
 * Define the Boxes for the Right Column
 */
var rightColumnBoxArray = new Array();
rightColumnBoxArray['Auswuchtservice']					= new rightColumnBox('/DE/Boxes/Auswuchtservice/index.html');
rightColumnBoxArray['Beschichtungsqualitaeten'] = new rightColumnBox('/DE/Boxes/Beschichtungsqualitaeten/index.html');
rightColumnBoxArray['CNC_Technik']							= new rightColumnBox('/DE/Boxes/CNC_Technik/index.html');
rightColumnBoxArray['Karte'] 										= new rightColumnBox('/DE/Boxes/Karte/index.html');
rightColumnBoxArray['Lagerhaltung']		 					= new rightColumnBox('/DE/Boxes/Lagerhaltung/index.html');
rightColumnBoxArray['Lieferprogramm'] 					= new rightColumnBox('/DE/Boxes/Lieferprogramm/index.html');
rightColumnBoxArray['Oberflaechentechnologie']	= new rightColumnBox('/DE/Boxes/Oberflaechentechnologie/index.html');
rightColumnBoxArray['Oberflaechentypen']				= new rightColumnBox('/DE/Boxes/Oberflaechentypen/index.html');
rightColumnBoxArray['Reparatur']								= new rightColumnBox('/DE/Boxes/Reparatur/index.html');
rightColumnBoxArray['Schleifservice']						= new rightColumnBox('/DE/Boxes/Schleifservice/index.html');
rightColumnBoxArray['Sonderformen']							= new rightColumnBox('/DE/Boxes/Sonderformen/index.html');
rightColumnBoxArray['Werkstatt_1'] 							= new rightColumnBox('/DE/Boxes/Werkstatt_1/index.html');
rightColumnBoxArray['Werkstatt_2'] 							= new rightColumnBox('/DE/Boxes/Werkstatt_2/index.html');

rightColumnBoxArray['CNC_Technology']						= new rightColumnBox('/EN/Boxes/CNC_Technology/index.html');
rightColumnBoxArray['CoatingQualities'] 				= new rightColumnBox('/EN/Boxes/CoatingQualities/index.html');
rightColumnBoxArray['CustomizedDesigns']				= new rightColumnBox('/EN/Boxes/CustomizedDesigns/index.html');
rightColumnBoxArray['GrindingService']					= new rightColumnBox('/EN/Boxes/GrindingService/index.html');
rightColumnBoxArray['Map']	 										= new rightColumnBox('/EN/Boxes/Map/index.html');
rightColumnBoxArray['PoolStore']	 							= new rightColumnBox('/EN/Boxes/PoolStore/index.html');
rightColumnBoxArray['ProductRange'] 						= new rightColumnBox('/EN/Boxes/ProductRange/index.html');
rightColumnBoxArray['Repairs']									= new rightColumnBox('/EN/Boxes/Repairs/index.html');
rightColumnBoxArray['RollerBalancing']					= new rightColumnBox('/EN/Boxes/RollerBalancing/index.html');
rightColumnBoxArray['SurfaceTechnologies']			= new rightColumnBox('/EN/Boxes/SurfaceTechnologies/index.html');
rightColumnBoxArray['SurfaceTypes']							= new rightColumnBox('/EN/Boxes/SurfaceTypes/index.html');
rightColumnBoxArray['Factory_1'] 								= new rightColumnBox('/EN/Boxes/Werkstatt_1/index.html');
rightColumnBoxArray['Factory_2'] 								= new rightColumnBox('/EN/Boxes/Werkstatt_2/index.html');

var rCBA = rightColumnBoxArray;

/**
 * Define the Content-Banners for the Pages
 */
var contentBannerArray = new Array();
contentBannerArray['Produkte'] 				= new contentBanner('/DE/ContentBanner/CB_Produkte.jpg', 205);
contentBannerArray['Sonderformen'] 		= new contentBanner('/DE/ContentBanner/CB_Sonderformen.jpg', 280);
contentBannerArray['Lieferprogramm'] 	= new contentBanner('/DE/ContentBanner/CB_Lieferprogramm.jpg', 176);
contentBannerArray['Produktion'] 			= new contentBanner('/DE/ContentBanner/CB_Werkstatt1.jpg', 206);
contentBannerArray['Werkstatt1'] 			= new contentBanner('/DE/ContentBanner/CB_Werkstatt_1.jpg', 206, true);
contentBannerArray['Werkstatt2'] 			= new contentBanner('/DE/ContentBanner/CB_Werkstatt_2.jpg', 206);
contentBannerArray['Service']					= new contentBanner('/DE/ContentBanner/CB_Service.jpg', 206);
contentBannerArray['Auswuchtservice']	= new contentBanner('/DE/ContentBanner/CB_Auswuchtservice.jpg', 246);
contentBannerArray['Produktion']			= new contentBanner('/DE/ContentBanner/CB_Produktion.jpg', 212);
contentBannerArray['Production']			= new contentBanner('/EN/ContentBanner/CB_Produktion.jpg', 212);
contentBannerArray['Anfahrt']					= new contentBanner('/src/0.gif', -22);

/**
 * Define the contents for the Pages
 */
var contents = new Array();
contents['de'] = new Array();
contents['en'] = new Array();

/**
 * Products
 */
// *** DE: Produkte
contents['de']['Produkte'] 							= new pageContent('/DE/Contents/Produkte/Produkte.html', [rCBA['Auswuchtservice'], rCBA['Oberflaechentechnologie'], rCBA['Sonderformen']], null, contentBannerArray['Produkte']);
contents['de']['Einsatzgebiete']				= new pageContent('/DE/Contents/Produkte/Einsatzgebiete.html', [rCBA['Beschichtungsqualitaeten'], rCBA['CNC_Technik'], rCBA['Sonderformen']], null, null);
contents['de']['Lieferprogramm']				= new pageContent('/DE/Contents/Produkte/Lieferprogramm.html', [rCBA['Auswuchtservice'], rCBA['CNC_Technik'], rCBA['Sonderformen']], null, contentBannerArray['Lieferprogramm']);
contents['de']['Oberflaechen']					= new pageContent('/DE/Contents/Produkte/Oberflaechen.html', [rCBA['Sonderformen'], rCBA['CNC_Technik'], rCBA['Reparatur']], null, null);
contents['de']['Sonderformen']					= new pageContent('/DE/Contents/Produkte/Sonderformen.html', [rCBA['Auswuchtservice'], rCBA['Oberflaechentechnologie']], null, contentBannerArray['Sonderformen']);

// *** EN: Products
contents['en']['Products'] 							= new pageContent('/EN/Contents/Products/Products.html', [rCBA['RollerBalancing'], rCBA['SurfaceTechnologies'], rCBA['CustomizedDesigns']], null, contentBannerArray['Produkte']);
contents['en']['Applications']				= new pageContent('/EN/Contents/Products/Applications.html', [rCBA['CoatingQualities'], rCBA['CNC_Technology'], rCBA['CustomizedDesigns']], null, null);
contents['en']['ProductRange']				= new pageContent('/EN/Contents/Products/ProductRange.html', [rCBA['RollerBalancing'], rCBA['CNC_Technology'], rCBA['CustomizedDesigns']], null, contentBannerArray['Lieferprogramm']);
contents['en']['Surfaces']							= new pageContent('/EN/Contents/Products/Surfaces.html', [rCBA['CustomizedDesigns'], rCBA['CNC_Technology'], rCBA['Repairs']], null, null);
contents['en']['CustomizedDesigns']			= new pageContent('/EN/Contents/Products/Customized.html', [rCBA['RollerBalancing'], rCBA['SurfaceTechnologies']], null, contentBannerArray['Sonderformen']);

/**
 * Contact
 */
// *** Contact/Kontakt
contents['de']['Kontakt']								= new pageContent('/DE/Contents/Kontakt/Impressum.html', [], null, null);
contents['de']['Map']										= new pageContent('/DE/Contents/Kontakt/Map.html', [], null, null);
contents['en']['Contact']								= new pageContent('/DE/Contents/Contact/Contact.html', [], null, null);

/**
 * Partners
 */
// *** DE: Partner
contents['de']['Partner']								= new pageContent('/DE/Contents/Partner/Partner.html', [], null, null);

// *** EN: Partners
contents['en']['Partners']							= new pageContent('/EN/Contents/Partners/Partners.html', [], null, null);

/**
 * Production
 */
// *** DE: Produktion
contents['de']['Produktion']						= new pageContent('/DE/Contents/Produktion/Produktion.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Produktion']);

contents['de']['Gummiwalzen']						= new pageContent('/DE/Contents/Produktion/Produktion.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Produktion']);

contents['de']['Auftragsgummierungen']	= new pageContent('/DE/Contents/Produktion/Produktion.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Produktion']);

contents['de']['Raeder_Rollen']					= new pageContent('/DE/Contents/Produktion/Produktion_2.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Produktion'], 'Raeder_Rollen');

contents['de']['Dreherei']							= new pageContent('/DE/Contents/Produktion/Produktion_2.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Produktion']);

// *** EN: Production
contents['en']['Production']						= new pageContent('/EN/Contents/Production/Production.html', [rCBA['ProductRange'], rCBA['SurfaceTypes'], rCBA['CoatingQualities']], null, contentBannerArray['Production']);

contents['en']['RubberRollers']						= new pageContent('/EN/Contents/Production/Production.html', [rCBA['ProductRange'], rCBA['SurfaceTypes'], rCBA['CoatingQualities']], null, contentBannerArray['Production']);

contents['en']['Rubberizing']	= new pageContent('/EN/Contents/Production/Production.html', [rCBA['ProductRange'], rCBA['SurfaceTypes'], rCBA['CoatingQualities']], null, contentBannerArray['Production']);

contents['en']['Wheels_Rollers']					= new pageContent('/EN/Contents/Production/Production_2.html', [rCBA['ProductRange'], rCBA['SurfaceTypes'], rCBA['CoatingQualities']], null, contentBannerArray['Production']);

contents['en']['LatheOperation']						= new pageContent('/EN/Contents/Production/Production_2.html', [rCBA['ProductRange'], rCBA['SurfaceTypes'], rCBA['CoatingQualities']], null, contentBannerArray['Production']);

/**
 * Profile
 */
// *** DE: Profil
contents['de']['Werkstatt_1']						= new pageContent('/DE/Contents/Profil/Werkstatt_1.html', [rCBA['Karte'], rCBA['Werkstatt_1']], null, contentBannerArray['Werkstatt1']);
contents['de']['Werkstatt_2']						= new pageContent('/DE/Contents/Profil/Werkstatt_2.html', [rCBA['Werkstatt_2'], rCBA['Beschichtungsqualitaeten']], null, contentBannerArray['Werkstatt2']);

// *** EN: Profile
contents['en']['Werkstatt_1']						= new pageContent('/EN/Contents/Profile/Werkstatt_1.html', [rCBA['Map'], rCBA['Factory_1']], null, contentBannerArray['Werkstatt1']);
contents['en']['Werkstatt_2']						= new pageContent('/EN/Contents/Profile/Werkstatt_2.html', [rCBA['Factory_2'], rCBA['CoatingQualities']], null, contentBannerArray['Werkstatt2']);

/**
 * Service
 */
// *** DE: Service
contents['de']['Service']								= new pageContent('/DE/Contents/Service/Service.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentechnologie'],rCBA['Sonderformen']], null, contentBannerArray['Service']);
contents['de']['Auswuchtservice']				= new pageContent('/DE/Contents/Service/Auswuchtservice.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentypen']], null, contentBannerArray['Auswuchtservice']);
contents['de']['Schleifservice']				= new pageContent('/DE/Contents/Service/Schleifservice.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentechnologie'], rCBA['Sonderformen']], null, null);
contents['de']['Lagerhaltung']					= new pageContent('/DE/Contents/Service/Schleifservice.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentechnologie'],rCBA['Sonderformen']], null, null);
contents['de']['Reparatur']							= new pageContent('/DE/Contents/Service/Schleifservice.html', [rCBA['Lieferprogramm'], rCBA['Oberflaechentechnologie'],rCBA['Sonderformen']], null, null);

// *** EN: Service
contents['en']['Service']								= new pageContent('/EN/Contents/Service/Service.html', [rCBA['ProductRange'], rCBA['SurfaceTechnologies'],rCBA['CustomizedDesigns']], null, contentBannerArray['Service']);
contents['en']['RollerBalancing']				= new pageContent('/EN/Contents/Service/Balancing.html', [rCBA['ProductRange'], rCBA['SurfaceTypes']], null, contentBannerArray['Auswuchtservice']);
contents['en']['Grinding']						= new pageContent('/EN/Contents/Service/Grinding.html', [rCBA['ProductRange'], rCBA['SurfaceTechnologies'],rCBA['CustomizedDesigns']], null, null);
contents['en']['PoolStore']						= new pageContent('/EN/Contents/Service/Grinding.html', [rCBA['ProductRange'], rCBA['SurfaceTechnologies'],rCBA['CustomizedDesigns']], null, null);
contents['en']['Repairs']							= new pageContent('/EN/Contents/Service/Grinding.html', [rCBA['ProductRange'], rCBA['SurfaceTechnologies'],rCBA['CustomizedDesigns']], null, null);

/**
 * Contact
 */
contents['de']['Anfahrt']								= new pageContent('/DE/Contents/Kontakt/Anfahrt.html', [rCBA['Werkstatt_1'], rCBA['Werkstatt_2']], null, contentBannerArray['Anfahrt']);

contents['en']['Map']										= new pageContent('/EN/Contents/Contact/Map.html', [rCBA['Factory_1'], rCBA['Factory_2']], null, contentBannerArray['Anfahrt']);

// *** Relations between the contents of the different languages
var contentRelationsArray = new Array();

// *** Products/Produkte
contentRelationsArray[0] = new contentRelation({'de': 'Produkte', 							'en': 'Products'});
contentRelationsArray[1] = new contentRelation({'de': 'Einsatzgebiete', 				'en': 'Applications'});
contentRelationsArray[2] = new contentRelation({'de': 'Lieferprogramm', 				'en': 'ProductRange'});
contentRelationsArray[3] = new contentRelation({'de': 'Oberflaechen', 					'en': 'Surfaces'});
contentRelationsArray[4] = new contentRelation({'de': 'Sonderformen', 					'en': 'CustomizedDesigns'});

// *** Service/Service
contentRelationsArray[5] = new contentRelation({'de': 'Service', 								'en': 'Service'});
contentRelationsArray[6] = new contentRelation({'de': 'Auswuchtservice', 				'en': 'RollerBalancing'});
contentRelationsArray[7] = new contentRelation({'de': 'Schleifservice', 				'en': 'Grinding'});
contentRelationsArray[8] = new contentRelation({'de': 'Lagerhaltung', 					'en': 'PoolStore'});
contentRelationsArray[9] = new contentRelation({'de': 'Reparatur', 							'en': 'Repairs'});

// *** Production/Produktion
contentRelationsArray[11] = new contentRelation({'de': 'Produktion', 						'en': 'Production'});
contentRelationsArray[12] = new contentRelation({'de': 'Gummiwalzen',						'en': 'RubberRollers'});
contentRelationsArray[13] = new contentRelation({'de': 'Raeder_Rollen',					'en': 'Wheels_Rollers'});
contentRelationsArray[14] = new contentRelation({'de': 'Dreherei',							'en': 'LatheOperation'});
contentRelationsArray[15] = new contentRelation({'de': 'Auftragsgummierungen',	'en': 'Rubberizing'});

// *** Profile/Profil
contentRelationsArray[16] = new contentRelation({'de': 'Werkstatt_1',	'en': 'Werkstatt_1'});
contentRelationsArray[17] = new contentRelation({'de': 'Werkstatt_2',	'en': 'Werkstatt_2'});

// *** Contact/Kontakt
contentRelationsArray[18] = new contentRelation({'de': 'Kontakt',	'en': 'Contact'});
contentRelationsArray[19] = new contentRelation({'de': 'Anfahrt',	'en': 'Map'});

// *** Partners/Partner
contentRelationsArray[20] = new contentRelation({'de': 'Partner',	'en': 'Partners'});

/**
 * Globals
 */
var currentLang = null;
var currentPage = null;
var currentContent = null;



/*************************
 * Start the whole thing
 *************************/
window.onload = function()
{ 

	// *** Register clicks on the Subnavigation-Anchors
	$$('#TSW_subNavi a').each(
		function(item) 
		{
			item.observe('click', clickOnSubnaviAnchor);
		}
	)
	
	// *** Parse the Query-String (URL-Parameters)
	if (window.location.search != '')
	{
		query_string = window.location.search.substring(1);
		search_array = query_string.split('&');
		for ( var i = 0; i < search_array.length; i++)
		{
			key_value = search_array[i].split('=');
			key 	= key_value[0];
			value = key_value[1];
			params[key] = value; 
		}
	}

	// *** Get the requested language from lang-Parameter (GET)
	// *** or read it from the lang-Attribute of the html-Tag (set by PHP from GET['lang], SESSION or Browser-Default-Lang)
	if (params.lang)
	{
		currentLang = params.lang;
	}
	else
	{
		el = $$('html')[0];
		currentLang = el.readAttribute('lang');
	}

	// *** Show the requested Sub-Page
	// *** (use ?page=XYZ, where XYZ is the Index of the contents-Array)
	if (params.page)
	{
		currentContent = params.page;
		content = contents[currentLang][params.page];
		content.change();
		activateSubnaviAnchor(params.page);
	}
	
	// *** Show Modalbox if desired 
	// *** (use ?modal=XYZ, where XYZ is 'danke' for DE and 'thanks' for EN)
	if (params.modal)
	{
		switch (params['modal'].toLowerCase())
		{
			case 'danke':
				Modalbox.show('/DE/PopUps/danke.html', {title: 'DANKE', width: 300}); 
				break;
			case 'thanks':
				Modalbox.show('/EN/PopUps/danke.html', {title: 'THANKS', width: 300}); 
				break;
		}
	}
}

/**
 * Fires when clicked on a sub-navigation anchor
 * @param {Object} event
 */
function clickOnSubnaviAnchor(event)
{
	// *** Get Event-Element
	var el = event.element();
	// *** Get href-Attribute from Anchor
	var pageName = el.readAttribute('rel');
	
	// *** Remove Active-Class from all Anchors in the Sub-Menu
	$$('div#TSW_subNavi a').each(
		function(item) {
			item.removeClassName('TSW_active');
		}
	);
	// *** Add Active-Class to clicked Anchor
	el.addClassName('TSW_active');
	// *** Get the Content-Name
	content = contents[currentLang][pageName];
	currentContent = pageName;
	// *** Change the Contents
	content.change();
	// *** Don't propagate with Click-Event (don't load initial href)
	Event.stop(event);
	
	currentContent = pageName;
	
	return(false);
}

/**
 * Activate the Subnavi-Anchor if a subpage is requested
 * @param {String} page (must equal the rel-Attribute of the Anchor to hit)
 */
function activateSubnaviAnchor(page)
{
	$$('div#TSW_subNavi a').each(
		function(item) {
			if (page == item.readAttribute('rel'))
			{
				item.addClassName('TSW_active');			
			}
			else
			{
				item.removeClassName('TSW_active');
			}
		}
	);
	
}

/**
 * 
 * @param {String} fromLang
 * @param {String} toLang
 */
function changeLanguage(fromLang, toLang)
{
	var thisPage = null;
	var pathname = window.location.pathname;
	pagesArray.each(function(p)
	{
		if (p.getPath(fromLang) == pathname) 
		{
			thisPage = p;
			return false;
		}
	});
	if (currentContent)
	{
		contentRelationsArray.each(function(cr)
		{
			if (cr.getContentNameByLang(currentLang) == currentContent) 
			{
				thisContent = cr;
				return false;
			}
		});
		window.location.href = window.location.protocol + '//' + window.location.host + thisPage.getPath(toLang) + '?lang=' + toLang + '&page=' + thisContent.getContentNameByLang(toLang);
	}
	else
	{
		window.location.href = window.location.protocol + '//' + window.location.host + thisPage.getPath(toLang) + '?lang=' + toLang;
		
	}
	return false;
}

/**
 * Just for Debugging
 * @param {Object} obj
 */
function outputObject(obj) {
	var ret = '';
	for (var key in obj)
	{
		ret = ret + key + ' = ' + obj[key] + '\n';
	}
	return ret;
}

