/*
Copyright (c) 2009, TG 08 Ober-Roden e.V. All rights reserved.
http://www.tgoberroden.de
version: 2.0.0
*/
// Open Window Script
function openWindow(url) {
	newWindow = window.open(url, "TG 08 Ober-Roden e.V.", "width=640,height=480,resizable=yes");
	newWindow.focus();
	return false;
}
// Slideshow Script
function slideSwitch() {
	var $active = $('#slideshow img.active');
	if($active.length == 0) $active = $('#slideshow img:last');
	// Reihenfolge festlegen
	var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');
	// Random Reihenfolge festlegen
	//var $sibs = $active.siblings();
	//var rndNum = Math.floor(Math.random()*$sibs.length);
	//var $next = $($sibs[rndNum]);
	$active.addClass('last-active');
	$next.css({opacity: 0.0}).addClass('active').animate({opacity:1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
}
// Scroll Variablen initialisieren
var naviName = '#naviContainer';
var scrollYloc = null;
var naviXYloc = null;
var scrollConst = null;
var footerXYloc = null;
var naviHeight = null;
var scrollTop = null;
var scroll = null;
// Onload Funktion
$(document).ready(function() {
	// Frameblocker
	if(top.location != self.location) top.location = self.location;
	// Navigation
	if(document.getElementById('naviContainer')) {
		// Scroll-, Navigation Position und oberen festen Scroll-Abstand holen
		scrollYloc = parseInt($(naviName).css('top').substring(0, $(naviName).css('top').indexOf('px')));
		naviXYloc = $(naviName).offset();
		// Hoehe auslesen
		//scrollConst = scrollYloc+$(document).scrollTop()+naviXYloc.top;
		//alert(scrollConst);
		scrollConst = 164;
		// Window Scroll Funktion
		$(window).scroll(function() {
			// Footer Position, Navigation Hoehe oberen dynamischen Scroll-Abstand und Scroll-Navigation Position holen
			footerXYloc = $('#footerContainer').offset();
			naviHeight = $(naviName).height();
			scrollTop = scrollYloc+$(document).scrollTop();
			scroll = scrollTop+naviXYloc.top;
			// Navigation scrollen
			if((scroll >= naviXYloc.top*2) && (footerXYloc.top >= naviHeight+scrollTop)) {
				offset = scrollTop-scrollConst+'px';
				$(naviName).animate({top:offset}, {duration:500, queue:false});
			}
			else if(scrollTop == 0) {
				offset = scrollTop+'px';
				$(naviName).animate({top:offset}, {duration:500, queue:false});
			}
		});
	}
	if(document.getElementById('slideshow')) {
		setInterval("slideSwitch()", 3000);
	}
});
