var MagSbg = MagSbg || { /*begin_debug_only*/__namespace: true /*end_debug_only*/ };

///////////////////////////////////////////////////////////////////////////////////////////////////
//  CLASS MAGSBG.CMS  /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
function MagSbg$CMS ()
{
	this.__portletTabs = [];
	this.__portletTabButtons = [];
	this.__originalCharset = (typeof (document.charset)!="undefined"?document.charset:null);
	
	// ----- constructor
	try
	{
// TODO: DCal 20101220 > implement a global domready event (in MagSbg.UserAgent based on MagSbg.Event)
		if (MagSbg.UserAgent) // we are on an interneu page
		{
			var currentObject = this, domReadyHandler = function () { currentObject.__Initialize (); };
			if (document.addEventListener) document.addEventListener ("DOMContentLoaded", domReadyHandler, false);
			else this.__CheckDOMReadyIE ();
		} // if
	}
	catch (ex)
	{
		// default fsc error handler ;-)
	} // try
} // MagSbg$CMS

MagSbg$CMS.prototype.__CheckDOMReadyIE = 
	function ()
	{
		if (document.documentElement.doScroll)
		{
			try
			{
				document.documentElement.doScroll ("left");
				this.__Initialize ();
			}
			catch (ex)
			{
				var currentObject = this;
				setTimeout (function () { currentObject.__CheckDOMReadyIE (); }, 0);
			} // try
		}
		else window.attachEvent ("onload", this.__Initialize ());
	} // __CheckDOMReadyIE

MagSbg$CMS.prototype.__OpenNewWindow = 
	function (url, name, parameters)
	{
		window.open (url, name, parameters);
	} // __OpenNewWindow

MagSbg$CMS.prototype.OpenGalleryImagePage = 
	function (anchorObject, url)
	{
		anchorObject.href = "javascript:void(0)";
		anchorObject.target = "_self";
		this.__OpenNewWindow (url, "", "");
	} // OpenGalleryImagePage

MagSbg$CMS.prototype.CloseGalleryImagePage = 
	function (anchorObject)
	{
		if (window.opener)
		{
			anchorObject.href = "javascript:void(0)";
			anchorObject.target = "_self";
			window.close ();
		} // if
	} // CloseGalleryImagePage

MagSbg$CMS.prototype.OpenContactPage = 
	function (anchorObject, url)
	{
		this.OpenGalleryImagePage (anchorObject, url);
	} // OpenContactPage

MagSbg$CMS.prototype.OpenSendAsEmailPage = 
	function (anchorObject, url)
	{
		this.OpenGalleryImagePage (anchorObject, url);
	} // OpenSendAsEmailPage

MagSbg$CMS.prototype.OpenShopCartPage = 
	function (anchorObject, url)
	{
		this.OpenGalleryImagePage (anchorObject, url);
	} // OpenSendAsEmailPage

MagSbg$CMS.prototype.ShowWebCast = 
	function (name)
	{
		window.open ('/MagSbg.CMS.WebPages/WebCast.aspx?path='+name, '_blank', 'height=650,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=1000');
	} // ShowWebCast

MagSbg$CMS.prototype.ShowParserImages = 
	function (parserPath, pageUrl)
	{
		document.getElementById ("parserImageXHTML").src = parserPath + "CheckXHTML.aspx?url=" + pageUrl + "&width=53&height=15";
		document.getElementById ("parserImageWAI").src = parserPath + "CheckWAI.aspx?url=" + pageUrl + "&width=35&height=15";
	} // ShowParserImages

MagSbg$CMS.prototype.CorrectAnnoyingIECharsetBug = 
	function ()
	{
		// ----- used by the library search form
		document.getElementById ("searchForm").attachEvent ("onsubmit", function () { document.charset = "iso-8859-1"; });
		var originalCharset = this.__originalCharset;
		window.attachEvent ("onunload", function () { document.charset = originalCharset; });
	} // CorrectAnnoyingIECharsetBug

