// Coding by Marco De Luca - DeLucaMarketing.ch */
/* V1.31 - 2008-07-15 */

var debug = false;
var displayTop=0;
var theMove = 0;
var byIdExists = typeof document.getElementById;	//	check if we have a modern browser

function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')				window.addEventListener('load', fn, false);
	else if (typeof document.addEventListener != 'undefined')	document.addEventListener('load', fn, false);
	else if (typeof window.attachEvent != 'undefined')				window.attachEvent('onload', fn);
	else
	{
		var oldfn = window.onload;
		if (typeof window.onload != 'function')	 window.onload = fn;
		else													{window.onload = function(){oldfn(); fn();};}
	}
}

// set interval for logo movement
function move()
{
	theMove = setInterval("moveElement()",10);
}

// move the logo
function moveElement()
{
	if (self.pageYOffset) // all except Explorer
	{
		ydiff = displayTop - self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)	// Explorer 6 Strict
	{
		ydiff = displayTop - document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		ydiff = displayTop - document.body.scrollTop;
	}

	if(ydiff != 0)
	{
		displayTop -= Math.round(ydiff/10);
		displayTop < 80 ? faktor = displayTop : faktor = 80;

		if(document.getElementById)
		{
			document.getElementById("you").style.top = displayTop-faktor + "px";
			if (debug) window.status = "W3C: " + displayTop + " | " + ydiff;
		}
		else if (document.all)
		{
			document.all.theWanderingElement.style.top=displayTop;
			if (debug) window.status = "IE: " + displayTop + " | " + ydiff;
		}
	}
}



/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);


/*
 * Metadata - jQuery plugin for parsing metadata from elements
 * Copyright (c) 2006 John Resig, Yehuda Katz, J?örn Zaefferer, Paul McLanahan
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * Revision: $Id: jquery.metadata.js 3620 2007-10-10 20:55:38Z pmclanahan $
 */
(function($){$.extend({metadata:{defaults:{type:'class',name:'metadata',cre:/({.*})/,single:'metadata'},setType:function(type,name){this.defaults.type=type;this.defaults.name=name;},get:function(elem,opts){var settings=$.extend({},this.defaults,opts);if(!settings.single.length)settings.single='metadata';var data=$.data(elem,settings.single);if(data)return data;data="{}";if(settings.type=="class"){var m=settings.cre.exec(elem.className);if(m)data=m[1];}else if(settings.type=="elem"){if(!elem.getElementsByTagName)return;var e=elem.getElementsByTagName(settings.name);if(e.length)data=$.trim(e[0].innerHTML);}else if(elem.getAttribute!=undefined){var attr=elem.getAttribute(settings.name);if(attr)data=attr;}if(data.indexOf('{')<0)data="{"+data+"}";data=eval("("+data+")");$.data(elem,settings.single,data);return data;}}});$.fn.metadata=function(opts){return $.metadata.get(this[0],opts);};})(jQuery);





