
$.ajaxSetup({
    async:      false,
    beforeSend: function (XMLHttpRequest)                           { Frontend.Ajax.Start(); },
    complete:   function (XMLHttpRequest, textStatus)               { Frontend.Ajax.Complete(); },
    error:      function (XMLHttpRequest, textStatus, errorThrown)  { Frontend.Ajax.Error();  }

});



var Frontend = {


    Init: function()
    {

        Frontend.Fancyzoom.Init( $('.fancybox'),                { 'titleShow' : true, 'padding' : 10  } );
        Frontend.Fancyzoom.Init( $('.fancyform'),               { 'type' : 'iframe', 'titleShow' : false, 'padding' : 0 ,  'scrolling' : 'yes' , 'width' : 720, 'height' : 580 } );
        Frontend.Fancyzoom.Init( $('a.newsletter'),             { 'type' : 'iframe', 'width' : 640, 'height' : 640, 'autoScale': false,  'scrolling' : 'no', 'overlayColor' : '#000' } );



        Frontend.Layout.Navigation.Init();
    },

    Ajax: {

        Start: function()
        {
            $('#loading').show();
        },

        Complete: function()
        {
            $('#loading').hide();
        },

        Error: function()
        {
            alert("AJAX-Error: " + textStatus + " " + errorThrown  );
        }

    },


    Fancyzoom: {

        defaults: {
            'transitionIn'  :   'elastic',
            'transitionOut' :   'elastic',
            'speedIn'       :   200,
            'speedOut'      :   200,
            'titlePosition' :   'inside',
            'opacity'       :   false,
            'cyclic'        :   true,
            'centerOnScroll':   true,
            'titleShow'     :   false,
            'padding'       :   0
        },

        Init: function (obj, options)
        {
            var settings = (options)? $.extend( {}, Frontend.Fancyzoom.defaults, options) : Frontend.Fancyzoom.defaults;

            obj.fancybox(settings);

        }
    },

    Layout: {

        Navigation: {
            Init: function ()
            {
                $('nav#links > ul > li:first > a').addClass("first");
            }
        }


    },


    FlowPlayer: {

        defaults: {
            plugins: {
                controls: {
                    mute:                   false,
                    volume:                 false,
                    fullscreen:             false,
                    height:                 50,
                    autoHide:               false,
                    buttonColor:            'rgba(0, 0, 0, 1)',
                    buttonOverColor:        '#000000',
                    backgroundColor:        '#FFFFFF',
                    backgroundGradient:     'medium',
                    sliderColor:            '#eeeeee',

                    sliderBorder:           '0px solid #fff',
                    volumeSliderColor:      '#000000',
                    volumeBorder:           '0px solid #fff',

                    timeColor:              '#333333',
                    durationColor:          '#333333',
                    sliderBorder:           'none',
                    scrubberHeightRatio:    .35,
                    scrubberBarHeightRatio: .35,
                    volumeSliderHeightRatio:.15

                }
            },

            clip: {
                autoPlay: false
            },
            onBeforeBegin: function() {

                $f("*").each(function() {
                    this.stop();
                });
            }
        },

        Init: function(playerid, file, options)
        {

            var params =
                $.extend(
                    {},
                    Frontend.Player.defaults,
                    {
                        'clip' : {
                            autoPlay: false,
                            url : file
                        }
                    },
                    (options? options : {})
            );
            $f(playerid, Framework.WWW_HOME_DIR + "swf/flowplayer/flowplayer-3.2.7.swf", params);



        }


    },


    Player: {

        defaults: {
            'modes':            [
                { type: "flash", src: Framework.WWW_HOME_DIR + "swf/jwplayer/player.swf" },
                { type: 'html5' }
            ],
            'width':            "515",
            'height':           "24",
            'skin':             Framework.WWW_HOME_DIR + 'swf/jwplayer/s2.zip', //'http://www.longtailvideo.com/files/skins/minima/5/minima.zip', //
            'autostart':        "false",
            'allowfullscreen':  false,
            'controlbar':       'bottom',
            'events' : {

                'onPlay': function (event) {

                    var current = $(this).attr("id");
                    //alert("current: " + current);
                    $('object[id^="player-"]').each( function() {

                        if ( $(this).attr("id") != current) {
                            jwplayer($(this).attr("id")).pause(true);
                            //alert( $(this).attr("id") );
                        }
                    });


                }
            }


        },

        Init: function(playerid, playlist, options)
        {

            var params =
                $.extend(
                    {},
                    Frontend.Player.defaults,
                    {
                        'file':  playlist
                    },
                    (options? options : {})
            );


            jwplayer(playerid).setup( params );


        }

    }



}