MagSbg$CMS.prototype.__SwitchPortletTab =
	function (clickEvent, clickedButton)
	{
		// ----- set style classes
		for (var i=0; i < this.__portletTabButtons.length; i++)
		{
			if (this.__portletTabButtons[i]==clickedButton)
			{
				this.__portletTabButtons[i].className += " tabButtonSelected";
				this.__portletTabs[i].className += " tabContentSelected";
			}
			else
			{
				this.__portletTabButtons[i].className = this.__portletTabButtons[i].className.replace (" tabButtonSelected", "");
				this.__portletTabs[i].className = this.__portletTabs[i].className.replace (" tabContentSelected", "");
			} // if
		} // for
		
		// ----- cancel url navigation
		(clickEvent.preventDefault?clickEvent.preventDefault ():clickEvent.returnValue = false);
	} // __SwitchPortletTab

MagSbg$CMS.prototype.__Initialize = 
	function ()
	{
// TODO: migrate to MagSbg.Event
		try
		{
// PORTLET TABS ///////////////////////////////////////////////////////////////////////////////////
			// ----- get button and content elements
			var browser = MagSbg.UserAgent.Get_Browser ();
			var tabsElement = document.getElementById ("portletTabs");
			if (tabsElement && (browser.Name!=MagSbg.Browser.InternetExplorer || browser.Version > 7))
			{
				// ----- get button div elements and content div elements and determine the maximum content height
				var elementClass = "", maxContentHeight = 0, currentListHeight;
				for (var i=0; i < tabsElement.childNodes.length; i++)
				{
					elementClass = tabsElement.childNodes[i].className;
					if (elementClass && elementClass.indexOf ("tabButton")==0) this.__portletTabButtons.push (tabsElement.childNodes[i]);
					else if (elementClass && elementClass.indexOf ("tabContent")==0)
					{
						this.__portletTabs.push (tabsElement.childNodes[i]);
						currentListHeight = tabsElement.childNodes[i].getElementsByTagName ("ul")[0].offsetHeight;
						if (currentListHeight > maxContentHeight) maxContentHeight = currentListHeight;
					} // if
				} // for
				
				// ----- create the tab navigation
				if (this.__portletTabButtons.length==this.__portletTabs.length)
				{
					// ----- get number of pixels of 1em
					var oneEmInPixels = document.getElementById ("tabSizeReference").offsetWidth;
					
					// ----- set button and content style to form the tabs
					var previousButtonsWidth = 0, domEvents = document.addEventListener;
					var currentObject = this;
					var switchTabHandler = function () { 
							var clickEvent = (arguments[0] || event);
							var clickedButton = (arguments[0].target || event.srcElement).parentNode;
							currentObject.__SwitchPortletTab (clickEvent, clickedButton); 
						};
					for (var i=0; i < this.__portletTabButtons.length; i++)
					{
						// ----- normalize tab content height
						this.__portletTabs[i].getElementsByTagName ("ul")[0].style.height = (maxContentHeight / oneEmInPixels) + "em";
						
						// ----- set necessary style classes
						if (i==0) this.__portletTabs[i].className += " tabContentFirst";
						else
						{
							this.__portletTabButtons[i].className = "tabButton tabButtonManaged";
							this.__portletTabButtons[i].style.left = (previousButtonsWidth / oneEmInPixels) + "em";
							this.__portletTabs[i].className = "tabContent";
						} // if
						
						// ----- remember width of all buttons to position the next one
						previousButtonsWidth += this.__portletTabButtons[i].offsetWidth + 3;
						
						// ----- register event handler for tab button clicks
						(domEvents?this.__portletTabButtons[i].firstChild.addEventListener ("click", switchTabHandler, false):
							this.__portletTabButtons[i].firstChild.attachEvent ("onclick", switchTabHandler));
					} // for
				} // if
			} // if
			
// PRINT BUTTON ///////////////////////////////////////////////////////////////////////////////////
			var printButton = document.getElementById ("print");
			if (printButton) printButton.style.display = "inline";
			
// DATE PICKER ////////////////////////////////////////////////////////////////////////////////////
			if (document.getElementById ("datepicker"))
			{
				$("#datepicker div").remove ();
				var d = new Date();
				$("#datepicker").datepicker({
					minDate:d, //Date.parse('today'),
					dateFormat: 'yymmdd',
					onSelect: function(dateText, inst) { 
						window.open('http://www.salzburgermonat.at/index.php?catID=all&re_location=1&date='+dateText,'_blank');
					}
				});
			} // if
			
// VIDEO PLAYLIST /////////////////////////////////////////////////////////////////////////////////
			try
			{
				if (document.getElementById ("video_box"))
				{
					$(function() {$("ul.video").ytplaylist();});
				} // if
			}
			catch (ex)
			{
			} // try
			
// LIBRARY VIRTUAL TOUR ///////////////////////////////////////////////////////////////////////////
			if ($.colorbox) $("a[href='http://www.stadt-salzburg.at/BiblioTour']").colorbox({innerWidth:"860px", innerHeight:"640px", iframe:true, title:"unterst&uuml;tzt vom Verein der Freunde der Stadtbibliothek"});
			
// PLACEHOLDERS ///////////////////////////////////////////////////////////////////////////////////
			$("input[placeholder]").enablePlaceholder();
			
// SYNC ARTICLE TITLE HEIGHTS /////////////////////////////////////////////////////////////////////
			var teasers = $("#articleOverview li");
			//alert (teasers.length);
			if (teasers.length > 0)
			{
				// ----- get number of pixels of 1em
				var oneEmInPixels = 0, i = 0, sizeRefNodes = null;
				while (oneEmInPixels==0 && i < teasers.length)
				{
					sizeRefNodes = $(".sizeReference", teasers[i++]);
					if (sizeRefNodes.length > 0) oneEmInPixels = sizeRefNodes[0].offsetWidth / 10;
				} // while
				
				//alert (oneEmInPixels);
				if (oneEmInPixels > 0)
				{
					for (var i=0; i < teasers.length - 1; i++)
					{
						//alert (teasers[i].className+"/"+teasers[i+1].className);
						if (($(teasers[i]).hasClass ("menuRow_2_cloum_img") || $(teasers[i]).hasClass ("menuRow_2_cloum")) && 
							($(teasers[i+1]).hasClass ("menuRow_2_cloum_img_right") || $(teasers[i+1]).hasClass ("menuRow_2_cloum_right")))
						{
							var leftHeading = $("h2", teasers[i])[0]; var rightHeading = $("h2", teasers[i+1])[0];
							var leftHeight = leftHeading.offsetHeight; var rightHeight = rightHeading.offsetHeight;
							
							if (leftHeight > rightHeight) rightHeading.style.height = (leftHeading.offsetHeight / oneEmInPixels) + "em";
							else leftHeading.style.height = (rightHeading.offsetHeight / oneEmInPixels) + "em";
						} // if
					} // for
				} // if
			} // if
		}
		catch (ex)
		{
			//alert (ex.message);
			// default fsc error handler ;-)
		} // try
	} // __Initialize

