function dirname(sPath) {
    var oArguments = ( dirname.arguments.length == 2 ? dirname.arguments[1] : false );
    sPath = sPath.substr(0,sPath.lastIndexOf('/')+(oArguments.bNoEndingSlash?0:1))
    return ( sPath.indexOf('//')!=-1 ? sPath.substr(sPath.indexOf('/',sPath.indexOf('//')+2)) : sPath );

}

function filename(sPath) {
    return sPath.substr(sPath.lastIndexOf('/')+1);
}

$(document).ready(function () {
    
    if ($('div.video')) {
        
        var oFlvPlayerCfg = {
            sId : 'flvvideoplayer',
            sPathPlayer : 'http://www.teachersteelpan.de/cms/swf/flvplayer/flvplayer.swf',
            sPathContent : 'http://www.teachersteelpan.de/cms/upload/videos/',
            sSwfVersion : '9.0.28',
            sExpressInstall : 'expressInstall.swf',
            sButtonOverlay : '', // Sets a custom buttonoverlay ( = button with play symbol on the intro screen).  Example: buttonoverlay-blue.swf    Default: default buttonoverlay
            sPreLoader : '', // Sets a custom preloader.  Example: preloader-ajax.swf    Default: default preloader 
            sPreRoll : '', // Allows you to show a video before the main video (for instance advertisement). The preroll video cannot be skipped.   Example: demo-ad.flv    Default: -
            sEnding : '', // Sets a custom ending ( = button with replay symbol on the end screen).  Example: ending-blue.swf    Default: default ending 
            sSkin : '', // Sets a custom skin. This skin has to be compatible with the FLV Playback Component of Flash (CS3+CS4). 	 Example: skin-applestyle.swf    Default: default skin
            sSkinColor : '0xFF0000', // Changes the color of the play skin. Use hex color values. (Note: Skin must support changing its color)  Example: 0xFF0000    Default: 0x555555 (grey) 
            iSkinScaleMaximum : 1, // This parameters is a scale factor for the skin in the fullscreen mode. A higher value will increase the size of the buttons in the fullscreen mode and will reduce the required computer power. 4.5 is the maximum (biggest buttons and best performance).  Example: 2 or 3 or 4.5    Default: 1
            iSkinControlbarHeight : 45,
            bAutoPlay : false,	 // The video starts immediatelly without the intro screen (containing the preview picture and the button).   Example: true or false    Default: false 
            bLoop : false, // If the video reaches the end, it'll be started again automatically.  Example: true  or false    Default: false
            bIsLive : false, // Enables live streaming mode. Requires a streaming server (FMS, Wowza, etc.)  Example: true  or false    Default: false 
            bSmoothing : true, // Specifies whether the video should be smoothed (interpolated) when it is scaled. This will result in better quality but requires more power.  Example: true  or false    Default: true 
            bAutoScale : false, // Your video will be automatically scaled to its native size. Therefore, it's displayed in the best quality – that's why this turned on by default. If want to force a custom a custom size: Set this parameter to false and use the following two parameters for the width and height of the video.  Example: true  or false    Default: true
            iVolume : 1, // Initial volume of the player.  Example: Number from 0 to 1 	 0 (mute), 0.5  (half)    Default: 1 
            oPlayerVars : false,
            sBgColor : '#ffffff',
            bDebug : false
        }               
        
        $('div.video div.noswfjs').remove();
        
        var sPathVideo = $('div.video div.player a.clip').attr('href');
        var sPathPreview = $('div.video div.player a.clip img').attr('src');
        $('div.video div.player').wrapInner('<div>').find('div').attr('id',oFlvPlayerCfg.sId);
        var iPlayerWidth = $("#"+oFlvPlayerCfg.sId).width();
        var iPlayerHeight = Math.ceil((iPlayerWidth/4)*3);
        var iVideoWidth = iPlayerWidth;
        var iVideoHeight = iPlayerHeight;
        iPlayerHeight += oFlvPlayerCfg.iSkinControlbarHeight;
        var captions = '';
            
        swfobject.embedSWF(
            oFlvPlayerCfg.sPathPlayer + '?'
                + 'contentpath=' + oFlvPlayerCfg.sPathContent + '&'
                + 'video=' + sPathVideo.replace(oFlvPlayerCfg.sPathContent,'') + '&'
                + 'preview=' + sPathPreview.replace(oFlvPlayerCfg.sPathContent,'') + '&'
                + 'captions=' + captions + '&'
                + 'preroll=' + oFlvPlayerCfg.sPreRoll + '&'
                + 'autoplay=' + oFlvPlayerCfg.bAutoPlay + '&'
                + 'loop=' + oFlvPlayerCfg.bLoop + '&'
                + 'islive=' + oFlvPlayerCfg.bIsLive + '&'
                + 'volume=' + oFlvPlayerCfg.iVolume + '&'
                + 'smoothing=' + oFlvPlayerCfg.bSmoothing + '&'
                + 'autoscale=' + oFlvPlayerCfg.bAutoScale + '&'
                + 'videowidth=' + iVideoWidth + '&'
                + 'videoheight=' + iVideoHeight + '&'
                + 'skincolor=' + oFlvPlayerCfg.sSkinColor + '&'
                + 'skinscalemaximum=' + oFlvPlayerCfg.iSkinScaleMaximum + '&'
                + 'skin=' + oFlvPlayerCfg.sSkin + '&'
                + 'preloader=' + oFlvPlayerCfg.sPreLoader + '&'
                + 'buttonoverlay=' + oFlvPlayerCfg.sButtonOverlay + '&'
                + 'ending=' + oFlvPlayerCfg.sEnding + '&'
                + 'debug=' + oFlvPlayerCfg.bDebug,
            oFlvPlayerCfg.sId,
            iPlayerWidth, iPlayerHeight, 
            oFlvPlayerCfg.sSwfVersion, 
            oFlvPlayerCfg.sExpressInstall, 
            oFlvPlayerCfg.oPlayerVars, 
            { 
                scale: 'noscale', 
                allowfullscreen: 'true',
                salign: 'tl', 
                bgcolor: oFlvPlayerCfg.sBgColor, 
                base: '.',
                quality: 'best',
                wmode: 'transparent'
            },
            {
                align: 'center'
            }
        );
        
        
    }
  
} );