var $wnd = $(window);
var $doc = $(document);

if (console === undefined){
	var console =  {};
	console.log = function(d){};
}

function plusGetElementById(id){
	if (document.getElementById){
		return (document.getElementById(id));
	}else if (document.all){
		return (document.all[id]);
	}else{
		if (navigator.appname.indexOf("Netscape") != -1 && parseInt(navigator.appversion == 4)){
			return (document.layers[id]);
		}
	}
}
function openWithSelfMain(url,name,width,height,returnwindow){
	var options = "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
	var new_window = window.open(url, name, options);
	window.self.name = "main";
	new_window.focus();
	if (returnwindow != null){
	   return new_window;
	}
}
function appendSelectOption(selectMenuId, optionName, optionValue){
	var selectMenu = plusGetElementById(selectMenuId);
	var newoption = new Option(optionName, optionValue);
	newoption.selected = true;
	selectMenu.options[selectMenu.options.length] = newoption;
}
function disableElement(target){
	var targetDom = plusGetElementById(target);
	if (targetDom.disabled != true) {
		targetDom.disabled = true;
	} else {
		targetDom.disabled = false;
	}
}
function plusCheckAll(formname, switchid){
	var ele = document.forms[formname].elements;
	var switch_cbox = plusGetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if (e.name != switch_cbox.name && e.type == 'checkbox'){
			e.checked = switch_cbox.checked;
		}
	}
}
function plusCheckGroup(formname, switchid, groupid){
	var ele = document.forms[formname].elements;
	var switch_cbox = plusGetElementById(switchid);
	for (var i = 0; i < ele.length; i++){
		var e = ele[i];
		if (e.type == 'checkbox' && e.id == groupid){
			e.checked = switch_cbox.checked;
			e.click(); e.click();  // Click to ativar subgroups. Twice so we don't reverse effect
		}
	}
}
function plusCheckAllElements(elementIds, switchId){
	var switch_cbox = plusGetElementById(switchId);
	for (var i = 0; i < elementIds.length; i++){
		var e = plusGetElementById(elementIds[i]);
		if (e.name != switch_cbox.name && e.type == 'checkbox'){
			e.checked = switch_cbox.checked;
		}
	}
}
function plusInsertText(domobj, text){
	if(domobj.selectionEnd){
		var str1=domobj.value.substring(0, domobj.selectionStart);
		var str2=domobj.value.substring(domobj.selectionEnd, domobj.value.length);
		domobj.value = str1 + text + str2;
		domobj.selectionEnd = domobj.selectionStart;
		domobj.blur();	
	}else if (domobj.createTextRange && domobj.caretPos){
  		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;  
	}else if (domobj.getSelection && domobj.caretPos){
		var caretPos = domobj.caretPos;
		caretPos.text = caretPos.text.charat(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}else{
		domobj.value = domobj.value + text;
  	}
}
function showImgSelected(imgId, selectId, imgDir, extra, plusUrl){
	plusUrl = plusUrl || "./";
	imgDom = plusGetElementById(imgId);
	selectDom = plusGetElementById(selectId);
	if (selectDom.options[selectDom.selectedIndex].value != ""){
		imgDom.src = plusUrl + "/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value + extra;
	}else{
        imgDom.src = plusUrl + "/imagens/blank.gif";
	}
}
function getSelect(id){
	if (window.getSelection){
		ele = document.getElementById(id);
		var selection = ele.value.substring(ele.selectionStart, ele.selectionEnd);
	}else if (document.getSelection){
		var selection = document.getSelection();
	}else if (document.selection){
		var selection = document.selection.createRange().text;
	}else{
		var selection = null;
	}
	return selection;
}
function valida_tecla(campo, event){
	var key, tecla, BACKSPACE = 8;
	CheckTAB=true;
	if(navigator.appName.indexOf("Netscape")!= -1){
		tecla = event.which;
	}else{
		tecla = event.keyCode;
	}
	key = String.fromCharCode(tecla);
	if (tecla == 13) return false;
	if (tecla == BACKSPACE) return true;
	return (isNum(key));
}
function isNum(caractere){ 
	var strValidos = '0123456789'; 
	if (strValidos.indexOf(caractere) == -1) return false; 
	return true; 
}
function mascara_data(el){
	var mydata = el.value;

	if (mydata.length == 2){
		mydata = mydata + '/';
		el.value = mydata;
	}
	if (mydata.length == 5){
		mydata = mydata + '/';
		el.value = mydata;
	}
	if (mydata.length == 10){
		if(!verifica_data(mydata)){
			el.value='';
		}
	}
}
function verifica_data(data){
	var situacao = '';
	if (data.length == 0) return true;
	if (data.length != 10){
		situacao = 'falsa';
	}else{
		mes = (data.substring(3,5));
	
		// verifica se o mes e valido
		if (mes < 1 || mes > 12){
			situacao = 'falsa';
		}else{
			dia = (data.substring(0,2));
			// Verifica se o dia é válido para cada mês, exceto fevereiro.
			if (dia < 1 || dia > 31 || (dia > 30 && (mes == 4 || mes == 6 || mes == 9 || mes == 11))){
				situacao = 'falsa';
			}
			// Verifica se o dia é válido para o mês de fevereiro.
			if (mes == 2 && (dia < 1 || dia > 29 || (dia > 28 && (parseInt(ano/4) != ano/4)))){
				situacao = 'falsa';
			}
		}
	}
	if (situacao == 'falsa'){
		alert('Data inválida!');
		return false;
	}
	return true;
}
function mascara_cpf(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 3){
		mydata = mydata + '.';
		el.value = mydata;
	}
	if (mydata.length == 7){
		mydata = mydata + '.';
		el.value = mydata;
	}
	if (mydata.length == 11){
		mydata = mydata + '-';
		el.value = mydata;
	}
}
function mascara_hora(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 2){
		mydata = mydata + ':';
		el.value = mydata;
	}
}
function mascara_cep(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 5){
		mydata = mydata + '-';
		el.value = mydata;
	}
}
function mascara_inscricaoestadual(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 13){
		mydata = mydata + '-';
		el.value = mydata;
	}
}
function mascara_integer(campo, teclapres){
	var tecla = 0;
    if(navigator.appName.indexOf("Netscape")!= -1){
   		tecla = teclapres.which;
   	}else{
		tecla = teclapres.keyCode;
	}
	// Falta o caractere ',' (vírgula) do teclado numérico.
	if ((tecla >= 48 && tecla <= 57) || (tecla >= 96 && tecla <= 105)
	      || tecla == 8 || tecla == 9 || tecla == 13
	      || tecla == 37 || tecla == 39
	      || tecla == 45 || tecla == 46 || tecla == 35 || tecla == 36
	      || ((tecla == 67 || tecla == 86) && teclapres.ctrlKey)){
		return true;
	}
	return false;
}
function formata_money(campo, teclapres){
	if(navigator.appName.indexOf("Netscape")!= -1){
		var tecla= teclapres.which;
	}else{
		var tecla = teclapres.keyCode;
	}
	
	tammax = 13;
	vr = campo.value;
	vr = vr.replace("/", "");
	vr = vr.replace("/", "");
	vr = vr.replace(",", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	tam = vr.length;
	
	if (tecla == 188 || tecla == 190 || tecla == 110 || tecla == 108){
		return false;
	}
	if (tam < tammax && tecla != 8){
		tam = vr.length + 1 ;
	}
	if (tecla == 8 ){
		tam = tam - 1 ;
	}
	if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105){
		if (tam <= 2){ 
			campo.value = vr ;
		}
		if (tam > 2){
			campo.value = vr.substr(0, tam - 2) + ',' + vr.substr(tam - 2, tam);
		}
		/*if ( tam >= 6 && tam <= 8) {
			campo.value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam) ;
		}
		if ( tam >= 9 && tam <= 11) {
			campo.value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam) ;
		}
		if ( tam >= 12 && tam <= 14) {
			campo.value = vr.substr(0, tam - 11) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);
		}
		if ( (tam >= 15) && (tam <= 17) ) {
			campo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3 + '.' + vr.substr( tam - 5, 3) + ',' + vr.substr(tam - 2, tam) ;}
		}*/
	}
	return true;
}
function mascara_telefone(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 1){
		mydata = '(' + mydata;
		el.value = mydata;
	}
	if (mydata.length == 3){
		mydata = mydata+') ';
		el.value = mydata;
	}
	if (mydata.length == 9){
		mydata =  mydata + '-';
		el.value = mydata;
	}
}
function mascara_cnpj(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 3){
		mydata = mydata + '.';
		el.value = mydata;
	}
	if (mydata.length == 7){
		mydata = mydata + '.';
		el.value = mydata;
	}
	if (mydata.length == 11){
		mydata = mydata + '/';
		el.value = mydata;
	}
	if (mydata.length == 16){
		mydata = mydata + '-';
		el.value = mydata;
	}
}
function mascara_rg(el){
	var mydata = '';
	mydata = mydata + el.value;
	if (mydata.length == 2 || mydata.length == 1){
		mydata = mydata.toUpperCase();
		el.value = mydata;
	}
	if (mydata.length == 2){
		mydata = mydata + '-';
		el.value = mydata;
	}
	if (mydata.length == 5){
		mydata = mydata + '.';
		el.value = mydata;
	}
	if (mydata.length == 9){
		mydata = mydata + '.';
		el.value = mydata;
	}
}

