/* ### BIBLIOTECA DE CÓDIGOS JAVASCRIPT ###############################################################################################################
function inputVal(obj) - apaga o valor de obj (input) caso este valor seja o padrão. Uso: onFocus="inputVal(this);"
function mostraFlash(src, larg, alt, wmode) - insere uma animação flash na tela, src=local+nome_do_flash.swf, larg/alt=largura/altura em pixel, wmode=transparent se deseja que fique com o fundo transparente
function limpaForm(form) - solicita ao usuario se ele deseja realmente limpar os valores preenchidos do formulário. Uso: onclick="return limpaForm(this.form);"
function highlite(obj,type) - altera o className e ID do objeto passado como parametro e baseado no type. Uso: onmouseover="highlite(this,1);" onmouseout="highlite(this,-1);" onfocus="highlite(this,2);" onblur="highlite(this,-2);"
prototype trim() - remove espaços em branco de uma string, uso: obj.value.trim()
prototype replaceAll(findstr,newstr) - substitue todas ocorrencias de uma string por outra. uso: var result=obj.value.replaceAll('á','a')
function innerTxt(obj) - retorna o mesmo que a funcao javascript innerText, porém este funciona no IE/Mozilla
function addEvent(object,evType,func,useCapture) - cria um event handler para o objeto, funciona no IE/Mozilla, (objeto/evento/funcao/parametros). exemplo: var func=function(){alert("minha funcao");}addEvent(document, "click", func);
function removeEvent=function(o,e,f,s) - remove um evento previamente definido atraves da funcao addEvent(), para remover a função, os parametros passados para esta função devem ser os mesmos daqueles passados em addEvent, Exemplo: removeEvent(document, "click", func);
function saveCookie(cookieName,cookieValue,days) - grava o cookie no computador do usuário.
function readCookie(cookieName) - retorna o valor do cookie (cookieName) salvo no computador do usuário.
function getMousePos(e) - retorna um array de 2 elementos(0 e 1, x e y respectivamente) com as coordenadas do mouse na tela do computador. Uso: document.onmousemove=getMousePos;
function checkEmail(string) - retorna true se a string passada for um email válido, caso contrário, retorna false.
#####################################################################################################################################################*/
function mostraFlash(src, larg, alt, wmode, file){
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ larg +'" height="'+ alt +'">';
	flash += '<param name="movie" value="'+ src +'" />';
	flash += '<param name="file" value="'+ file +'" />';
	flash += '<param name="allowScriptAccess" value="sameDomain" />';
	flash += '<param name="menu" value="false" />';	
	flash += '<param name="wmode" value="'+ wmode +'" />';	
	flash += '<embed src="'+ src +'" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" width="'+ larg +'" height="'+ alt +'" menu = "" wmode = "'+ wmode +'" file="'+file+'"></embed>';
	flash += '</object>';
	document.write(flash);
}

function inputVal(obj){
	if(obj.defaultValue==obj.value){obj.value=''};
}

function limpaForm(form){
	return confirm('Tem certeza de que deseja limpar os valores preenchidos acima?');
}

function highlite(obj,type){  //uso: onmouseover="highlite(this,1);" onmouseout="highlite(this,-1);" onfocus="highlite(this,2);" onblur="highlite(this,-2);"
	if(type==-1){obj.className=obj.className.replace(/inputOver/,'');}
	else if(type==1){obj.className+=' inputOver';}
	else if(type==2){obj.id='inputOver';}
	else{obj.id='';obj.className=obj.className.replace(/inputOver/,'');}
}

function checkEmail(valor){
	if(valor==''){return true;}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){return (true);}
	return (false);
}

/*#####################################################################################################################################################*/
//VARIAVEIS IMPORTANTES
var IE=document.all?true:false;

//FUNCTION PROTOTYPES
String.prototype.trim=function(){  //trim leading or trailing whitespace and extra spaces
	return this.replace(/^\s*/, "").replace(/\s*$/, "").replace(/\s{2,}/, " ");
}

String.prototype.replaceAll=function(findstr,newstr){  //replace all occurences of string
	return this.replace(eval('/'+findstr+'/gi'),newstr);  //case insensitive
}

//OTHER FUNCTIONS
function innerTxt(obj){  //retorna o mesmo que innerText - para IE/Mozilla
	if(!obj){return '';}
	return (obj.innerText)?obj.innerText:obj.textContent;
}

