/* funcoes gerais */
$(document).ready(function() {
    $('.rounded').corners("10px");
    $(".round").corner("20px bottom");
    $(".roundbr").corner("20px br");
    $(".roundbl").corner("20px bl");
	
	
	$('.rounded a').parent().addClass('bolinhas');
	
	
});

function multi(linha) {
    li      = '.lithumb'+linha;
    grande  = '.grd'+linha;
    txt  = '.txtg'+linha;
    $(li).siblings().removeClass('activo');
    $('.txtg').addClass('hideimp');
    $(txt).removeClass('hideimp');
    $(li).addClass('activo');
    $(grande).fadeOut("slow");
    //$(grande).siblings().addClass('hide');
    $(grande).fadeIn("slow");
    //$(grande).removeClass('hide');
    $(grande).siblings().fadeOut('fast');
}

function expande(linha) {
    tr = '.tr'+linha;
    if ( $(tr).hasClass('hide') ) {
        $('.detalhes').addClass('hide');
        $(tr).toggleClass('hide');
    } else {
        $(tr).toggleClass('hide');
    }
}

function galeria(big,tiny) {
    $('.big').addClass('hideimp');
    $(big).removeClass('hideimp');
    $('.tiny').removeClass('activo');
    $(tiny).addClass('activo');
}

$(function() {
    $('#spotlight').spotlight({ displayTime: 3, transition: ['fadeIn', 'slow'] });
});

/* spotlight */
(function($){$.fn.spotlight=function(options){if(this.length&&(spotlight=$.data(this[0],"spotlight"))){return spotlight;}return this.each(function(){$.data(this,"spotlight",new $.spotlight.init(this,options));});};$.spotlight={defaults:{featureItems:".spotlight_item",itemContent:".featured_content",feature:".spotlight_feature",featuredClass:"activo",displayTime:3,autoReStart:true,transition:null},init:function(element,settings){var self=this;this.settings=$.extend({},$.spotlight.defaults,settings);this.features=$(element).find(this.settings.featureItems);this.featureContainer=$(element).find(this.settings.feature);if(this.settings.transition){if(typeof this.settings.transition=="object"){this.settings.transitionSpeed=this.settings.transition[1];this.settings.transition=this.settings.transition[0];}this.transitionContainer=this.featureContainer.clone().css({position:"absolute",top:0,left:0,margin:0,border:0,overflow:"hidden"}).hide();}this.features.each(function(idx){var featured=$(this);featured.data("idx",idx);featured.data("featured",featured.find(self.settings.itemContent).remove().html());}).hover(function(){self.show($(this).data("idx"));},function(){self.restart();});this.featureContainer.hover(function(){self.stop();},function(){self.restart();});this.show(0);this.start();}};$.extend($.spotlight.init.prototype,{currentIdx:0,showing:null,running:false,interval:null,show:function(idx){this.stop();if(this.showing){this.showing.removeClass(this.settings.featuredClass);}this.showing=this.features.eq(idx);this.currentIdx=idx;this.showing.addClass(this.settings.featuredClass);if(this.featureContainer){if(this.transitionContainer){this.transitionTo(this.showing.data("featured"));}else{this.featureContainer.html(this.showing.data("featured"));}}},start:function(){var self=this;this.running=true;this.interval=setTimeout(function(){self.next(true);},this.settings.displayTime*1000);},stop:function(){this.running=false;clearTimeout(this.interval);},restart:function(){if(this.settings.autoReStart){this.start();}},next:function(override){if(this.running||override){var idx=this.currentIdx+1;if(idx>=this.features.size()){idx=0;}this.show(idx);if(this.running||override){this.start();}}},transitionTo:function(html){var self=this;this.transitionContainer.hide().html(html).appendTo(this.featureContainer);this.transitionContainer[this.settings.transition](this.settings.transitionSpeed,function(){self.featureContainer.html(html);});}});})(jQuery);

/* ------------------------PRINT PREVIEW------------------------ */ 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent( function(){ add_print_link( 'nav' ) } );

function add_print_link( id ){
  if( !document.getElementById ||
      !document.getElementById( id ) ) return;

  // add extra functions to page tools list
  var print_page = document.getElementById( id );

  // create print link
  var print_function = document.createElement('p');
  print_function.className = 'print-link';
  print_function.onclick = function(){ print_preview(); return false; };
  print_function.appendChild( document.createTextNode( 'Print the Page' ) );

}

function print_preview() {
    //popupWin = window.open('<?=$_SERVER["REQUEST_URI"]?>', 'open_window', 'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0');
    // Switch the stylesheet
    setActiveStyleSheet('Print Preview');
    // Create preview message
    add_preview_message();
    // Print the page
    window.print();
}

