// JavaScript Document

$("document").ready(function()
{
	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		transition: 1,
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 4000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 3000 // animation speed
	};
	
	// initialize SuperBGImage
	$('#bg_image').superbgimage().hide();
	
	function ContentHeight()
	{
		var col_right_height;
		col_right_height = $(".active_height").find(".col_right").css("height");
		col_right_height = parseInt(col_right_height);
		
		var col_left_height;
		col_left_height = $(".active_height").find(".col_left").css("height");
		col_left_height = parseInt(col_left_height);

		var content_height;
		content_height = $(".active_height .col_left").height();
		content_height = parseInt(content_height);
		
		// alert("Content Height: "+(content_height)+"\nCol-Left: "+(col_left_height)+"\nCol-Right: "+col_right_height);
		
		if(parseInt(content_height) > parseInt(col_right_height))
		{
			// $(".active_height").find(".col_right").css("height", (content_height + 10) + 'px');
		}else{
			// $(".active_height").find(".col_left").css("height", (col_right_height - 10) + 'px');
		}
	}
	
	// start slideshow
	$('.start').click(function(e) {
		e.preventDefault();
		$(this).addClass("hidden");
		$(".stop").removeClass("hidden");			
		$('#startseite_thumbs').startSlideShow();			
	});

	// stop slideshow
	$('.stop').click(function(e) {
		e.preventDefault();
		$(this).addClass("hidden");
		$(".start").removeClass("hidden");
		
		my_slideshowActive = false;
		$('.thumblist').stopSlideShow();
	});
	
	// prev slide
	$('.prev').click(function() {
		return $('#startseite_thumbs').prevSlide();
	});

	// next slide
	$('.next').click(function() {
		return $('#startseite_thumbs').nextSlide();
	});
	
	$("a.modal").click(function(e)
	{
		e.preventDefault();
		var active_content_container = $(this).attr("rel");
		/*
		$(".content_container").addClass("hidden");
		$(".content_container").removeClass("active_height");			
		$("#"+active_content_container).removeClass("hidden");
		$("#"+active_content_container).addClass("active_height");
		ContentHeight();
		*/
		jQuery.modal.close();
		window.setTimeout(function()
		{
			var height;
			height = $("#"+active_content_container).height();
			$('#'+active_content_container).modal({overlayClose:true, opacity:70, overlayCss: {backgroundColor:"#fff"}});
		}, 250);

		return false;
	});
	
	$("a.loadset").click(function(e)
	{
		e.preventDefault();
		var div;
		div = $(this).attr("rel");
			
		var $magicLine = $("#magic-line");
		$(this).parent().siblings().removeClass("current_page_item");
        $(this).parent().addClass("current_page_item");
        $magicLine
            .width($(".current_page_item").width())
            .css("left", $(".current_page_item a").position().left)
            .data("origLeft", $magicLine.position().left)
            .data("origWidth", $magicLine.width());     
		
		// $(".visible").slideUp("slow", function(){ $(".footer").removeClass("footer_bottom"); $("#"+div).slideDown("slow", function() { ContentHeight(div); }); $(".visible").removeClass("visible"); $("#"+div).addClass("visible"); });
		// $(".visible").fadeOut("slow", function(){ $(".footer").removeClass("footer_bottom"); $("#"+div).fadeIn("slow", function() { ContentHeight(div); }); $(".visible").removeClass("visible"); $("#"+div).addClass("visible"); });			
		$(".visible").hide(1, function(){ $("#"+div).show(1, function() { ContentHeight(); }); $(".visible").removeClass("visible"); $("#"+div).addClass("visible"); FooterContent(); });
		$(".showtext").attr("rel", div);
	});
	
    $(".close").click(function(e)
	{
		e.preventDefault();
		var div = $(this).attr("rel");
        $(".showtext").attr("rel", div);
		$("#"+div).fadeOut();
		$("#"+div).addClass(".hidden");
		FooterBottom();
	});
    
	$(".showtext").click(function(e)
	{
		e.preventDefault();
		var clicked_link = $(this).attr("rel");
		$("a.loadset [rel='" + clicked_link + "']").click();
		$(".showtext").addClass("hidden");
        FooterContent();
        $("#"+clicked_link).fadeIn();
	});
	

	
	function FooterBottom()
	{
		$(".footer").fadeOut("slow", function() { $(".footer").addClass("footer_bottom"); $(".footer").fadeIn(); });
		$(".showtext").removeClass("hidden");		
	}
	
	function FooterContent()
	{
		if($(".footer").hasClass("footer_bottom"))
		{
			$(".footer").fadeOut("slow", function() { $(".footer").removeClass("footer_bottom"); $(".footer").fadeIn(); });
			$(".showtext").addClass("hidden");
		}
	}		
});

$(function()
{
    var $el, leftPos, newWidth,
        $mainNav = $("#example-one");

    $mainNav.append("<li id='magic-line'></li>");
    var $magicLine = $("#magic-line");

    $magicLine
        .width($(".current_page_item").width())
        .css("left", $(".current_page_item a").position().left)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());

    $("#example-one li a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        });
    });
});
