var anchor = self.document.location.hash.substring(1);


$(window).load(function(){

// Aufbau Projekt-Seite
var tl_cols = $("a[attr='top-row']");
var th_cols = $(".category-outer");

var speed = 300;

// init timer and stores it's identifier so it can be unset later
var timer = setInterval(show, speed);

var length = th_cols.th_cols;

var index = 0;
function show() {
	 tl_cols.eq(index+1).css('color','#000');
     th_cols.eq(index).fadeIn(400);
     index++;
     // remove timer after interating through all articles
     if (index >= length) {
         clearInterval(timer);
     }
}


// Animierte Overlays für Startseite
els = $("a.thumb-inner");
els.each(
	function(){
		$(this).hover(
			function() {
				ol = $(this).children("div");
				ol.animate({height: "50px"});
			},
			function() {
				ol = $(this).children("div");
				ol.animate({height: "0"});
				
			}
		);
	}
);


// Scroll-To funktion
$("div.cat-image").each(
	function(){
		if(anchor){
			if($(this).attr("id") == anchor){
				$.scrollTo("#"+anchor, 800, {offset:{top:-10}});
				return false;
			}
		} 
	}

);


// Navigations Flitzer
var fl = $("#nav-flitzer");
var pos = fl.position();
var c_pos = null;
var c_w = null;
var a_pos = null;
var a_w = null;

var c_el = null;
var a_el = null;

var roll_in = false;

var counttest = 0;


function setCurrent() {
	attr = c_el.attr("attr");
	alt = c_el.attr("alt");
	pos = c_el.position();
	w = c_el.width();

	if(alt == 'first') {
		pos_left = 0;
	} else {
		pos_left = pos.left-7;
	}
	
	fl.css({left: pos_left + "px", top: pos.top-2 + "px", width: w+14});
	if(fl.css("display") == 'none')
		fl.fadeIn(200);

	a_el = c_el;

	setHover(c_el);

	roll_in = false;
}

c_el = $('#top-nav-pack a.current');
if(c_el.attr("href")) {
	//$('#top-nav-pack').append("<p style=\"display:none\">"+c_el+"</p>");
	setCurrent();
} else {
	roll_in = true;
}

function setHover(el) {
	if(el.attr("href") == a_el.attr("href")) {
		if(a_el.hasClass("white") && a_el.attr("href") != c_el.attr("href"))
			a_el.removeClass("white");
		else
			a_el.addClass("white");

	} else {
		a_el.removeClass("white");

	}
}

function anim(el, attr) {
	pos = el.position();
	t_w = el.width();
	c_pos = c_el.position();
	c_attr = c_el.attr("attr");
	c_alt = c_el.attr("alt");
	el_alt = el.attr("alt");
	
	//$('#top-nav-pack').append("<p>"+el.position().left+"</p>");
	if(el_alt == 'first')
		pos_left = 0;
	else
		pos_left = pos.left-7;

	if(c_el.attr("href") == a_el.attr("href")) {
		setHover(el);
		//alert(c_el.attr("href") + ',' + a_el.attr("href"));
	}


	if(c_attr == attr) {
		fl.animate({left: pos_left + "px", width: t_w+14},
			function(){
				setHover(el);
			}
		);
	} else {
		if(c_alt == 'first') {
			if(el_alt == c_alt) {
				fl.animate({top: pos.top-2 + "px", width: t_w+14}, 
					function(){
						setHover(el);
					}
				);
			} else {
				fl.animate({top: pos.top-2 + "px"},
					function() {
						$(this).animate({left: pos_left + "px", width: t_w+14},
							function(){
								setHover(el);
							}
						);
					}
				);
			}
			
			
		} else {
			fl.animate({left: pos_left + "px", width: "120px"},
				function() {
					$(this).animate({top: pos.top-2 + "px", width: t_w+14},
						function(){
							setHover(el);
						}
					);
				}
			);
		}
	}
	c_el = el;
			
}

$("#top-nav-pack a").hover(
	function() {
		if(roll_in) {
			c_el = $(this);
			setCurrent();
		} 
		anim($(this), $(this).attr("attr"));
		//$('#top-nav-pack').append("<p style=\"display:none\">"+counttest+1+"</p>");

	},
	function() {}
);

$("#top-nav-pack").mouseleave(
	function() {				
		if(a_el.attr("href") != c_el.attr("href")) {		
			c_el = $("top-nav-pack a.current");
			c_el = a_el;
			fl.fadeOut(200,
				function() {
					setCurrent();
				}
			);
		} 
		if(!$('#top-nav-pack a.current').attr("href")) {
			roll_in = true;
			c_el = null;
			a_el.removeClass("white");
			fl.fadeOut(200);

		}
	}
);












});