//EXEMPLOS:var func=function(){alert("minha funcao");}addEvent(document, "click", func);
addEvent=function(o,e,f,s){  //adiciona evento ao objeto IE/FF - objeto/evento/funcao/parametros
	var r=o[r="_"+(e="on"+e)]=o[r] || (o[e]?[[o[e],o]]:[]),a,c,d;
	r[r.length]=[f,s || o],o[e]=function(e){
		try{
			(e=e || event).preventDefault || (e.preventDefault=function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation=function(){e.cancelBubble=true;});
			e.target || (e.target=e.srcElement || null);
			e.key=(e.which+1 || e.keyCode+1)-1 || 0;
		}catch(f){}
		for(d=1, f=r.length; f;r[--f] && (a=r[f][0],o=r[f][1],a.call?c=a.call(o,e):(o._=a,c=o._(e),o._=null),d &=c!==false));
		return e=null,!!d;
	}
};

//EXEMPLOS:removeEvent(document, "click", func);
removeEvent=function(o,e,f,s){  //remove evento do objeto IE/FF
	for(var i=(e=o["_on"+e] || []).length;i;)
	if(e[--i] && e[i][0]==f && (s || o)==e[i][1])
	return delete e[i];
	return false;
};

function addEvent(object,evType,func,useCapture){  //attacha um evento a um elemento IE/MOZILLA
	useCapture=true;
	if(object.addEventListener){
		object.addEventListener(evType,func,useCapture);
	}else if(object.attachEvent){
		object.attachEvent("on"+evType,func);
	}
}

function saveCookie(cookieName,cookieValue,days){
	var date=new Date();
	var expires;
	if(days){
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires='EXPIRES='+date.toGMTString()+';';
	}
	if(document.cookie=cookieName+"="+cookieValue+";"+expires+"PATH=/"){
		return true;
	}
	return false;
}

function readCookie(cookieName){
	var cookieString=document.cookie;
	var index1=cookieString.indexOf(cookieName);
	if(index1<0 || cookieName==''){return "";}
	var index2=cookieString.indexOf(';',index1);
	if(index2<0){index2=cookieString.length;}
	return unescape(cookieString.substring(index1+(cookieName.length+1),index2));
}

var mousePos=new Array();
function getMousePos(e){  //pega a posicao do mouse
	if(IE){
		mousePos[0]=event.clientX+document.body.scrollLeft;
		mousePos[1]=event.clientY+document.body.scrollTop;
	}else{
		mousePos[0]=e.pageX;
		mousePos[1]=e.pageY;
	}
	mousePos[0]=Math.max(0,mousePos[0]);
	mousePos[1]=Math.max(0,mousePos[1]);
	return ([mousePos[0],mousePos[1]]);
}


var capa={
	maximized:null,
	time:500,
	
	minimize:function(others){
		$(others).animate({ 
			width: '250px'
		},capa.time).find('img.title').animate({ 
			width: '120px',
			marginLeft: '50px'
		},capa.time);
		$(others).find('img.moldura').animate({ 
			width: '250px',
			top: '55px'
		},capa.time);
		$(others).find('table').animate({ 
			top: '39px',
			left: '17px'
		},capa.time);
		$(others).find('table img').animate({ 
			width: '120px'
		},capa.time);
	},
	
	maximize:function(obj){
		capa.maximized=obj;
		$(obj).animate({ 
			width: '388px'
		},capa.time).find('img.title').animate({ 
			width: '186px',
			marginLeft: '80px'
		},capa.time);
		$(obj).find('img.moldura').animate({ 
			width: '388px',
			top: '85px'
		},capa.time);
		$(obj).find('table').animate({ 
			top: '130px',
			left: '78px'
		},capa.time);
		$(obj).find('table img').animate({ 
			width: '186px'
		},capa.time);
	},
	
	bringToFront:function(obj){
		if(obj==capa.maximized){
			location.href=$(obj).find('a')[0];
		}
		var others=$('.fotoCapa').not(obj);
		capa.minimize(others);
		capa.maximize(obj);
	}
}

function goToDarkness(){
	inDarkness=1;
	$('#secondaryBG').css('background','#000000 url(gfx/BG_body_dark.jpg) top center no-repeat').css('height',screen.height+'px');
}
