jQuery(function( $ )
{
        $.easing.none = function(x, t, b, c, d)
        {
                if (!Autoscroll())
                {
                        throw('err1');
                }

                return (x);
        };
});

function InsertPlayer(songUrl, repeat)
{
        var so = new SWFObject('./assets/audio/player/mediaplayer.swf','mp3player','0','0','6');
        so.addParam('allowscriptaccess','always');
        so.addVariable('width','0');
        so.addVariable('height','0');
        so.addVariable('file', songUrl);
        so.addVariable('autostart', 'true');
        so.addVariable('repeat', repeat);
        so.addVariable('volume', '0');
        so.addVariable('javascriptid','mp3player');
        so.addVariable('enablejs','true');
        so.write('playerObj');
}

function ToggleMusic()
{
        $.cookie('autoplay', ($.cookie('autoplay') == 'true') ? 'false' : 'true');
        $('#player').removeClass();
        $('#player').addClass((Autoplay()) ? 'stop' : 'play');

        SendEvent('mp3player', 'volume', (Autoplay()) ? '100' : '0');
}

function InitMusic()
{
        if (Autoplay())
        {
                $('#player').removeClass();
                $('#player').addClass('stop');

                try
                {
                        SendEvent('mp3player', 'volume', '100');
                }
                catch (err)
                {
                        setTimeout('InitMusic()', 100)
                }
        }
}

function Autoplay()
{
        if (($.cookie('autoplay') != 'true') &&
                ($.cookie('autoplay') != 'false'))
        {
                $.cookie('autoplay', 'true');
        }

        return ($.cookie('autoplay') == 'true') ? true : false;
}

function InitAutoscroll(id, myDuration)
{
        SetMarginsForScroller(id);

        //this one is important, many browsers don't reset scroll on refreshes`
        $(id).scrollTo( 0 ); //reset all scrollable panes to (0,0)

        if (Autoscroll())
        {
                $('#scrollerButton').removeClass();
                $('#scrollerButton').addClass('autoScroll');
                $(id).removeClass('manualScrolling');
                $(id).addClass('autoScrolling');
                $(id + ' > div').removeClass('manualScroller');
                $(id).scrollTo( $('#end'), {easing:'none', duration:myDuration, margin:false, onAfter:function(){GoToNext();}} );
        }
        else if (! $(id).hasClass('manualScroll'))
        {
                $('#scrollerButton').removeClass();
                $('#scrollerButton').addClass('stopScroll');
                $(id).removeClass('autoScrolling');
                $(id).addClass('manualScrolling');
                $(id + ' > div').addClass('manualScroller');
        }
        
}

function ToggleAutoscroll(id, myDuration)
{
        $.cookie('autoscroll', ($.cookie('autoscroll') == 'true') ? 'false' : 'true');

        $(id).stop(); // stop the scrolling

        SetMarginsForScroller(id);

        if (Autoscroll())
        {
                $('#scrollerButton').removeClass();
                $('#scrollerButton').addClass('autoScroll');
                $(id).removeClass('manualScrolling');
                $(id).addClass('autoScrolling');
                $(id).scrollTo( $('#end'), {easing:'none', duration:myDuration, margin:false, onAfter:function(){GoToNext();}} );
        }
        else if (! $(id).hasClass('manualScroll'))
        {
                $('#scrollerButton').removeClass();
                $('#scrollerButton').addClass('stopScroll');
                $(id).removeClass('autoScrolling');
                $(id).addClass('manualScrolling');
        }
}

function SetMarginsForScroller(id)
{
        var margin = parseInt($(id).css('height'));

        if (Autoscroll())
        {
                $('#scroller').css('margin-top', margin + 'px');
                $('#scroller').css('margin-bottom', margin + 'px');
                $(id).scrollTo('+=' + (margin - 30) + 'px');
        }
        else
        {
                $('#scroller').css('margin-top', '30px');
                $('#scroller').css('margin-bottom', '30px');
                $(id).scrollTo('-=' + (margin - 30) + 'px');
        }
}

function Autoscroll()
{
        if (($.cookie('autoscroll') != 'true') &&
                ($.cookie('autoscroll') != 'false'))
        {
                $.cookie('autoscroll', 'true');
        }

        return ($.cookie('autoscroll') == 'true') ? true : false;
}

function SendEvent(swf, typ, prm)
{ 
        GetMovie(swf).sendEvent(typ, prm); 
}

function GetMovie(swf)
{
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
                return window[swf];
        }
        else
        {
                return document[swf];
        }
}

