/*
jQuery("#imageflow").ready(function() {
		jQuery("#loading").fadeOut(1000, function() {						
			refresh(true);
			jQuery("#images").css("visibility","visible");
			jQuery("#scrollbar").css("visibility","visible");
			initMouseWheel();
			initMouseDrag();
			
			var mitte=0;
		
			if(max%2 == 1)
				mitte = Math.round(max/2)-1;
			else
				mitte = max/2;
		
			glideTo(-(mitte*xstep), mitte);
			
			jQuery("#sidebarbox").ready(function() {
											
			});
			
		});
	});
*/

window.onload = function () { 
    addReflections();

    jQuery("#loading").fadeOut(1000, function() {
        refresh(true);
        jQuery("#images").css("visibility","visible");
        jQuery("#scrollbar").css("visibility","visible");
        initMouseWheel();
        initMouseDrag();

        //var mitte=0;

        //if(max%2 == 1)
        //	mitte = Math.round(max/2)-1;
        //else
        //	mitte = max/2;

        //glideTo(-(mitte*xstep), mitte);
    });
}


jQuery(document).ready(function(){
    jQuery("#nav").decorate("navigation", {item:1});

    /* set height */
    jQuery("#glasswrapper").css("height",(pageheight+355)+"px");
    jQuery("#sidebarbox").css("height",(pageheight+315)+"px");
    jQuery("#maincontentbox").css("height",(pageheight+315)+"px");
    jQuery("#content-border-right").css("height",(pageheight+355)+"px");

    /*
    SlimboxOptions.resizeSpeed = 400;
    SlimboxOptions.overlayOpacity = 0.8;
    SlimboxOptions.loop = true;
    SlimboxOptions.allowSave = false;
    SlimboxOptions.slideshowAutoplay = false;
    SlimboxOptions.slideshowInterval = 5000;
    SlimboxOptions.slideshowAutoclose = true;
    SlimboxOptions.counterText = 'Bild ###x### von ###y###';
    */

    /* initialisize resize animation */
    slideanimation("body",null);

    /* Gallery on homepage */
    $(document).everyTime(3000,"galleryslide",function() {
        if(((-target)/xstep) == array_images.length-1)
        {
                glideTo(0,0);
        }
        else
        {
                handle(-1);
        }
    });
});

function pageswitch(href,slide)
{			
    jQuery("#langswitch").load("http://www.buschbaum-media.com/index.php?id="+href+" #langswitch");

    jQuery("#maincontent").fadeOut(250, function()
    {
        jQuery("#maincontent").load("http://www.buschbaum-media.com/index.php?id="+href+" #maincontent", function()
        {
            jQuery("#maincontent").fadeIn(500, function()
            {
                jQuery("#loading").fadeOut(1000, function()
                {
                    refresh(true);
                    jQuery("#images").css("visibility","visible");
                    jQuery("#scrollbar").css("visibility","visible");
                    initMouseWheel();
                    initMouseDrag();
                    $(document).everyTime(3000,"galleryslide",function()
                    {
                        if( ( (-target)/xstep) == array_images.length-1)
                        {
                            glideTo(0,0);
                        }
                        else
                        {
                            handle(-1);
                        }
                    });

                    SlimboxOptions.resizeSpeed = 400;
                    SlimboxOptions.overlayOpacity = 0.8;
                    SlimboxOptions.loop = true;
                    SlimboxOptions.allowSave = false;
                    SlimboxOptions.slideshowAutoplay = false;
                    SlimboxOptions.slideshowInterval = 5000;
                    SlimboxOptions.slideshowAutoclose = true;
                    SlimboxOptions.counterText = 'Bild ###x### von ###y###';
                });
            });
            slideanimation("#maincontent", null);
        })
    });


    jQuery("#sidebar").fadeOut(250, function(){
        jQuery(this).load("http://www.buschbaum-media.com/index.php?id="+href+" #sidebar", function(){
            jQuery(this).fadeIn(500, function() { addReflections(); });
            slideanimation("#sidebarbox", null);
        })
    });


    if(slide[0] == "slide")
    {
        var px = 315 + parseInt(slide[1]);
        //var px  = jQuery("#maincontent").height();
        //alert(px);
        //jQuery("#maincontentbox, #sidebarbox, #content-border-right").animate({height:(355)+"px"}, 500);
        if(slide[2] == 1)
        {
            //jQuery("#sidebarbox").animate({width:"255px"}, 1, function(){
            //jQuery("#sidebarbox").animate({width:"0px", padding:"0px", height:px+"px"}, 500);
            jQuery("#maincontentbox").animate({width:"900px", height:px+"px"}, 500);
            //})
            jQuery("#content-border-right").animate({height:(px+40)+"px"}, 500);
            jQuery("#glasswrapper").animate({height:(px+40)+"px"}, 500);
            jQuery("#sidebarbox").animate({height:(px)+"px"}, 500);
        }
        else
        {
            jQuery("#maincontentbox").animate({width:"600px", height:px+"px"}, 500);
            //jQuery("#sidebarbox").animate({width:"260px", padding:"20px", height:px+"px"}, 500);
            jQuery("#content-border-right").animate({height:(px+40)+"px"}, 500);
            jQuery("#glasswrapper").animate({height:(px+40)+"px"}, 500);
            jQuery("#sidebarbox").animate({height:(px)+"px"}, 500);
        }
    }
    else
    {
        jQuery("#maincontentbox").animate({width:"600px", height:"315px"}, 500);
        //jQuery("#sidebarbox").animate({width:"260px", padding:"20px", height:"315px"}, 500);
        jQuery("#content-border-right").animate({height:"355px"}, 500);
        jQuery("#glasswrapper").animate({height:"355px"}, 500);
        jQuery("#sidebarbox").animate({height:"315px"}, 500);
    }
}

function slideanimation(divcontainer, starthref)
{
    /* stop animation of gallery */
    jQuery(document).stopTime("galleryslide");

    /* show address on mouseover on the image "your first..." */
    jQuery("#c49 img").mouseenter(function(){
        jQuery("#addresswrapper").stop().animate({left:"960px"},500);
    });
    jQuery("#c49 img").mouseleave(function(){
        jQuery("#addresswrapper").stop().animate({left:"660px"},500);
    });
	
    //
    jQuery(divcontainer+" a").each(function()
    {
        if(jQuery(this).attr("target") == "_blank" || jQuery(this).attr("target") == "_top"  || jQuery(this).attr("href").indexOf("javascript") != -1 || jQuery(this).attr("class") == "internal-link" || jQuery(this).attr("rel").indexOf("lightbox") != -1 || jQuery(this).parent().attr("class") == "tx-bblanguageselect-pi1" || jQuery(this).parent().parent().parent().parent().attr("class") == "filelist" || jQuery(this).parent().parent().attr("id") == "browseresultlist")
        {
            if(jQuery(this).attr("target").indexOf("slide") != -1 )
                jQuery(this).attr("target", "");
        }
        else
        {
            var href = jQuery(this).attr("href").replace("index.php?id=", "");
            var slide = jQuery(this).attr("target").split("|");
            jQuery(this).attr("href", document.location.href.split("/")[document.location.href.split("/").length-1].replace(/#/, "")+"#");
            jQuery(this).attr("target", "");
            jQuery(this).unbind('click');

            //alert(jQuery(this).attr('class'));
            jQuery(this).click(function(){
                pageswitch(href,slide);
            })
        }
    })	
}

