/**
 * Scrolls to the specified ID;
 * 
 * @param targetId
 *            The ID of the element to scroll to.
 */
function scrollToId(targetId) {
    $.scrollTo('#' + targetId, 800);
};

function initAll() {
    $(document).ready(function() {
        
        var projectScroller;
        
       // initialize tooltip
        $("#navi a[title]").tooltip( {
                // use single tooltip element for all tips
                tip : '#tooltip-1',
                // tweak the position
                offset : [ 10, -100 ],
                // use "slide" effect
                effect : 'slide',
                // position
                position : "bottom"
                // add dynamic plugin
                }).dynamic( {
                // customized configuration on bottom edge
                bottom : {
                // slide downwards
                direction : 'down',
                // bounce back when closed
                bounce : true
                }
        });
        
        /*$('#navi a').hover(function() {
                $(this).stop().effect("highlight", {}, 500);
            }, function() {
                $(this).stop().effect("highlight", {}, 500);
        });*/
        
        
        $("#navi a").mouseover(function() {
            $(this).effect("highlight", {color: "#ffffff"}, 550);
        });
        
        // Projekte
        projectScroller = $("#scroller").scrollable({
                size: 3
            }).circular().autoscroll({autoplay: true, api: true});
        
        var saveImageName;
        var imageName;
        
        $("#scroller div.items img").click(function() {
            $("#tooltip-1").hide();
            projectScroller.stop();
            imageName = $(this).attr('name');
            if (saveImageName !== "" && saveImageName != ("#project"+imageName)) {
                $(saveImageName).fadeTo("medium", 0.0); 
                $(saveImageName).hide();
                $("#project"+imageName).fadeTo("medium", 0.5);
            }
            
            if (saveImageName != ("#project"+imageName)) {
                $("#project"+imageName).fadeTo("slow", 1.0);
                saveImageName = "#project"+imageName;
            }
        });
        
        //var mouseIsInside = false;
        
        // Start Scroll on click outside
        /*$('#orangeArea').hover(function(){ 
            mouseIsInside = true; 
        }, function(){ 
            mouseIsInside = false; 
        });
        
        $("#page").mouseup(function() {
            if (!mouseIsInside) {
                $("#scroller div.items img.active").removeClass('active');
                projectScroller.play();
            }
        });*/
        
        // Showroom
        $("#scroller div.items img").mouseover(function() {
            projectScroller.stop();
            $(this).fadeTo("medium", 0.6);
        });
        
        $("#scroller div.items img").mouseout(function() {
            $(this).fadeTo("medium", 1.0);
        });
        
        // Thumbs
        $("#orangeArea div.thumbs img").mouseover(function() {
            $(this).fadeTo("medium", 0.6);
        });
        
        $("#orangeArea div.thumbs img").mouseout(function() {
            $(this).fadeTo("medium", 1.0);
        });
        
        var linkColor = "#555555";
        
        // Links (redArea)
        $("#redArea a").hover(function() {
            $(this).animate({
                color: "#D21717"
            }, 350);
        }, function() {
            $(this).animate({
                color: linkColor
            }, 350);
        });
        
        // Links (orangeArea)
        $("#orangeArea a").hover(function() {
            $(this).animate({
                color: "#ED8F11"
            }, 350);
        }, function() {
            $(this).animate({
                color: linkColor
            }, 350);
        });
        
        // prettyPhoto
        $("a[rel^='prettyPhoto']").prettyPhoto({
            theme: 'facebook'
        });
        
        /*$("#scroller div.items img[title]").tooltip( {
            // use single tooltip element for all tips
            tip : '#tooltip-1',
            // tweak the position
            offset : [ 10, -223 ],
            // use "slide" effect
            effect : 'slide',
            // position
            position : "bottom",
            predelay : 30,
            // add dynamic plugin
            }).dynamic( {
            // customized configuration on bottom edge
            bottom : {
            // slide downwards
            direction : 'down',
            // bounce back when closed
            bounce : true
            }
    });*/
        
    });
};