/**
 * Menu
 */
(function($){
	var opts = {};

	$.fn.dropdownmenu = function(settings){
		opts.settings = $.extend({}, $.fn.dropdownmenu.defaults, settings);
		return this.each(function(){
			var $this = $(this);
			$.fn.dropdownmenu.init($this, opts.settings);
		});
	};
	
	$.fn.dropdownmenu.init = function(menuroot, o){
		var ultags = jQuery("ul", menuroot);
		menuroot.addClass("menuroot");
		menuroot.children("li").addClass("menuroot");
		menuroot.children("li").children("a").addClass("menuroot");
		menuroot.children("li:last-child").addClass("ultimo");
		
		jQuery.each(ultags, function(i, elem){
			var ultag = jQuery(this);
			ultag.prev("a").addClass("submenu");
			ultag.parent("li").addClass("submenu");
			
			switch (o.childGrowDirection){
				default:
				case 2:
					if (ultag.parent().parent().get(0)==menuroot.get(0)){
						ultag.css("left", ultag.parent().width()+"px");
					}else{
						ultag.css("left", jQuery("a", ultags[i-1]).width()+"px");
						ultag.css("display", "none");
					}
					break;
				case 3:
					if (ultag.parent().parent().get(0)==menuroot.get(0)){
						ultag.css("top", ultag.parent().height()+"px");
						ultag.css("left", "0px");
					}else{
						ultag.css("left", ultag.prev("a").width()+"px");
						ultag.css("display", "none");
					}
					break;
			}
			
			ultag.parent().mouseover(function(){
				ultag.css("display", "block");
			});
			ultag.parent().mouseout(function(){
				ultag.css("display", "none");
			});
		});
		
		jQuery.each(ultags, function(i, elem){
			var ultag = jQuery(this);
			ultag.css("visibility", "visible");
			ultag.css("display", "none");
		});
	};
	$.fn.dropdownmenu.defaults = {
		childGrowDirection:	2
	};
})(jQuery);

