$(document).ready(function(){
	
    $('a[rel="external"]').attr('target','_blank');

    var slider = $(".scroller .scroll").bxSlider(
    {
        displaySlideQty : 2,
        prevText : "",
        nextText : "",
        controls : false
    });

    $('.scroller .prev').click(function()
    {
        slider.goToPreviousSlide();
        return false;
    });

    $('.scroller .next').click(function()
    {
        slider.goToNextSlide();
        return false;
    });
     
    $(".onswerkscroller .scroll")
    .bxSlider(
    {
        displaySlideQty : 6,
        ticker: true,
    	tickerSpeed: 10000
    });

    $(".onswerkscroller .klantscroll")
    .bxSlider(
    {
        displaySlideQty : 4,
        ticker: true,
    	tickerSpeed: 10000
    }); 
    
    $('.content_tabs a')
    .click(
        function()
        {
            if ($(this).attr("rel") != "external")
            {
                var selector = $(this)
                .attr("rel");
                $(this)
                .parent()
                .parent()
                .parent()
                .parent()
                .find(
                    '.content_box .content_boxes')
                .each(
                    function()
                    {
                        $(
                            this)
                        .css(
                            "display",
                            "none");
                    });
                $(this)
                .parents("ul")
                .find('a')
                .each(
                    function()
                    {
                        $(
                            this)
                        .removeClass(
                            "active");
                    });
                $(this).addClass(
                    "active");
                $(selector).css(
                    "display",
                    "block");
                jscroll.reinitialise();
            }
        });
    
    $(".splash").showcase(
    {

        animation :
        {
            interval : 4500,
            stopOnHover : false,
            easefunction : "swing",
            type : "fade",
            speed : 600
        },

        navigator :
        {
            position : "top-right",
            orientation : "vertical",
            showNumber : false,

            css :
            {
                padding : "0px",
                margin : "273px 10px 0px 1px"
            },
            item :
            {
                css :

                {
                    height : "12px",
                    "float" : "left",
                    width : "12px",
                    "-moz-border-radius" : "0px",
                    "-webkit-border-radius" : "0px",

                    backgroundColor : "#8A7E1A",
                    borderColor : "#ffffff",
                    margin : "0px 5px 0px 0px",
                    "text-align" : "center",
                    "vertical-align" : "middle"
                },
                cssHover :
                {
                    backgroundColor : "#C0AF2C",
                    borderColor : "#FFFFFF"
                },
                cssSelected :
                {
                    backgroundColor : "#C0AF2C",
                    borderColor : "#FFFFFF"
                }
            }
    },
    titleBar :
    {
        enabled : false,
        autoHide : false,
        css :
        {

            color : "#FFFFFF",
            width : "505px",
            "-moz-border-radius" : "0px",
            "-webkit-border-radius" : "0px",
            fontSize : "1.4em",
            height : "50px",
            margin : "0px 0px 38px 0px",

            opacity : "1"
        }

    }
});
    var element = $('.content_wide .content_box').jScrollPane(
		{
		    showArrows : true,
		    animateScroll : false
		});
		var jscroll = element.data('jsp');
function collapse()
{
    $(".nieuws_item_box").animate({height : '97px'}, 500);
    var selector = $(this).attr("rel");
    if ($(selector + " .nieuws_item_box").height() == 97)
    {
        var h = $(selector + " .nieuws_item_box div").height();
        if (h < 97)
        {
            h = 97;
        }
    } else
	{
        var h = 97;
    }
    $(selector + " .nieuws_item_box").animate(
	    {
	        height : h + 'px'
	    },
		{
	        duration : 500,
	        step : function()
	        {
	            jscroll.reinitialise();
	            jscroll.scrollToElement( $(selector),true);
	        }
	    });
}
function collapseOut()
{
    var selector = $(this).attr("rel");
    var h = $(selector + " .nieuws_item_box div").height();
    if (h < 97)
    {
        h = 97;
    }
    if ($(selector + " .nieuws_item_box").height() > 97)
    {
        jscroll.reinitialise();
        jscroll.scrollToElement($(selector),
            true);
    } else
	{
        $(".nieuws_item_box").animate(
        {
            height : '97px'
        }, 500);
        
        $(selector + " .nieuws_item_box").animate({height : h + 'px'},
			{	
	            duration : 500,
	            step : function()
	            {
	                jscroll.reinitialise();
	                jscroll.scrollToElement($(selector), true);
	            }
			});
	}
	return false;
}

function collapseWork()
{
    $(".onswerk_item_box").animate({height : '185px'}, 500);
    var selector = $(this).attr("rel");
    if ($(selector + " .onswerk_item_box").height() == 185)
    {
        var h = $(selector + " .onswerk_item_box div").height();
        if (h < 185)
        {
            h = 185;
        }
    } 
    else
    {
        var h = 185;
    }
    $(selector + " .onswerk_item_box").animate({height : h + 'px'},
    	{
	        duration : 500,
	        step : function()
	        {
	            jscroll.reinitialise();
	            jscroll.scrollToElement($(selector),true);
	        }
	   });
}
function collapseOutWork()
{
    var cat = $(this).attr("rel2");
    $(cat).trigger('click');
    $(".onswerk_item_box").animate({height : '185px'}, 500);
    var selector = $(this).attr("rel");
    var h = $(selector + " .onswerk_item_box div").height();
    if (h < 185)
    {
        h = 185;
    }

    $(selector + " .onswerk_item_box").animate({height : h + 'px'},
	{
        duration : 500,
        step : function()
        {
            jscroll.reinitialise();
            jscroll.scrollToElement($(selector),true);
        }
    });
}

$('.nieuws_item_button a').click(collapse);
$('.nieuws_tabs a').click(collapseOut);
$('.scroller .scroller_item_img a').click(collapseOut);
$('.onswerkscroller .scroller_item_img a').click(collapseOutWork);

$('.onswerk_item_button a').click(collapseWork);

$('.werk_tabs a')
.click(
    function()
    {
        var selector = $(this).attr(
            "rel");
        $(this)
        .parent()
        .parent()
        .parent()
        .parent()
        .find('.content_box_inside')
        .each(
            function()
            {
                $(this)
                .css(
                    "display",
                    "none");
            });
        $(this)
        .parents("ul")
        .find('a')
        .each(
            function()
            {
                $(this).removeClass("active");
            });
        $(this).addClass("active");
        $(selector).css("display","block");
        /*
        $(selector).jScrollPane(
            {
	            showArrows : true,
	            animateScroll : true
            });
        jscroll = $(selector).data('jsp');*/
        jscroll.reinitialise();
    });

$('.nieuws_arrow_right').mousehold(50, goLeft, 100);
$('.nieuws_arrow_left').mousehold(50, goRight, 100);

var slideWidth = 0;
$(".nieuws_slide li").each(function()
{
    slideWidth += $(this).width();
});

if (slideWidth < 600)
{
    $(".nieuws_arrow_right").remove();
    $(".nieuws_arrow_left").remove();
    $(".nieuws_tabs").width(636);
}
						
$("div.onswerk_item_img a").fancybox();
$("div.nieuws_item_img a").fancybox();


function goLeft()
{
    var slideWidth = 0;
    $(".nieuws_slide li").each(function()
    {
        slideWidth += $(this).width();
    });
    var maxLeft = 600 - slideWidth;
    var left = $(".nieuws_slide").position().left;
    var newLeft = left - 5;
    if (newLeft > maxLeft)
    {
        $(".nieuws_slide").css("left",
            newLeft + "px");
    }
}
function goRight()
{
    var slideWidth = 0;
    var left = $(".nieuws_slide").position().left;
    var newLeft = left + 5;
    if (newLeft < 0)
    {
        $(".nieuws_slide").css("left",
            newLeft + "px");
    }
}

/*
$("#jquery_jplayer_1").jPlayer({
    ready: function () {
        $(this).jPlayer("setMedia", {
            wav: "/tableaux/customer/music.wav"
        });
        $(this).jPlayer("play");
    },
    ended: function (event) {
        $(this).jPlayer("play");
    },
    swfPath: "/tableaux/customer/scripts",
    supplied: "wav",
    solution: 'html, flash',
    supplied: 'wav',
    preload: 'auto',
    volume: 0.8,
    muted: false
});
					
$("#music_pause").click(function(){
    $("#jquery_jplayer_1").jPlayer("pause");
    $("#music_pause").hide();
    $("#music_play").show();
});
						
$("#music_play").click(function(){
    $("#jquery_jplayer_1").jPlayer("play");
    $("#music_play").hide();
    $("#music_pause").show();
});
*/


});

function musicOn(){
	document.getElementById('musica').src = 'http://pre-vision.nl/tableaux/customer/flash/muziek.html';
        document.getElementById('music_pause').style.display='block';
        document.getElementById('music_play').style.display='none';
}
function musicOff(){
	document.getElementById('musica').src = '';
        document.getElementById('music_pause').style.display='none';
        document.getElementById('music_play').style.display='block';
}