function add_preview_message(){
var main_content = document.getElementById('contentbg');
var main_body = main_content.parentNode;

	if (document.getElementById){
		
		var preview_message = document.createElement('div');
		preview_message.id = 'preview-message';
	
		// Create Heading
		var preview_header = document.createElement('h3');
		var preview_header_text = document.createTextNode('');
		preview_header.appendChild(preview_header_text);
		
		// Create paragraph
		var preview_para = document.createElement('p');
		var preview_para_text = document.createTextNode('');
		
		var cancel_function_link = document.createElement('a');
			cancel_function_link.onclick = function(){ cancel_print_preview(); return false; };
			cancel_function_link.setAttribute('href', '#');	
		var cancel_function_link_text = document.createTextNode('Voltar ao site');
		cancel_function_link.appendChild(cancel_function_link_text);
		preview_para.appendChild(preview_para_text); //
		preview_para.appendChild(cancel_function_link);
		
		// Put it all toegether
		preview_message.appendChild(preview_header); 
		preview_message.appendChild(preview_para);
		main_body.insertBefore(preview_message, main_content);

	}
}

function cancel_print_preview() {
	// Destroy the preview message
	var print_preview = document.getElementById('preview-message');
	var main_body = print_preview.parentNode;
	main_body.removeChild(print_preview);
	
	// Switch back stylesheet
	setActiveStyleSheet('default');
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}
/* ------------------------FIM PRINT PREVIEW------------------------ */
function addFormFieldpt() {
    var id = document.getElementById("id").value;
    $("#divTxt").append("<p class='linha' id='row" + id + "'><label for='txt" + id + "'>Destinatário " + id + ":<\/label> <input type='text' size='20' name='txt[]' class='destinatario' id='txt" + id + "'> <span class='edicao'><\/span><\/p>");
    $('#row' + id).highlightFade({ speed:1000 });

    $('#txt' + (id-1)).addClass("readonly");
    $('#txt' + (id-1)).attr("readonly",true);
    $('#row' + (id-1) + ' span.edicao').replaceWith("<span class='edicao'><a href='#' class='editar' onClick='toggleReadonly("+(id-1)+"); return false;'>editar<\/a> <a href='#' onClick='removeFormField(\"#row" + (id-1) + "\"); return false;'>remover<\/a><\/span>");

    id = (id - 1) + 2;
    document.getElementById("id").value = id;
}
function addFormFielden() {
    var id = document.getElementById("id").value;
    $("#divTxt").append("<p class='linha' id='row" + id + "'><label for='txt" + id + "'>Receiver " + id + ":<\/label> <input type='text' size='20' name='txt[]' class='destinatario' id='txt" + id + "'> <span class='edicao'><\/span><\/p>");
    $('#row' + id).highlightFade({ speed:1000 });

    $('#txt' + (id-1)).addClass("readonly");
    $('#txt' + (id-1)).attr("readonly",true);
    $('#row' + (id-1) + ' span.edicao').replaceWith("<span class='edicao'><a href='#' class='editar' onClick='toggleReadonly("+(id-1)+"); return false;'>edit<\/a> <a href='#' onClick='removeFormField(\"#row" + (id-1) + "\"); return false;'>remove<\/a><\/span>");

    id = (id - 1) + 2;
    document.getElementById("id").value = id;
}
function removeFormField(id) { jQuery(id).remove(); }
function toggleReadonly(id) {
    if ($('#txt' + id).attr("readonly") == true) {
        $('#txt' + id).removeAttr("readonly"); 
        $('#txt' + id).removeClass("readonly"); 
    } else {
        $('#txt' + id).addClass("readonly"); 
        $('#txt' + id).attr("readonly",true); 
    }
}
/* highlight */
jQuery.fn.highlightFade=function(settings){var o=(settings&&settings.constructor==String)?{start:settings}:settings||{};var d=jQuery.highlightFade.defaults;var i=o.interval||d.interval;var a=o.attr||d.attr;var ts={linear:function(s,e,t,c){return parseInt(s+(c/t)*(e-s));},sinusoidal:function(s,e,t,c){return parseInt(s+Math.sin(((c/t)*90)*(Math.PI/180))*(e-s));},exponential:function(s,e,t,c){return parseInt(s+(Math.pow(c/t,2))*(e-s));}};var t=(o.iterator&&o.iterator.constructor==Function)?o.iterator:ts[o.iterator]||ts[d.iterator]||ts.linear;if(d.iterator&&d.iterator.constructor==Function){t=d.iterator;}return this.each(function(){if(!this.highlighting){this.highlighting={};}var e=(this.highlighting[a])?this.highlighting[a].end:jQuery.highlightFade.getBaseValue(this,a)||[255,255,255];var c=jQuery.highlightFade.getRGB(o.start||o.colour||o.color||d.start||[255,255,128]);var s=jQuery.speed(o.speed||d.speed);var r=o["final"]||(this.highlighting[a]&&this.highlighting[a].orig)?this.highlighting[a].orig:jQuery.curCSS(this,a);if(o.end||d.end){r=jQuery.highlightFade.asRGBString(e=jQuery.highlightFade.getRGB(o.end||d.end));}if(typeof o["final"]!="undefined"){r=o["final"];}if(this.highlighting[a]&&this.highlighting[a].timer){window.clearInterval(this.highlighting[a].timer);}this.highlighting[a]={steps:((s.duration)/i),interval:i,currentStep:0,start:c,end:e,orig:r,attr:a};jQuery.highlightFade(this,a,o.complete,t);});};jQuery.highlightFade=function(e,a,o,t){e.highlighting[a].timer=window.setInterval(function(){var newR=t(e.highlighting[a].start[0],e.highlighting[a].end[0],e.highlighting[a].steps,e.highlighting[a].currentStep);var newG=t(e.highlighting[a].start[1],e.highlighting[a].end[1],e.highlighting[a].steps,e.highlighting[a].currentStep);var newB=t(e.highlighting[a].start[2],e.highlighting[a].end[2],e.highlighting[a].steps,e.highlighting[a].currentStep);jQuery(e).css(a,jQuery.highlightFade.asRGBString([newR,newG,newB]));if(e.highlighting[a].currentStep++>=e.highlighting[a].steps){jQuery(e).css(a,e.highlighting[a].orig||"");window.clearInterval(e.highlighting[a].timer);e.highlighting[a]=null;if(o&&o.constructor==Function){o.call(e);}}},e.highlighting[a].interval);};jQuery.highlightFade.defaults={start:[255,255,128],interval:50,speed:400,attr:"backgroundColor"};jQuery.highlightFade.getRGB=function(c,d){var result;if(c&&c.constructor==Array&&c.length==3){return c;}if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c)){return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];}else{if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c)){return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];}else{if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c)){return[parseInt("0x"+result[1]),parseInt("0x"+result[2]),parseInt("0x"+result[3])];}else{if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c)){return[parseInt("0x"+result[1]+result[1]),parseInt("0x"+result[2]+result[2]),parseInt("0x"+result[3]+result[3])];}else{return jQuery.highlightFade.checkColorName(c)||d||null;}}}}};jQuery.highlightFade.asRGBString=function(a){return"rgb("+a.join(",")+")";};jQuery.highlightFade.getBaseValue=function(e,a,b){var s,t;b=b||false;t=a=a||jQuery.highlightFade.defaults.attr;do{s=jQuery(e).css(t||"backgroundColor");if((s!=""&&s!="transparent")||(e.tagName.toLowerCase()=="body")||(!b&&e.highlighting&&e.highlighting[a]&&e.highlighting[a].end)){break;}t=false;}while(e=e.parentNode);if(!b&&e.highlighting&&e.highlighting[a]&&e.highlighting[a].end){s=e.highlighting[a].end;}if(s==undefined||s==""||s=="transparent"){s=[255,255,255];}return jQuery.highlightFade.getRGB(s);};jQuery.highlightFade.checkColorName=function(c){if(!c){return null;}switch(c.replace(/^\s*|\s*$/g,"").toLowerCase()){case"aqua":return[0,255,255];case"black":return[0,0,0];case"blue":return[0,0,255];case"fuchsia":return[255,0,255];case"gray":return[128,128,128];case"green":return[0,128,0];case"lime":return[0,255,0];case"maroon":return[128,0,0];case"navy":return[0,0,128];case"olive":return[128,128,0];case"purple":return[128,0,128];case"red":return[255,0,0];case"silver":return[192,192,192];case"teal":return[0,128,128];case"white":return[255,255,255];case"yellow":return[255,255,0];}};


/* fontsize */
var min=10;var max=18;function aumentarTamanho(){
    var c=document.getElementById("contentbg");
    if(c.style.fontSize){
        var s=parseInt(c.style.fontSize.replace("px",""));
    }else{
        var s=13;
    }
    if(s<max){
        s+=2;
    }else{
        if(s>=max){s=min;s+=2;}
    }
    c.style.fontSize=s+"px";
}