/**
 * PopUp
 */
function plusPopUp(url, o){
	function _convbool(b){
		return b ? 'yes' : 'no'; 
	}
	if (o === null) o = new Array();
	o.dontreturn = o.dontreturn || false; 
	o.window = o.window || 'plusPopUp';
	o.toolbar = _convbool(o.toolbar || false); 
	o.location = _convbool(o.location || false); 
	o.status = _convbool(o.status || false); 
	o.menubar = _convbool(o.menubar || false); 
	o.scrollbars = _convbool(o.scrollbars || false); 
	o.resizable = _convbool(o.resizable || false); 
	o.width = o.width || '400';
	o.height = o.height || '300';
	o.centerScreen = o.centerScreen || false;
	if (o.centerScreen){
		o.left = (screen.width/2)-(o.width/2);
		o.top = (screen.height/2)-(o.height/2);
	}
	o.maximized = o.maximized || false;
	if (o.maximized){
		o.left = 0;
		o.top = 0;
		o.width = window.screen.availWidth;
		o.height = window.screen.availHeight; 
	}
	o.left = o.left || '100';
	o.top = o.top || '100';
	o.extra = o.extra || '';
	
	var janela = window.open(url, o.window,
				'toolbar='+o.toolbar+
				',location='+o.location+
				',status='+o.status+
				',menubar='+o.menubar+
				',scrollbars='+o.scrollbars+
				',resizable='+o.resizable+
				',width='+o.width+
				',height='+o.height+
				',top='+o.top+
				',left='+o.left+
				o.extra);
	if (!o.dontreturn)
		return janela;
}

