// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function wordWrap(){
	/******
	* wordWrap to firefox for big words
	* Creative Commons license * Version: 1.0 - 26/04/2006
	* Autor: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
	* Uso: call the function on onload of body element.
	* put the class "word-wrap" on elements to wordwrap
	*******/
	    var larg_total,larg_carac,quant_quebra,pos_quebra;
	    var elementos,quem, caracs, texto, display_orig;

	    elementos = document.getElementsByTagName("p")

	    for(var i=0; i<elementos.length;i++){
	        if(elementos[i].className=="word-wrap"){
	            quem = elementos[i];

	            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
	            texto = String(quem.innerHTML)

	            quem.innerHTML = " "

	            display_orig = quem.style.display;
	            quem.style.display="block";
	            larg_oficial = quem.offsetWidth;
	            //alert("oficial: " + larg_oficial)
	            //alert("display " + quem.style.display)
	            if(!document.all) quem.style.display="table";
	            //alert("display " + quem.style.display)
	            quem.innerHTML = texto;
	            larg_total = quem.offsetWidth;
	            //alert("total: " + larg_total)

	            pos_quebra = 0;
	            caracs = texto.length;
	            texto = texto.replace(/Ø/g," ")
	            larg_carac = larg_total / caracs
	            if(larg_total>larg_oficial){
	                quant_quebra = parseInt(larg_oficial/larg_carac)
	                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
	                quem.innerHTML = ""
	                while(pos_quebra<=caracs){
	                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
	                    pos_quebra = pos_quebra + quant_quebra;
	                }
	            }else{
	                quem.innerHTML = texto;
	            }//end if do larg_total>larg_oficial
	            quem.style.display = display_orig;
	        }//end if do word wrap
	    }//end for loop dos elementos
	}

	function hideFlashMessages() {
		
		$('flash_alert').setStyle({
		  display: 'none'
		});
		
		fixCols();
		
	}

function setMenuJS_old(){
	//<script defer='defer'>flashMenu({id:'menus_<%= menu[:label] %>',largura:'80',sufix:'.'})</script>

	
}

function setMenuJS(){
	//	console.log("START")
		//activateMENUS('menunav',0,flashMenu);
		picturesAbout()
}




function picturesAbout(){
	
	var intID = $('aboutPictures');
	
		if(intID){
			intuls = intID.getElementsByTagName('li');
		
			
			for(i=0;i<intuls.length;i++){
				Event.observe(intuls[i].childNodes[0], 'click', function(event) { changePicture(this) });
				intuls[i].childNodes[0].onclick = function() { return false; }
			}
		}
	
	
}



function changePicture(e){
	$('pictureAbout').fade({ duration: 0.5,afterFinish: function() { appearPicture(e)}   });	
}

function appearPicture(e){
	$('title_gallery').innerHTML = e.getAttribute('title')
	$('pictureAbout').src = e.getAttribute('href',2)
	$('pictureAbout').appear({ duration: 1.0 });
}


function activateMENUS (id,nivelChild,func) {

	var intID = $(id);
	
		if(intID){
			intuls = intID.getElementsByTagName('li');
		
			for(i=0;i<intuls.length;i++){
				
				if(intuls[i].childNodes[nivelChild].className != 'undefineds'){	
					
					j =intuls[i].getAttribute('id').split("_")
					idM = 'menus_'+j[1]
					flashMenu({id:idM,largura:'90',sufix:'.'})
				}
			}
		}
	
}



function flashMenu(params){
	
	if(!params['largura']){
		params['largura'] = 100
	}
	
	if(!params['font-size']){
		params['font-size'] = 18
	}
	
	params['altura'] = 25
	
	if(!params['fontface']){
		params['fontface'] = 'yellowoodfont';
	}
	
	//document.write('<![CDATA[');
	
	 //<![CDATA[
		
		//alert('/flash/'+params['fontface']+'.swf')
		//http://s3.yellowoodstore.com.s3.amazonaws.com
        var so = new SWFObject('/flash/'+params['fontface']+'.swf', 'fm', params['largura'], params['altura'], '7', '#CCCCCC');
        so.addParam('menu', 'false');   
        so.addParam('wmode', 'transparent');   
		so.addParam('scale', 'noscale'); 
		
		so.addVariable('fora', '1');
		
		/*
		if( params['sufix'] ) {
			var textx = $(params['id']).getAttribute('rel') + params['sufix']
		}else{
			var textx = $(params['id']).getAttribute('rel')
		}
		*/
		
		
		
		//j = $(params['id']).getAttribute('id').split("_")
		//var textx = j[1]
		
			if(params['id']){
				
				mHTML = $(params['id']).innerHTML;
				mText = mHTML.replace(/<[^>]*>/g,"")
			
			}else if(params['class']){
				console.log(params['class'])
			}
			
			
			so.addVariable('texto', mText);
			
			//console.log(mText)
	
		
		//so.addVariable('texto','tone');
		//alert($(params['id']).firstChild.text)
		
		if(params['whocontent']){
		
		}else{
			
		
			if($(params['id']).firstChild.tagName == 'A'){
				so.addVariable('cor', '0xFFFFFF');
				so.addVariable('corH', '0xFED000');
				so.addVariable('link', '/'+ mText);
				//$(params['id']).getAttribute('rel'));
			}else{
				so.addVariable('cor', '0xFED000');
			}
		
		
		}
		
		so.addVariable('largura', params['largura']);
		so.addVariable('tamanhof', params['font-size']);
		
        so.write(params['id']);

		
		//return false;
    
	//document.write(']]>');
	
	
	
}



	function helloFlash(){
		
		//$('idflash').firstChild.attributes[0].nodeValue = '../images/assets/00'+slide+".jpg"
		//console.log('../images/assets/'+slide+".jpg");
		//alert($('idflash').firstChild.attributes[0].nodeValue)
		if(slide > 4){
			slide=1
		}else{	
			slide++;
		}
	}

function checkpasswords(){
	if ( ( $('password_confirmation').value != $('password').value )   ||  $('password').value == ''  ) {
		alert('please, fill the password in the two fields')
		return false;
	}else{
		$('formPASS').submit();
	}
}


function getViewPort(){
	
	<!--

	 var viewportwidth;
	 var viewportheight;

	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }

	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }

	 // older versions of IE

	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	var rval = {
        width: viewportwidth,
        height: viewportheight
    };

    return rval;

	
	
}

function fixCols(menus){
	
	// FIX PARA IE ERROR
	document.body.appendChild(document.createElement('div'))

	$('nav').setStyle({
	  height: $('content').getHeight()+'px'
	});
	
	
	$('logo_yw').setStyle({
	  height: $('content').getHeight()-190+'px'
	});
	
	
	wDim = getViewPort();
	
	
	dif = wDim.height - $('master').getHeight()
	
	
	aplly = $('footer').getHeight() + dif;
	
	if(aplly < 0){
		aplly = 200;
	}
	
	
	$('footer').setStyle({
	  height: aplly + 'px'
	});
	
	if(menus == 1){
		setMenuJS();
	}
	
}


window.onload = function(){
	/*$('body').setStyle({
	  backgroundImage: 'url(../images/assets/fundos/42.jpg)'
	});
	console.log($('body'))*/
	if($('corSel0')){
		$('corSel0').click();
	}
	
	if($('pageACt')){
		Effect.ScrollTo('head2');
	}
	
	fixCols(1);	
}


/*
document.observe("dom:loaded", function() {
	fixCols();	
});*/