//	SCROLL
function scroll(obj,offset){
	if(location.pathname.replace(/^\//,'')==obj.pathname.replace(/^\//,'') && location.hostname==obj.hostname)
	{
	var jQuerytarget=jQuery(obj.hash);
	jQuerytarget=jQuerytarget.length&&jQuerytarget||jQuery('[name='+obj.hash.slice(1)+']');
	if(jQuerytarget.length)
		{
		var targetOffset=jQuerytarget.offset().top+offset;
		jQuery('html,body').stop().animate({scrollTop:targetOffset},500,'swing');
		return false;
		}
	}
}


//	EXIBE CONTATO
var contact_show=false;
function contact(obj){
	jQuery('#contact').slideToggle(500);
	if(!contact_show)
	{
		scroll(obj,0);
		setTimeout(function(){jQuery('#name').focus();},500);
	}
contact_show=!contact_show;
}


//	LIGHTBOX
var $l = jQuery.noConflict()

$l(function() {
	$l('a[@rel*=lightbox]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.5,
		imageLoading: 'http://www.somnio.com.br/images/lightbox/loading.gif',
		imageBtnClose: 'http://www.somnio.com.br/images/lightbox/close.gif',
		imageBtnPrev: 'http://www.somnio.com.br/images/lightbox/prev.gif',
		imageBtnNext: 'http://www.somnio.com.br/images/lightbox/next.gif',
		txtImage: 'Imagem',
		txtOf: 'de'
   });
});


//	FADE
var $j = jQuery.noConflict()

$j(document).ready(function(){
$j(".work_frame img").fadeTo("slow", 0.5); 

$j(".work_frame img").hover(function(){
$j(this).fadeTo("fast", 1.0); 
},function(){
$j(this).fadeTo("fast", 0.5); 
});
});    


//	ACCORDION
jQuery().ready(function()
{
	jQuery('#sanfona').accordion();
	var accordions = jQuery('#sanfona');
});


//	VALIDA FORMULÁRIO
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- Verifique o email.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' precisa conter um numero.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' precisa ser um n&uacute;mero entre '+min+' e '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- O campo '+nm+' deve ser preenchido.\n'; }
    } if (errors) alert('Orreram os seguintes erros:\n'+errors);
    document.MM_returnValue = (errors == '');
} }