MagSbg.CMS = new MagSbg$CMS ();

if (parent.frames.length > 0 && parent.frames.length!=2) { window.top.location.href = this.location; }





/*DCal 20090831 > this function is needed for compatability reasons only because of links inside page contents; also MagSbg.CMS.WebPages makes use of it*/
function CD_ShowCitymap (by, arrParams)
{
	var gisServer = "http://gis.stadt-salzburg.at/";
	if (this.location.host.toLowerCase().indexOf (".gv.at") > 0) gisServer = "http://gis.stadt-salzburg.gv.at/";
	
	switch (by)
	{
		case "address":		// params: 0...strassennummer, 1...hausnummer mit alphazeichen
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?address='+arrParams[0]+'-'+arrParams[1], 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		case "office":		// params: 0...encrypted office code
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?office='+arrParams[0], 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		case "theme":		// params: 0...name des themas
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?' + arrParams[0] + '=1', 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		case "code":		// params: 0...code
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?code=' + arrParams[0], 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		case "meeting":		// params: 0...code
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?meeting=' + arrParams[0], 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		case "appl":		// params: 0...appl, 0...appl_part
			var giswindow = window.open (gisServer + 'citymap/citymap.asp?appl=' + arrParams[0] + '&appl_param=' + arrParams[1], 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
			break;
		default:
			var giswindow = window.open (gisServer + 'citymap/citymap.asp', 'frCityMap', 'height=550, locationbar=no, menubar=no, resizable=yes, status=yes, width=800, top=0, left=0'); 
	}
} // CD_ShowCitymap

/*DCal 20090831 > this function is needed for compatability reasons only because of links inside page contents*/
function CD_ShowWebCast (name)
{
	MagSbg.CMS.ShowWebCast (name);
} // CD_ShowWebCast
