/**
 * @author nueysan.waldman
 * @author Pieter van der Sluis
 * @author ferenc.radius
 *
 * @requires jquery/jquery-1.4.2.min
 * @requires ml/MatchesLoader
 */

ML.settings.setSingleRequest(false);

/**
 * Catch all view (for all urls) will be replaced by correct model
 */
ML.add(new ML.UrlMatches(""),
    [
        "swfobject.js"
    ], new ML.Action(
    {
        success: function() {

            $("a[href*='url='], a[href^='http://']").attr('target','_blank').attr('title','Deze link opent in een nieuw venster');

            $('#font-size a span').html('a');

            /***********************************************************************************************************
             * @author Nuey San Waldman
             * Diagonal notch creation
             */
            $('.links li').each(function(){

                var buttonHeight  = $(this).height();
                var notchWidth    = ((buttonHeight/2)+6);

                $(this).find('a').css('padding-right', notchWidth);

                $(this).find('div.notch').css({
                    'height': buttonHeight,
                    'width': notchWidth
                });

                $(this).find('div.top-notch').css({
                    'height': (buttonHeight-12)
                });

            });

            /***********************************************************************************************************
             * @author Ferenc Radius
             * campagne banner
             */
            $('#campaign_container li a').mouseover(function(e) {
                $(this).parents('ul').find('li').removeClass('active');
                $(this).parents('li').addClass('active');
            });

            /***********************************************************************************************************
             * @author Ferenc Radius
             * @author Pieter van der Sluis
             * @author Nuey San Waldman
             * campagne mp3 player
             */
            if($('#flash_container').length > 0) {
                var SWFID = "audioplayer";
                swfobject.embedSWF(
                    "./assets/swf/audioplayer.swf", "flash_container",
                    "600", "30",
                    "9.0.45","./assets/swf/expressinstall.swf",
                    {  },
                    {"menu": "false", "allowScriptAccess": "always", "swliveconnect": "true", "wmode": 'transparent' },
                    { "id": SWFID, 'enablejs': 'true' },
                    false
                );

                $("#transcript").hide();

                $("<h2 class=\"h6\" id=\"active-title\"></h2>").insertBefore('#audio-wrapper');

                $("#campaign-audio-container li div").hide();

                $("#campaign-audio-container a.audio").attr("target", "_blank").click(function(e) {

                    $('#campaign-audio-container li').removeClass('active');

                    $(this).parent('li').addClass('active');

                    $("#transcript").html(
                        $(this).next().html()
                    ).fadeIn();

                    $('#active-title').html(
                        $(this).parent().find('h2').html()
                    ).insertBefore('#audio-wrapper');

                    var swf = swfobject.getObjectById(SWFID);

                    if(swf != null && swf.playAudio) {
                        swf.playAudio( $(this).attr('href') );
                    }

                    if(swfobject.hasFlashPlayerVersion("9")) {
                        e.preventDefault();
                        return false;
                    }

                });
            }
        }
    })
);

