﻿VideodExtensions = ".(fla|mpg|asf|wma|wmv|avi|mov|mp3|rmvb|mid)$";
ImageExtensions	= ".(jpg|gif|jpeg|png|bmp)$" ;
FlashExtensions	= ".(swf)$" ;
FlvExtensions	= ".(flv)$" ;

var Images=new RegExp(ImageExtensions, 'i' );
var Flashs= new RegExp(FlashExtensions, 'i' ) ;
var Videos=new  RegExp(VideodExtensions, 'i' ) ;
var Flvs= new RegExp(FlvExtensions, 'i' ) ;

function LoadMedia(url,width,height){
    if(typeof width== 'undefined'){
        width=0;
    }
    if(typeof height== 'undefined'){
        height=0;
    }
    var str="";
    if(Images.test(url)){
        if(width!=0&&height!=0){
            str="<img src='"+url+"' width='"+width+"px'  height='"+height+"px'/>";
        }
        else{
            str="<img src='"+url+"'/>";
        }
    }
    else if(Flashs.test(url)){
        if(width!=0&&height!=0){
            str="<embed  width='"+width+"' height='"+height+"' pluginspage='http://www.macromedia.com/go/getflashplayer' src='"+url+"' type='application/x-shockwave-flash'/>";            
        }
        else{
            str="<embed width='250' height='200' pluginspage='http://www.macromedia.com/go/getflashplayer' src='"+url+"' type='application/x-shockwave-flash' WMODE='opaque' QUALITY='high' allowNetworking='internal' allowScriptAccess='never'/>";
        }
    }
    else if(Flvs.test(url)){
        if(width!=0&&height!=0){
            str="<object width='"+width+"' height='"+height+"' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>"+ 
                "<param name='movie' value='flvplayer.swf?autostart=1&repeat='always'' />"+
                "<param name='quality' value='high' />"+
                "<param name='allowfullscreen' value='true' />"+
                "<param name='IsAutoPlay' value='1' />"+
                "<param name='flashvars' value='file="+url+"&IsAutoPlay=1&repeat='always''/></object>";            
        }
        else{
              str="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>"+ 
                "<param name='movie' value='flvplayer.swf?autostart=1&repeat='always'' />"+
                "<param name='quality' value='high' />"+
                "<param name='allowfullscreen' value='true' />"+
                "<param name='IsAutoPlay' value='1' />"+
                "<param name='flashvars' value='file="+url+"&IsAutoPlay=1&repeat='always'' /></object>";  
        }
    }
    else if(Videos.test(url)){
        var type="";
        if(WinPlayer(url)!=null){ 
            type='application/x-mplayer2';
        } 
        else if(RealPlayer(url)!=null){ 
            type='audio/x-pn-realaudio-plugin'; 
        } 
        else if(QuickTime(url)!=null){ 
           type='application/video/quicktime'; 
        } 
        
        if(width!=0&&height!=0){
            str="<embed autostart='1' showpositioncontrols='0' showstatusbar='0' loop='1'  width='"+width+"' height='"+height+"' src='"+url+"' type='"+type+"'/>";
        }
        else{
            str="<embed width='250' height='200'  autostart='1' showpositioncontrols='0' showstatusbar='0' loop='1' src='"+url+"' type='"+type+"'/>";
        }
    }
    document.write(str);
}

function WinPlayer(url){
    var r, re;
    re = /.(avi|wmv|asf|wma|mid|mp3|mpg)$/i;
    r = url.match(re);
    return r;
}

function RealPlayer(url){
    var r, re;
    re = /.(.rm|.ra|.rmvb|ram)$/i;
    r = url.match(re);
    return r;
}

function QuickTime(url){
    var r, re;
    re = /.(mov|qt)$/i;
    r = url.match(re);
    return r;
}
