
DRHorton = DRHorton || {};

DRHorton.community = DRHorton.community || {};

DRHorton.community.mediaHelper = DRHorton.community.mediaHelper || {};

;(function($){
    
    var _id, _src, _selector, _width, _height, _autoplay, _controls, _loop,
        _mediaHTML = '<object name="#id#" id="#id#" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject" width="#width#" height="#height#" >'
        + '<param name="filename" value="#url#" />'
        + '<param name="stretchtofit " value="1" />'
        + '<param name="autosize" value="1" />'
        + '<param name="displaysize" value="0" />'
        + '<param name="transparentatstart" value="0" />'
        + '<param name="autostart" value="#autostart#" />'
        + '<param name="showcontrols" value="#showcontrols#" />'
        + '<param name="loop" value="#loop#" />'
        + '<embed name="#id#" id="#id#" type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" '
        + 'src="#url#" width="#width#" height="#height#" '
        + 'bgcolor="darkblue" displaysize="0" autosize="1" showtracker="-1" transparentatstart="0" '
        + 'showdisplay="0" showstatusbar="0" videoborder3d="-1" designtimesp="5311" stretchtofit="-1" '
        + 'autoStart="#autostart#" loop="#loop#" showcontrols="#showcontrols#" controls="#showcontrols#" '
        + 'playCount="0" >'
        + '</embed>'
        + '</object>',
        
        
        _embedMedia = function(){
            
            $(_selector).html(
                DRHorton.utils.parseTemplate(_mediaHTML, {
                    url : _src,
                    width : _width,
                    height : _height,
                    id : _id,
                    loop : _loop,
                    showcontrols : _controls,
                    autostart : _autoplay
                })                
            );
            
            DRHorton.utils.testConditionOverTime({
                expression: "$('#" + _id + "').width() > " + _width,
                interval: 250,
                timeLimit: 2000,
                success: function(){
                    $('#' + _id).width(_width).height(_height);
                }
            })
        },
        
        _embedFlash = function(){
            $(_selector).flash({
                swf: _src,
                width: _width,
                id: _id,
                height: _height,
                play: true,
                allowscriptaccess: "never"
            });
        }
        
        
        ;
        
    DRHorton.core.include('/App_Themes/DRHortonSite/js/DRHorton/DRHorton.utils.js');
    DRHorton.core.include('/App_Themes/DRHortonSite/js/jquery.swfobject.1-1-1.min.js');
    
    DRHorton.community.mediaHelper.embed = function(data){

        _id = "community_object_" + Math.random().toString().replace('.', '');
        _src = data.url;
        _selector = data.selector;
        _width = data.width
        _height = data.height;
        _autoplay = data.autoplay;
        _controls = data.controls;
        _loop = data.loop;
    
    
        var match = _src.match(/\.(wmv|swf|mpg|mpeg|avi|mov)/im);
        
        if(match != null){
            switch(match[1].toLowerCase()){
                
                case('swf'):{
                    _embedFlash();
                    break;
                }
                default:{
                    _embedMedia();
                }
            }
        }
        else {
            alert("Unknown Video Format")
        }
        
        return;
    
    }
    
}(jQuery))