/*Open and Collapse form elements*/
function toogleSession(elemento){
	var el = $(elemento).parent().next(); 
	while(true){
		if(el.find(".fim_form_title").length == 0) {
			el.toggle();
			el = el.next();
		}else {
			break;
		}
	}
}

function nTableFold(elemento, e){
	if (e !== undefined){
		if (e.target.nodeName == "A"){
			return;
		}
	}
	var start = $(elemento);
	var closed = start.hasClass("plusNTableBreakClosed");
	
	jQuery.each(start.nextAll(), function(i, val){
		if ($(this).hasClass("plusNTableBreakEnd")) return false;
		if (closed) $(this).show();
		else $(this).hide();
	});
	
	if (closed){
		start.removeClass("plusNTableBreakClosed");
		start.find("div.plusNTableBreakLinks").show();
	}else{
		start.addClass("plusNTableBreakClosed");
		start.find("div.plusNTableBreakLinks").hide();
	}
}

/**
 * Cookies
 */
jQuery.cookie = function(name, value, options){
    if (typeof value != 'undefined'){ // name and value given, set cookie
        options = options || {};
        if (value === null){
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)){
            var date;
            if (typeof options.expires == 'number'){
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 86400000)); //24 * 60 * 60 * 1000
            }else{
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    }else{ // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != ''){
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++){
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')){
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
 * Util
 */
function strtr(str, from, to) {
	var fr = '', i = 0, j = 0, lenStr = 0, lenFrom = 0;
	var tmpFrom = [], tmpTo = [], ret = '', match = false;
	
	if (typeof from === 'object'){
		this.krsort(from);
		for (fr in from){
			tmpFrom.push(fr);
			tmpTo.push(from[fr]);
		}
		from = tmpFrom;
		to = tmpTo;
	}
	
	lenStr  = str.length;
	lenFrom = from.length;
	for (i = 0; i < lenStr; i++){
		match = false;
		for (j = 0; j < lenFrom; j++){
			if (str.substr(i, from[j].length) == from[j]){
				match = true;
				i = (i + from[j].length)-1;
				break;
			}
		}
		if (false !== match){
			ret += to[j];
		}else{
			ret += str[i];
		}
	}
	return ret;
}

/**
 * Ajax dependency
 */
function makeAjaxDependency(){
	var origins = this.origins, target = this.target, paramnames = this.paramnames;
	var path = target.attr("plus_dependencypath");
	var mode = target.attr("plus_dependencymode");
	var type = target.get(0).nodeName;
	
	var rdata = {};
	for (i in paramnames){
		rdata[paramnames[i]] = origins.eq(i).val();
	}
	
	$.getJSON(path, $.param(rdata), function(resposta){
		
		if (type == 'SELECT'){
			var currentval = target.val();
			target.empty();
			$.each(resposta.data, function(i, item){
				(!item) && (item = {});
				(!item.value) && (item.value = '');
				var option = document.createElement("option");
				option.value = item.value;
				option.innerHTML = item.label;
				if (item.value == currentval) option.selected = "selected";
				target.append(option);
			});
		}else if (type == 'INPUT'){
			target.val(resposta.data);
		}else{
			target.html(resposta.data);
		}
		
		if (mode == "recursive"){
			target.change();
		}
	});
}

function loadAjaxDependency(){
	var onreadyfuncs = [];
	var dependency = $("[plus_dependsof]");
	dependency.each(function(i, el){
		var $target = $(this);
		var origins = $target.attr("plus_dependsof").split(",");
		var paramnames = [];
		for (i in origins){
			var o = origins[i].split("\|")
			origins[i] = document.getElementById(o[0]);
			paramnames.push(o[1] !== undefined ? o[1] : o[0]);
		}
		var $origins = $(origins);
		var func = $.proxy(makeAjaxDependency, {origins: $origins, target: $target, paramnames: paramnames});
		$origins.each(function(i, el){
			$(this).change(func);
		});
		if ($target.attr("plus_dependencyonready") == "yes"){
			onreadyfuncs.push(func);
		}
	});
	for (i in onreadyfuncs){
		onreadyfuncs[i]();
	}
}

/**
 * TinyMCE
 */
function izp_call_browser(field_name, url, type, win){
	if(type == "image"){
		tinyMCE.activeEditor.windowManager.open({
			file: plus_url+"/browser_image.php",
			width: 550,
			height: 380,
			resizable: "yes",
			inline: "yes",
			close_previous: "no"
		},{
			win: win,
			input: field_name
		});
	}else if(type == "media"){
		tinyMCE.activeEditor.windowManager.open({
			file: plus_url+"/modulos/conteudo/admin/browser_media.php",
			width: 550,
			height: 380,
			resizable: "yes",
			inline: "yes",
			close_previous: "no"
		},{
			win: win,
			input: field_name
		});
	}else if(type == "file"){
		tinyMCE.activeEditor.windowManager.open({
			file: plus_url+"/modulos/conteudo/admin/browser_files.php",
			title: "Gerenciador de imagens",
			width: 550,
			height: 380,
			resizable: "yes",
			inline: "yes",
			close_previous: "no"
		},{
			win: win,
			input: field_name
		});
	}
	return false;
}

/**
 * PlusModal
 */
function plusModal(urlmodal, action){
	if (typeof(action) == "function"){
		$.nyroModalManual({
			url: urlmodal,
			endRemove: action
		});
	}else{
		$.nyroModalManual({
			url: urlmodal,
			endRemove: function(){
				atualizaComponentes(action);
			}
		});
	}
}
function atualizaComponentes(actions){
	if (actions == null) return;
	for (var i in actions){
		var a = actions[i];
		//TODO: type (json/html)
		var obj = $(a.elem);
		atualizaRequest(a.url, obj);
	}
}
function atualizaRequest(url, obj, params){
	if (params === undefined) params = {};
	jQuery.get(url, params, function(r){
		var type = obj.get(0).nodeName;
		if (type == 'SELECT'){
			r = eval("("+r+")");
			var oldvalue = obj.val();
			obj.empty();
			$.each(r.data, function(i, item){
				var option = document.createElement("option");
				option.value = item.value;
				option.innerHTML = item.text;
				obj.append(option);
			});
			obj.val(oldvalue);
		}else if (type == 'INPUT'){
			r = eval("("+r+")");
			obj.val(r.data.value);
		}else{
			obj.html(r);
		}
	});
}

function PlusAtualiza(){
	this.grupos	= new Array(); //PlusAtualizaGrupo
}
PlusAtualiza.prototype = {
	addGrupo: function(nome){
		if (nome == "") return false;
		if (this.getGrupo(nome) != null) return false;
		var item = new PlusAtualizaGrupo(nome);
		this.grupos.push(item);
		return item;
	},
	getGrupo: function(nome){
		if (nome == "") return null;
		var g = this.grupos;
		for(var i in g){
			if (g[i].nome == nome) return g[i];
		}
		return null;
	},
	executeGrupo: function(nome, params){
		params = params || null;
		var grupo = this.getGrupo(nome);
		if (grupo != null){
			grupo.execute(params);
		}
	}
};

function PlusAtualizaGrupo(nome){
	this.nome	= nome;
	this.lista	= new Array(); //Object {elem, url}
}
PlusAtualizaGrupo.prototype = {
	addItem: function(action){
		this.lista.push(action);
	},
	execute: function(params){
		if (params != undefined && params != null){
			var cLista = new Array();
			for (var i in this.lista){
				var item = this.lista[i];
				var cItem = {};
				jQuery.each(item, function(j, val){
					cItem[j] = changeParams(val);
				});
				cLista.push(cItem);
			}
			atualizaComponentes(cLista);
		}else{
			atualizaComponentes(this.lista);
		}
		
		function changeParams(p){
			for (var i in params)
				p = p.replace(eval("/<@"+i+">/g"), params[i]);
			return p;
		}
	}
};

var plusAtualiza = new PlusAtualiza();

/**
 * Dialog
 */
function plusYNDialog(title, msg, link){
	$('<div title="'+title+'">').html(msg).dialog({
		bgiframe: false,
		resizable: false,
		width: "auto",
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			'Sim': function(){
				$(this).dialog('close');
				if (typeof(link) == "function") {
					link();
				}else{
					window.location = link;
				}
			},
			'Não': function(){
				$(this).dialog('close');
			}
		}
	});
}
function plusDialog(title, content, buttons){
	return $('<div title="' + title + '">').html(content).dialog({
		bgiframe: false,
		resizable: false,
		width: "auto",
		maxWidth: 500,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: buttons
	});
}

