var Rbm = {
}
Rbm.Form={
    remote:function (form,container){
        $(form).request(
            {
                onSuccess:function(obj){
                    try{
                        /*var scripts = obj.responseText.extractScripts();
                        try{                          
                          scripts = "window._tmp= function(){"+scripts+"}";
                          eval(scripts);
                          var fn = window._tmp;
                          window._tmp = null;
                          fn();
                        }catch(e){
                            alert(e+" - Erro ao executar o script do retorno");
                        }*/
                        var html = obj.responseText;
                        
                        $(container).update(html);
                        

                    }catch(e){
                        alert(e);
                    }
                },
                onFailure:function(obj){
                  
                    //alert('Ocorreu um erro por favor informe o erro apresentado a seguir ao desenvolvedor');
                    document.write('<h1>Por favor informe este erro</h1> '.obj.responseText);
                }

            }
        );


              
    }
}
Rbm.Popup = {
    PopupObserver : function(url,width,height,callBack){
        this._popup = Rbm.Popup.open(url,width,height);
        this.callBack = callBack;
        this.onTimer = function(){
            if(this._popup.closed){
                clearInterval(this.timer);
                this.callBack();
            }
        }
        this.timer = setInterval(this.onTimer.bind(this),500);//escuta para ver se o popup foi fechado
    },
    open: function(url,width,height){
        var top = (screen.height - height) / 2;
	var left = (screen.width - width) / 2;
        var parameters =  "scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" + width + ",height=" + height + ",top=" + top + ",left=" +  left;
        return window.open(url, '_blank', parameters);
    }
}

Rbm.Youtube = Class.create(
       {
        initialize:function(width,height){
            this.width= typeof width !='undefined'?width:300;
            this.height= typeof height !='undefined'?height:210;
        },
        showPlayer:function(url,id){
          url = this.parseUrl(url);
          if(!url)return;
          var container = document.getElementById(id);
          try{
            var urlatual = container.getElementsByTagName('embed').item(0);
            urlatual = urlatual.src;
            if(urlatual == url)return;
          }catch(e){

          }
          container.innerHTML = this._showPlayer(url);
        },
        _showPlayer:function(url){
          var ret= '<object width="'+this.width+'" height="'+this.height+'">'+
                    '<param name="movie" value='+url+'>'+
                    '</param><param name="allowFullScreen" value="true"></param>'+
                    '<param name="wmode" value="transparent" />'+
                    '<param name="allowscriptaccess" value="always"></param>'+
                    '<embed wmode="transparent" src="'+url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+this.width+'" height="'+this.height+'">'+
                '</embed>'+
             '</object>  ';
         return ret;
        }
        ,
        parseUrl:function(url){
           var reg = /http:\/\/[^\"\']+/;
           var url = reg.exec(url);
           url = url?url[0]:'';
           url = url.replace('watch?v=', 'v/');
           url = url.split('&');
           url = url[0];
           url = url?url + "&hl=pt-BR&fs=1":null;

           return url;
        }

    }
);
Rbm.Flash = Class.create({
    height:'100%',
    width :'100%',
    transparent:true,
    url:'',
    initialize:function(url,width,height,transparent){
        this.url = url;
        this.height = height?height:this.height;
        this.width = width?width:this.width;
        this.transparent = transparent?transparent:this.transparent;

    },
    display:function(container){
        
        var transparent = this.transparent?'transparent':'normal';
        $(container).update(
            '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+this.width+'" height="'+this.height+'" id="teste" align="middle">'+
                '<param name="allowScriptAccess" value="sameDomain" />'+
                 '<param name="menu" value="false" />'+
                '<param name="movie" value="'+this.url+'" />'+
                '<param name="quality" value="best" />'+
                '<param name="bgcolor" value="#ffffff" />'+
                '<embed src="'+this.url+'" wmode="'+transparent+'" menu="false" '+
                        'quality="best" width="'+this.width+'" height="'+this.height+'" '+
                        'name="teste" align="middle" allowScriptAccess="sameDomain" '+
                        'type="application/x-shockwave-flash" '+
                        'pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
                '<param name="wmode" value="'+transparent+'" />'+
            '</object>'
        );
    }


})

function openFlashPlayer(flashvideo , video_container , auto, width, height , path_image)
{ 
    var s1 = new SWFObject(BASE_URL+"javascripts/mediaplayer/player.swf", "flv-viewer", width, height, "9");
    s1.addParam('allowfullscreen','false');
    s1.addParam('allowscriptaccess','always');
    s1.addParam('wmode','transparent');
    s1.addParam("base", "");

    if(path_image!=""){
        s1.addParam('flashvars','file='+flashvideo+'&autostart='+auto+'&plugins=advertising,delicious&image='+path_image);
    }else{
        s1.addParam('flashvars','file='+flashvideo+'&autostart='+auto+'&plugins=advertising,delicious');
    }

    s1.write(video_container);
}


function banner_rotativo(container){

	var elemento = '#'+container;						//equivalente à document.getElementById()
	$j(elemento).cycle({						//metodo da biblioteca jquery.cycle.all.js
			cleartype:     !$j.support.opacity,  //true if clearType corrections should be applied (for IE)
    		cleartypeNoBg: true, 				//set to true to disable extra cleartype fixing (leave false to force background color setting on slides)
		 	fx:    'fade',				//efeito
		    sync:   0, 							//de onde surge o próximo elemento
		    delay: -2000,						//tempo após inicio do 'scrollDown' quando elemento está saindo da página para que o próximo elemento faça o 'scrollDown', entrando na página
		    timeout:  10000,						//intervalo entre efeitos
                    speed:1500
		});

}