var info = new Hash();
var userPicX = 0;

Event.observe(window, 'load', init, false);

/*
var WindowSize = Class.create({
    width: window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth),
    height: window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight)
});
*/
var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
var viewportWidth = viewport.width; // Usable window width
var viewportHeight = viewport.height; // Usable window height


sfHover = function() {
	var sfEls = document.getElementById("mainNav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function init()
{
	
	//Section Animations
	if($$('#sections div.section') != '') {
	$$('#sections div.section').each(
		function(section)
		{
			section.onmouseover=function() {
				this.down('div.layer').appear({duration: 0.6});
				this.down('div.title').setStyle('color:#00869a;');
			
			}
			section.onmouseout=function() {
				this.down('div.layer').fade({duration: 0.6});
				this.down('div.title').setStyle('color:#ffffff;');
			}
			section.onclick=function() {
				document.location=this.down('a').href;
			}
		}
	);
	}
	// $$('div.section a.link').each(
	// 	function(section)
	// 	{
	// 		section.onmouseover=function() {
	// 			this.next('div.layer').appear({duration: 0.6});
	// 			this.next('div.title').morph('color:#00869a;', {duration: 0.6});
	// 			// alert(this);
	// 		}
	// 		section.onmouseout=function() {
	// 			this.next('div.layer').fade({duration: 0.6});
	// 			this.next('div.title').morph('color:#ffffff;', {duration: 0.6});
	// 			
	// 			//alert(this.down('a'));
	// 		}
	// 		
	// 	}
	// );
	// }
	
	//teaser rollover
	if($$('#teaserBox div.section') != '') {
		$$('#teaserBox div.section a').each(
			function(teaser)
			{
				teaser.onmouseover=function() {
					// alert(this.down('a'));
					this.down('h1').morph('color:#00869a;', {duration: 0.6});
					this.down('p').morph('color:#00869a;', {duration: 0.6});
				}
				teaser.onmouseout=function() {
					// alert(this.down('a'));
					this.down('h1').morph('color:#707070;', {duration: 0.6});
					this.down('p').morph('color:#707070;', {duration: 0.6});
				}
			}
			);
	}
	
	//infobox info
	if($('infoBoxInfo')) {
		new Tip(
			'infoBoxInfo',
			{
				target: 'infoBox',
				title: infoBoxTitle,
				style: 'default',
				viewport: true,
				showOn: 'click',
				hideOn: 'click',
				hideOthers: true,
				closeButton: true,
				width: 'auto',
				hook: { target: 'leftMiddle', tip: 'rightMiddle' },
				stem: 'rightMiddle',
				offset: { x: 0, y: 0 },
				ajax: {
					url: '/ajax/infoBoxInfo.php',
					options:
					{
						parameters: 'lg='+LG
					}
				}
			}
		);
		if (infoBoxInfoShow == 1)
		{
			$('infoBoxInfo').prototip.show();
		}
	}

	//glossar
	$$('span.underline').each(function(element)
	{
		element.addClassName('glossary');
		new Tip(
			element,
			{
				target: element,
				// title: element.innerHTML,
				title: glossarTitle,
				style: 'default',
				viewport: true,
				showOn: 'click',
				hideOn: 'click',
				hideOthers: true,
				closeButton: true,
				width: 'auto',
				hook: { target: 'topMiddle', tip: 'bottomMiddle' },
				stem: 'bottomMiddle',
				offset: { x: 0, y: 0 },
				ajax: {
					url: '/ajax/glossary.php',
					options:
					{
						parameters: 'string='+element.innerHTML.stripTags()
					}
				}
			}
		);
	});





	
}

function getInfo(mode) {
	if (mode == 'all')
		var infoString = $('infoBoxForm').serialize() + '&all=on'
	else
		var infoString = $('infoBoxForm').serialize();
	if(infoString == '') {
		return false;
	} else {
//		infoString += '&m='+masterPage+'&s='+subMasterPage;
		Lightview.show({
			href: '/ajax/infobox.php?'+infoString,
			rel: 'ajax',
			options: {
				// autosize: true
				width: 770,
				height: viewportHeight-100
			}
		});
	}
}

function scrollStrip(id, direction)
{
	var strip = $(id);
	var viewport = strip.down('div.viewport');
	var glider = viewport.down('div.glider');
//	Position.prepare();
	var containerOffset = Position.cumulativeOffset(viewport);
	var elementOffset = Position.cumulativeOffset(glider);
	if (direction)
		userPicX -= 352;
	else
		userPicX += 352;
	new Effect.SmoothScroll(viewport,{duration:1, x:userPicX, y:0});
}

Effect.SmoothScroll = Class.create();
Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      y:    0,
      mode: 'absolute'
    } , arguments[1] || {}  );
    this.start(options);
  },
  setup: function() {
    if (this.options.continuous && !this.element._ext ) {
      this.element.cleanWhitespace();
      this.element._ext=true;
      this.element.appendChild(this.element.firstChild);
    }

    this.originalLeft=this.element.scrollLeft;
    this.originalTop=this.element.scrollTop;

    if(this.options.mode == 'absolute') {
      this.options.x -= this.originalLeft;
      this.options.y -= this.originalTop;
    }
  },
  update: function(position) {
    this.element.scrollLeft = this.options.x * position + this.originalLeft;
    this.element.scrollTop  = this.options.y * position + this.originalTop;
  }
});

function toggleTooltip(id)
{
	var tts = $$('div.tooltip');
	tts.each(function(tt){
		if (tt.id == 'tooltip'+id)
		{
			if (tt.visible())
				tt.hide();
			else
				tt.show();
		}
		else if (tt.visible())
		{
			tt.hide();
		}
	});
}

function logger(realm,name,data)
{
	if (data != 'undefined')
		_gaq.push(['_trackEvent', realm, name, data]);
	else
		_gaq.push(['_trackEvent', realm, name, '']);
}