/**
 * SEO
 */
function seoTitle(title){
	title = jQuery.trim(title.toLowerCase());
	title = title.replace(/[ ]+/g, ' ');
	title = strtr(title, "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ '&\"-", "aaaaeeiooouucAAAAEEIOOOUUC_____");
	title = title.replace(/\W/g, '');
	title = title.replace(/_/g, '-');
	return title;
}
function removeAcento(str){
	return strtr(str, "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ", "aaaaeeiooouucAAAAEEIOOOUUC");;
}

/**
 * Plus Object
 */
var plus = new Object;

plus.tema = {};
plus.modulos = {};
plus.fn = {};
plus.form = {};

function Timer(){};
Timer.prototype = {
	list: new Array,
	
	out: function(name, time, func){
		this.clear(name);
		var o = setTimeout(func, time);
		this.list[name] = {o: o, type: "out"};
		return o;
	},
	repeat: function(name, time, func, callnow){
		callnow = (callnow === undefined) ? false : callnow;
		this.clear(name);
		if (callnow) func();
		var o = setInterval(func, time);
		this.list[name] = {o: o, type: "repeat"};
		return o;
	},
	clear: function(name){
		var item = this.list[name];
		if (item === undefined) return false;
		
		if (item.type == "out"){
			clearTimeout(item.o);
			delete this.list[name];
		}else if (item.type == "repeat"){
			clearInterval(item.o);
			delete this.list[name];
		}
		return true;
	}
};
plus.timer = new Timer;

