$(document).ready(function(){
	
	$("a").removeAttr("title");
	$("img").removeAttr("title");
	
    /* Start Page */
    $("#startseite, #startlayer").hide();
    $("#startseite").fadeIn(2000, "linear");

    $("#loidl-logo-eingang, #deutsch, #english").click(function() {
        var url = $(this).attr("href");
        $("body").stop().fadeOut(1000, "linear", function() { location.href=url; });
        return false;
    });
    
    
    $("#loidl-logo-eingang").hover(
        function() {
            $("#startlayer").fadeIn(300, "linear");
        });

    $("#startlayer").hover(
        function() {
            $("#startlayer").fadeOut(300, "linear");
        });

    

  /* STARTSEITEN BILD GROESSENANPASSUNG */
  var width = $(window).width();
  var height = $(window).height();
  var prop = (width / height);
  
  if (prop < 1.5) {
    $("#startimage img, #startimage video").addClass("highprop");
  } else {
    $("#startimage img, #startimage video").removeClass("highprop");
  }
  
  $(window).resize(function() {
    var runwidth = $(window).width();
    var runheight = $(window).height();
    var runprop = (runwidth / runheight);
    if (runprop < 1.5) {
      $("#startimage img").addClass("highprop");
    } else {
      $("#startimage img").removeClass("highprop");
    }
  });


    /* Content Pages */
    $("#section").hide().fadeIn(1000, 'linear');
    $(".project .project-content").hide();

    $("#nav ul li a").hover(
        function() {
            $(this).stop().animate({backgroundColor: "#ff00ff"}, 200);
        },
        function() {
            $(this).stop().animate({backgroundColor: "#362615"}, 200);
        });

    $("#nav ul li.current-item a").hover(
        function() {
            $(this).stop().animate({backgroundColor: "#ff99ff"}, 200);
        },
        function() {
            $(this).stop().animate({backgroundColor: "#ff00ff"}, 200);
        });

    $(".project-info").hover(
        function() {
            $(this).stop().animate({backgroundColor: "#ff00ff", color: "#ffffff"}, 200);
        },
        function() {
            $(this).stop().animate({backgroundColor: "#ffffff", color: "#70604f" /*#362615*/}, 200);
        });

    $(".highlighted, .sticky").hover(
        function() {
            $(this).stop().animate({backgroundColor: "#ff00ff", color: "#ffffff"}, 200);
        },
        function() {
            $(this).stop().animate({backgroundColor: "#ffffff", color: "#ff00ff"}, 200);
        });

    /* Accordion Function */

    $("a.project-info").click(function() {
        var href = $(this).attr('href');
        var params = location.search ? location.search.substring(1) : undefined;;
        $(this).css("outline","none");
        var parent = $(this).parent();

        if(parent.hasClass("current")) {
            $(this).siblings("div.project-content").slideUp(500,function() {
                parent.removeClass("current");
                /*$.scrollTo( $(this).siblings('object').offset().top , 500);*/
            });
        } else {
            $("#section div.current div.project-content").slideUp(500, function() {
                $(this).parent().removeClass("current");
            });
            var contentdiv = $(this).siblings("div.project-content");

            var scroll = function() {
                if( $(this).offset().top - 211 < 0 ) {
                    $.scrollTo( $(this).offset().top - 186 , 500);
                } else {
                    $.scrollTo( $(this).offset().top - 211 , 500);
                };
            };


            // already loaded content is just shown. this is either marked by 'content-loaded'
            // class or when the a-element has no href whatsoever (other categories like contacts)
            if(contentdiv.hasClass("content-loaded") || !href) {
                contentdiv.slideDown(500, scroll).parent().addClass("current");
            } else {
                // make spinner
                // content is 500px + 1px for <hr />
                contentdiv.height(501);
                contentdiv.prepend($('<div class="loadspinner" /><hr />'))
                  .slideDown(500, scroll)
                  .parent()
                  .addClass("current");
                // set var is_single to 0
                // var is_single = 0;
                // load the post and grab the body of the post for insertion
                contentdiv.load(href, params, function() {
                    contentdiv.addClass('content-loaded');
                });
            }
        }

        return false;
    });

    $('a.project-info-nobutton').removeAttr('href');

    /* Image Slideshow */

    $(".project-images").live('hover', function() {
        $(this).find('.slideshow-nav').fadeToggle(200);
     });

    /* Sliding Text for Sticky Posts / Newsticker */

    $(".scroller").simplyScroll({ autoMode: 'loop' });
});

$(window).load(function() {
    // dieser Code wird ausgeführt, wenn das komplette
    // Dokument im Browser geladen ist.
});

