/**
 * @author Stephan Kroppenstedt
 * @date Christmas 2009
 */
 
 $(document).ready(function () {
	
	var viewPortHeight = $(window).height();
	var viewPortWidth = $(window).width();
	var sizeContentList = $("#content > li").size();
	var exposeOffset = 50;
	
	var viewportWidth = $(window).width();
	var viewportHeight = $(window).height();
				                                         
	var windowMaxSize = $(".frame").size();	
	
	// Berechnen der Framegroesse
	$(".frame.image").css({"max-width": viewportWidth, "max-height":viewportHeight-280});
	var portraitimageSize = $(".frame.portrait img").width();
	$(".frame.image img").css({"max-width":"1100px", "min-height":"250px","max-height":viewportHeight-220});
	
	// Letzten Frame erweitern für Scrollbalken
	$(".frame:last").css({"width": viewportWidth})
	
	$("body.home").attr("id","start");
	$("body#start #frame-1").css({"padding-left":viewportWidth});
	
	var frameWidth = 310;
	$(".frame").each(function(){
		// alert(""+frameWidth);
		frameWidth += $(this).innerWidth();
	});
	frameWidth += 500;
	$("body").css({"width":frameWidth});
	
	$("body").css({"width":windowMaxSize*(viewportWidth-100)});
	//alert($("#framebox").width() + "");
	$("body").css({"width": $("#framebox").width() });

	$(".update").find("img").attr("class", "big-teaser"); // set big-teaser class to mark big images - diasbles the zoom function
	$(".big-teaser").css({width: 60, height: 60, "padding-top": 5 });
	$("img:not(.big-teaser)").removeAttr("width");
	$("img:not(.big-teaser)").removeAttr("height");
	$("img").removeAttr("alt");
	$("img").removeAttr("title");  
	
	$(".image-list a").click(function (){
		$.scrollTo($(this).attr('href'), 800, {axis:'x'});
	});
		
	// Navigation
	
	// Bei der Startseite1 Frame weg schieben
	// Navigation statisch ohne Hover aber mit Relationen
	
	

	// Hinzufuegen von Wrapper und zusaetzlichem Div zum Scrollen
	$("ul#navigation").addClass("js");
	
	
	$('.subnavigation').wrap("<div class='wrapper'></div>");
	$('.wrapper').wrap("<div class='wrapper-out'></div>");
	$(".wrapper-out").prepend("<a class='prev'><</a>");
	$(".wrapper-out").prepend("<a class='next'>></a>");
	
	$("body:not(#start) .wrapper-out").hide("slow");
	
	$(".prev").click(function() {
		$(this).next(".wrapper").scrollTo( '-=100px', 800);
	});
	$(".next").click(function() {
		$(this).parent().find(".wrapper").scrollTo( '+=100px', 800);
	})
	
	$("ul#navigation.js .wrapper-out").css({
		"width": ($(window).width()-300) + "px"
	});
	
	$(".subnavigation").each(function() {
		$(this).parent().parent().parent().addClass('has-subnavigation');
	});
	
	$("ul#navigation .subnavigation span").hide();
	
	$("ul.subnavigation li").css({"float":"left"});
	
	if(!$.browser.safari){
	$("#navigation").hover(function() {
		
		$("#framebox").animate({opacity: 0.3}, 800); 
	}, function() {
		$("#framebox").animate({opacity: 1},800);
	} );
}
	
	
	$("#navigation li").hover(function(){
		// Problem mit IE 8
		if(!$.browser.msie){
			$("#navigation").css({"opacity":"1", "z-index": "99"});
		}
		
		$(this).find(".wrapper-out").show();
	}, function(){
		// $(this).find("body:not(.home) .wrapper-out").hide();
	});
	
	$("body:not(.home) .wrapper-out").hover(function() {
		$(".wrapper-out").show();
	}, function() {
		$("body:not(.home) .wrapper-out").hide();
	});
	

	// Tooltip in Navigation anzeigen lassen
	$("#navigation li .subnavigation").css({"height":"70px"});
	
	
	$("#navigation li .subnavigation a").hover(function(){
		// .head ausgrauen
		
		// Tooltipp erstellen
		
		this.title = $(this).find("span").html();
		$("body").append("<p id='tooltip'>"+ this.title +"</p>");
		$("#tooltip").hide();

		$("#tooltip").css({
			"top": ($(this).find("img").offset().top-$("#tooltip").innerHeight()+11), 
			"left": ($(this).offset().left-10) 

		});
		

		$(this).find("img:not(.big-teaser)").stop().animate({
			paddingTop: "5px",
			height: "60px", 
		},400, 'linear', function() {
			$("#tooltip").fadeIn("slow");
			//return;
		});
		
	}, function(){
		$("#tooltip").hide("fast").remove();
		
		$(this).find("img:not(.big-teaser)").stop().animate({
				height: "30px",
				paddingTop: "20px" 
			}, 100);
	});       
	
              
	
	// Semantische Bezuege herrstellen
	
	$("#navigation li.projekte .subnavigation a").hover(
		function(){
	   	 $(".projekte .wrapper-out").show();
			$(".kuenstler .wrapper-out").show();
			$(".kuenstler .wrapper-out ul.subnavigation").find("li").hide();
			
			var finds = new Array();
			finds = $(this).attr('class').split(' ');
		
			if(finds.length >= 1){
				for (var i = 0; i < finds.length; i++){

					if(finds[i].length >= 1){
						$("." + finds[i]).parent().show("fast");
					} 
				}
			}
			    
		}, function(){
			$().stop();
			finds = new Array();
			$(".wrapper-out ul.subnavigation li").show("fast");
		}
	);        
	
	$("#navigation li.kuenstler .subnavigation a").hover(function(){
		$(".kuenstler .wrapper-out").show();
		$(".projekte .wrapper-out").show();
		$(".projekte .wrapper-out ul.subnavigation").find("li").hide();
		
		var finds = new Array();
		finds = $(this).attr('class').split(' ');
		
		if(finds.length >= 1){
			for (var i = 0; i < finds.length; i++){
				
				if(finds[i].length >= 1){
					$("." + finds[i]).parent().show("fast");
				} 
			}
		}
	}, function(){
		$().stop();
		finds = new Array();
		$(".wrapper-out ul.subnavigation li").show("fast");
	});
	
	
	 $("#topbox .menu ul li:last").after($("a#language-switch"));
   	// Languageswitch Koordinaten
	$(".qtrans_language_chooser").parent().hide();
	$("#language-switch").click(function() {
		$(".qtrans_language_chooser").parent().toggle();
	});
	var langSwitchPos = $("#language-switch").offset();
	$(".qtrans_language_chooser").parent().css({
		"list-style-type":"none",
		"position":"fixed",
		"left": langSwitchPos.left,
		"top": langSwitchPos.top + $("#language-switch").height() + 6 
	});
	
	// Scrollbarposition setzen
	
	$(window).scroll(function () {
		var activeFrame =  $('.frame:in-viewport').attr('id');
		$("a.aktive").removeClass("aktive").find("img").animate({height:"40px", paddingTop: "20px", opacity: ".7"},200);
		$("a[href^=#"+ activeFrame +"]").addClass("aktive");
		return false; 
	});
	
	$("#scrollbox a").hover(function(){
	   $(this).find("img").animate({height:"60px", "paddingTop":"0", opacity: "1"},200); 
	}, function() {
		$(this).find("img").animate({height:"40px", paddingTop:"20px", opacity: ".7"},500);
	});
	
	// Facebook einbinden
	
	var liElemente = 0;
	$(".menu li").each(function() {
		liElemente++;
		$(this).addClass("liElemente-"+liElemente);
	});
	$(".liElemente-3").after("<li style=''><iframe src='http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.schir.net&amp;layout=button_count&amp;show_faces=true&amp;width=90&amp;action=like&amp;colorscheme=light&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:85px; height:20px; position: relative; top: 5px;' allowTransparency='true'></iframe></li>");

	$("a[hreflang=he]").parent().remove();

});
