/***
 * FlashMovie Einbindung
 * @author: Oliver Neudeck, Michael Bayer
 */

if (swfobject.hasFlashPlayerVersion("8")) {

    $(function () {

        $("body").append($("<div></div>").attr('id','layer'));
        $("body").append($("<a></a>").attr('id','stopvideo'));

        // Auslesen Bildname und entfernen Pfadangaben
        var StrImgURL = $("#img").attr("href");
        StrImgURL = StrImgURL.replace(/(fileadmin\/img\/)/g,'');
        // Auslesen Video-Name und entfernen Pfadangaben
        var StrFlvURL = $("#film").attr("href");
        StrFlvURL = StrFlvURL.replace(/(fileadmin\/swf\/)/g,'');
        // Ersetzen der Typo3-Hooks durch Variablen (Javascriptcode wird durch T3 nach Tags und Pfaden geparst)
        var WA = "/";
        var WAgt = ">";
        var WAlt = "<";
        var StrVideo = ''+WAlt+'div class="text layout_container"'+WAgt+''+WAlt+'a href="#" id="playvideo" class="blank"'+WAgt+''+WAlt+'img src="/fileadmin/img/'+StrImgURL+'" '+WA+'/'+WAgt+''+WAlt+''+WA+'a'+WAgt+''+WAlt+'div id="video_container"'+WAgt+''+WAlt+'div id="video"'+WAgt+''+WAlt+''+WA+'div'+WAgt+''+WAlt+''+WA+'div'+WAgt+'';
    
        // Event-Handler Video-Start
        $("div[class='text layout_container']").replaceWith(StrVideo);
        $("a#playvideo").live('click',function () {
    
            (isIE6) ? $('html').css('overflow-x','hidden').css('overflow-y','hidden') : '';
    
            if( $('#video').length == 0 ) {
                $('#video_container').append( $("<div></div>").attr('id','video') );
            }
            var params = {};
                params.wmode = 'window';
                params.allowfullscreen = 'true';
            var flashvars = {};
                wiredminds.trackEvent('Infofilm_so_funktioniert_LC1');
                flashvars.file = StrFlvURL;
                flashvars.image = '/fileadmin/swf/preview.jpg';
                flashvars.fullscreen = 'true';
                flashvars.smoothing = 'true';
                flashvars.autostart = 'true';
            swfobject.embedSWF("/fileadmin/swf/player.swf", "video", "488", "295", "8.0.0", null, flashvars, params, null );
    
            $('#layer').height( $(document).height() ).width( $(document).width() ).css('opacity','0.8').fadeIn('300');
            $('#video_container').show();
            $('#stopvideo').css('display','block');
    
            return false;
        });
    
        $("#layer,#stopvideo").live('click',function () {
            $('#layer').fadeOut(300,function() {
                swfobject.removeSWF("video");
                $('#video_container').hide();
                $('#stopvideo').css('display','none');
                (isIE6) ? $('html').css('overflow-x','scroll').css('overflow-y','scroll') : '';
            });
    
            return false;
        });
        
    });

}