plus.tabs = {
	init: function(){
		$(".plusTabs").each(function(){
			plus.tabs.make($(this));
		});
	},
	make: function(plustab){
		var tabs = plustab.children(".tabTabs").children(".tabItem");
		var contents = plustab.children(".tabContents").children(".tabContent");
		
		tabs.each(function(){
			var tab = $(this);
			var tabitem = tab.attr("plus_tabitem");
			var obj = {
				tabs: tabs,
				contents: contents,
				tab: tab,
				tabitem: tabitem,
				content: contents.filter("[plus_tabitem="+tabitem+"]"),
				path: tab.attr("plus_tabitempath") || ""
			};
			tab.click($.proxy(plus.tabs.select, obj));
		});
		
		tabs.filter(".selected:first").click();
	},
	select: function(){
		this.tabs.removeClass("selected");
		this.tab.addClass("selected");
		this.contents.removeClass("selected").hide();
		this.content.addClass("selected").show();
		
		if (this.path != ""){
			atualizaRequest(this.path, this.content);
		}
	}
};

plus.player = {
	ctrl: null,
	displayList: {},
	
	init: function(){
		top.window.playerInterfaceInit();
	},
	ready: function(ctrl){
		plus.player.ctrl = ctrl;
		plus.player.ctrl.updateDisplay = plus.player.updateDisplay;
		
		if (top.window.autoload.url != "" && top.window.autoload.text != ""){
			plus.player.ctrl.loadMusic(top.window.autoload.url, top.window.autoload.text);
			top.window.autoload.url = "";
			top.window.autoload.text = "";
		}else if (top.window.autoload.list == true){
			plus.player.ctrl.loadList(ctrl.prop.autostart);
			top.window.autoload.list = false;
		}
		
		plus.player.ctrl.display();
	},
	setDisplay: function(name, func){
		plus.player.displayList[name] = func;
	},
	updateDisplay: function(name){
		if (name == undefined || name == null) {
			for (var display in plus.player.displayList){
				$.proxy(plus.player.displayList[display], plus.player.ctrl)();
			}
		} else if (plus.player.displayList[name]){
			$.proxy(plus.player.displayList[name], plus.player.ctrl)();
		}
	}
};

$doc.ready(function(){
	loadAjaxDependency();
	plus.tabs.init();
});