// popup window stuff
var popupWin;
function openWindow(url, name, w, h, flags)	// 1.01
{
	//	flags = 'directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes';
	w = (w > screen.availWidth)  ? screen.availWidth  - 40 : w;
	h = (h > screen.availHeight) ? screen.availHeight - 120 : h;
	var winX = (screen.availWidth - w) / 2;
	var winY = (screen.availHeight - h) / 2;
	// if (popupWin && !popupWin.closed) popupWin.close();
	popupWin = window.open(url, name, 'width=' + w + ',height=' + h + ', left=' + winX + ',top=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',' + flags);
	popupWin.focus();
}

// opens popup window with flash sound controler
var SoundControllerWindow = false;
function openSoundcontroller(url, name)
{
	// size of client window
	w = 130;
	h = 130;

	// get x-position of actual window
	var winX = 0;
	if (typeof screenX != 'undefined')
	{
		winX = screenX;
	}
	else if (typeof screenLeft != 'undefined')
	{
		winX = screenLeft;
	}

	// get width of actual window
	var winWidth = 0;
	if (typeof outerWidth != 'undefined')
	{
		winWidth = outerWidth;
	}
	else if (typeof document.documentElement.clientWidth != 'undefined')
	{
		winWidth = document.documentElement.clientWidth+25;
	}

	// calculate position for client window
	winX += winWidth;
	if (winX > screen.availWidth-130) // make sure it's not beyond screen coordinates
	{
		winX = screen.availWidth-130;
		if (identifyBrowser() == 'ie6')	// make ie corrections (forget about 5+)
			winX-=10;
	}

	var winY = 0;
	if (typeof screenY != 'undefined')
	{
		winY = screenY;
	}
	else if (typeof screenTop != 'undefined')
	{
		winY = screenTop;
	}

	flags = 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no';
	SoundControllerWindow = window.open(url, 'Sound', 'width=' + w + ',height=' + h + ', left=' + winX + ',top=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',' + flags);
	SoundControllerWindow.focus();
}

// simple browser identification (only needed for popup of sound controller)
function identifyBrowser()
{
	var agent = navigator.userAgent.toLowerCase();
	if (typeof document.all != "undefined")
	{
		if (typeof document.getElementById != "undefined")
		{
			var browser = agent.replace(/.*ms(ie[\/ ][^ $]+).*/, "$1").replace(/ /, "");
			if (typeof document.uniqueID != "undefined")
			{
				if (browser.indexOf("5.5") != -1)	return browser.replace(/(.*5\.5).*/, "$1");
				else											return browser.replace(/(.*)\..*/, "$1");
			}
			else
			{
				return "ie5mac";
			}
		}
		return false;
	}
	return false;
}

// reopens sound controller if it was temporarilly shut down (e.g. the video controller was playing)
function checksound()
{
	if(soundflag)
	{
		winX = getCookieValue('soundx');
		winY = getCookieValue('soundy');
		w = 130;
		h = 130;
		flags = 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no';
		SoundControllerWindow = window.open('../sound/sound.html', 'Sound', 'width=' + w + ',height=' + h + ', left=' + winX + ',top=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',' + flags);
	}
}

/*==============================================================================

Routine to write a session cookie

    Parameters:
        cookieName        Cookie name
        cookieValue       Cookie Value
    
    Return value:
        true              Session cookie written successfullly
        false             Failed - persistent cookies are not enabled

   e.g. if (writeSessionCookie("sound","on") then
           alert ("Session cookie written");
        else
           alert ("Sorry - Session cookies not enabled");
*/

function writeSessionCookie (cookieName, cookieValue)
{
	if (testSessionCookie())
	{
		document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		return true;
	}
	else return false;
}

/*==============================================================================

get the current value of a cookie

Parameters:		cookieName		Cookie name
Return value:	false				Failed - no such cookie
					value				Value of the retrieved cookie

e.g. if (!getCookieValue("sound"))
          cookieValue = getCoookieValue ("pans2);
*/
function getCookieValue (cookieName)
{
	var exp = new RegExp (escape(cookieName) + "=([^;]+)");
	if (exp.test (document.cookie + ";"))
	{
		exp.exec (document.cookie + ";");
		return unescape(RegExp.$1);
	}
	else return false;
}

function testSessionCookie()
{
	document.cookie ="testSessionCookie=Enabled";
	return getCookieValue ("testSessionCookie")=="Enabled";
}

function soundInit()
{
	if (!byIdExists)	return false;

	try
	{
		var soundLink = document.getElementById('sound');		// find a#sound (which is invisible by CSS
		soundLink.style.display = "inline";							// make it visible, since we have JavaScript
		if(soundLink)
		{
			// install the onclick handler
			soundLink.onclick = function() {openSoundcontroller(soundLink.href+'?'+document.URL, 'SoundControllerWindow'); return false;}

			var soundIcon = document.getElementById('si');	// get the IMG#si
			if (soundIcon)
			{
				// this makes it work from subdirs too
				uri = soundIcon.src;					// uri to soundicon image
				i = uri.lastIndexOf("/") + 1;		// find last '/'
				path = uri.substr(0,i);				// extract path

				// install rollover handler
				soundLink.onmouseover = function() {soundIcon.src = path + 'sound-over.gif';}
				soundLink.onmouseout  = function() {soundIcon.src = path + 'sound.gif';}
			}
		}
	}
	catch (err) {return false;}
}
addLoadListener(soundInit);


$(document).ready(function()
{
	if(!$('#home').is('body'))				// on all pages except home.html install sliding logo
	{
		addLoadListener(move);
	}


	if($('#jumpmenu').is('form'))			// Jumpmenu
	{
		$('#jumpmenu').show();
		$('#colright h2').each(function(i)
		{
			title = $(this).text().slice(10);
			titlemaxlen = 57;
			if(title.length > titlemaxlen)
			{
				title = title.slice(0,titlemaxlen) + '...';
			}
			$(this).attr('id','a'+i);
			$('#select').append('<option value="#a' + i + '" selected>' + title + '</option>');
		});
		$('#select').change(function()
		{
			s = this.options[this.selectedIndex].value;
			$.scrollTo(s,800);
			document.jumpmenu.reset();
		});
		document.jumpmenu.reset();
		$('.homeanchor a').click(function()
		{
			$.scrollTo(0,400);
			return false;
		});
	}


});