$().ready(function (){
	
	
   $(".abrevideo").colorbox({iframe:true, innerWidth:425, innerHeight:344});
   $('a.galeria').colorbox();

	
	
        $(function () {
	
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 600,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Iniciar",             // Start text
			stopText: "Parar",               // Stop text
			navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
		});
		
	   
		
	});
	
	if ($("#direita").html()!=null){
				
				// We only want these styles applied when javascript is enabled
			
				$('div.navigation').css({'width' : '300px', 'float' : 'left'});
			
				$('div.content').css('display', 'block');
			
			
			
				// Initially set opacity on thumbs and add
			
				// additional styling for hover effect on thumbs
			
				var onMouseOutOpacity = 0.67;
			
				$('#thumbs ul.thumbs li').opacityrollover({
			
					mouseOutOpacity:   onMouseOutOpacity,
			
					mouseOverOpacity:  1.0,
			
					fadeSpeed:         'fast',
			
					exemptionSelector: '.selected'
			
				});
			
				
			
				// Initialize Advanced Galleriffic Gallery
			
				var gallery = $('#thumbs').galleriffic({
			
					delay:                     1500,
			
					numThumbs:                 6,
			
					preloadAhead:              30,
			
					enableTopPager:            false,
			
					enableBottomPager:         true,
			
					maxPagesToShow:            999,
			
					imageContainerSel:         '#slideshow',
			
					controlsContainerSel:      '#controls',
			
					captionContainerSel:       '#caption',
			
					loadingContainerSel:       '#loading',
			
					renderSSControls:          true,
			
					renderNavControls:         true,
			
					playLinkText:              'Tocar Slideshow',
			
					pauseLinkText:             'Pausar Slideshow',
			
					prevLinkText:              '&lsaquo; Anterior',
			
					nextLinkText:              'Próximo &rsaquo;',
			
					nextPageLinkText:          'Mais &rsaquo;',
			
					prevPageLinkText:          '&lsaquo; Menos',
			
					enableHistory:             true,
			
					autoStart:                 true,
			
					syncTransitions:           false,
			
					defaultTransitionDuration: 300,
			
					onSlideChange:             function(prevIndex, nextIndex) {
			
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
			
						this.find('ul.thumbs').children()
			
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
			
							.eq(nextIndex).fadeTo('fast', 1.0);
			
					},
			
					onPageTransitionOut:       function(callback) {
			
						this.fadeTo('fast', 0.0, callback);
			
					},
			
					onPageTransitionIn:        function() {
			
						this.fadeTo('fast', 1.0);
			
					}
			
				});
			
			
			
				/**** Functions to support integration of galleriffic with the jquery.history plugin ****/
			
			
			
				// PageLoad function
			
				// This function is called when:
			
				// 1. after calling $.historyInit();
			
				// 2. after calling $.historyLoad();
			
				// 3. after pushing "Go Back" button of a browser
			
				function pageload(hash) {
			
					// alert("pageload: " + hash);
			
					// hash doesn't contain the first # character.
			
					if(hash) {
			
						$.galleriffic.gotoImage(hash);
			
					} else {
			
						gallery.gotoIndex(0);
			
					}
			
				}
			
			
			
				// Initialize history plugin.
			
				// The callback is called at once by present location.hash. 
			
				$.historyInit(pageload, "advanced.html");
			
			
			
				// set onlick event for buttons using the jQuery 1.3 live method
			
				$("a[rel='history']").live('click', function(e) {
			
					if (e.button != 0) return true;
			
					
			
					var hash = this.href;
			
					hash = hash.replace(/^.*#/, '');
			
			
			
					// moves to a new page. 
			
					// pageload is called at once. 
			
					// hash don't contain "#", "?"
			
					$.historyLoad(hash);
			
			
			
					return false;
			
				});
	}


});


function formatText(index, panel) {
	  return index + "";
}



function confirma(msg,url){
		jConfirm('Atenção',msg,url);
}
function alerta(msg){
	jAlert('Atenção', msg, '', 450);
}

var jAlert = function(titulo, textoHtml, objetoFoco, largura) {
	if(!largura) { largura = 300; }

	var div = document.createElement('div');
	$(div).addClass('alerta').html(textoHtml).hide().appendTo('body');
	$('div.alerta').dialog({
			title: titulo,
			modal: true,
			width: largura,
			overlay: {backgroundColor:'#777',opacity:'.7'},
			close: function() {
					$('div.alerta').dialog('destroy').remove();
					$(objetoFoco).focus();
			},
			buttons: {
				'OK': function(){ 
					$('div.alerta').dialog('close');
					$(objetoFoco).focus();
				} 
			}
	});
}

var jConfirm = function(titulo, textoHtml, url, largura) {
	if(!largura) { largura = 300; }

	var div = document.createElement('div');
	$(div).addClass('alerta').html(textoHtml).hide().appendTo('body');
	$('div.alerta').dialog({
			title: titulo,
			modal: true,
			width: largura,
			overlay: {backgroundColor:'#777',opacity:'.7'},
			close: function() {
					$('div.alerta').dialog('destroy').remove();
			},
			buttons: {
				
				'Cancelar': function(){ 
					$('div.alerta').dialog('close');
				},
				'OK': function(){ 
					$('div.alerta').dialog('close');
					window.location=url;
				}
				
			}
	});
}
	
validaForm = function (formulario){
	$("form fieldset input").trimFields();
	$("form fieldset textarea").trimFields();
	var form=document.getElementById(formulario);
	var i=0;
	for (i=0;i<form.elements.length;i++){
		if (form.elements[i].title!=""){
			if (form.elements[i].value==""){
				jAlert ('Atenção',form.elements[i].title,form.elements[i]);
				return false;
			}else if (form.elements[i].name=="email"){
					var validacao=/^[a-zA-Z0-9-_.]+@[a-zA-Z0-9-_]+\.([a-zA-Z0-9]{2,4})\.?([a-zA-Z0-9]{2,4})?$/;
					if (!validacao.test(form.elements[i].value)){
						jAlert ('Atenção',"E-mail inválido, por gentileza informe um e-mail válido!",form.elements[i]);
						return false;
					}
			}else if ( (form.elements[i].value=="_____-___") || (form.elements[i].value=="(__) ____-____")  || (form.elements[i].value=="__/__/____") || (form.elements[i].value=="__:__") || (form.elements[i].value=="___.___.___-__") || (form.elements[i].value=="_.___.___") || (form.elements[i].value=="__.___.___/____-__") || (form.elements[i].value=="___.___.___") || (form.elements[i].value=="___-____") ){
				jAlert ('Atenção',form.elements[i].title,form.elements[i]);
				return false;
			
				
			}
			
		}
	}
}


jQuery.fn.trimFields = function(){
  this.each(function(){
   $(this).val( jQuery.trim($(this).val()) );
  });
 }

