// JavaScript Document

function mudarCoisas(tag, modifier, property, val){
	//trace(tag + "; " + property + "; " + modifier + "; " + val);
	if(tag == "body")
		tag = "#sandbox";
	else if(tag == "bg"){
		tag = "#sandbox";
		property = "background-color";
	}
	
	if(modifier == 'visited')
		tag = "#sandbox #visited";
	else if(modifier == 'hover'){
		var stls = $("pseudoStyle").get('html');	
		//var defs = stls.match(/{(.|\n|\r)*}/)[1];
		var rx = new RegExp(property + ":(.*);$", "m");
		if(stls.match(rx)){
			stls = stls.replace(rx, property + ": " + val + ";\n");
		}
		else{
			//var pos = stls.indexOf('}');
			stls = stls.replace(/}/, property + ": " + val + ";\n}");
		}
		//trace(stls);
		$('pseudoStyle').set('html', stls);
		return;
	}
	else if(tag == "a")
		tag = "#sandbox a.linke";
		
	$$(tag).each(function(item){
		item.setStyle(property, val);							
	});
}

function setDefaultStyle(estilo){
	trace(estilo);

	var styleElem = $("defaultStyle");
	if(styleElem.styleSheet)
		styleElem.styleSheet.cssText = estilo;	// IE
	else
		styleElem.set('text', estilo); // Browsers
}


function trace(str){
	$('output').innerHTML += str + '<br>';
}