

//Cookies
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


//funçoes
function fechar(){$.colorbox.close();}
function login(){$.colorbox({transition:"none", speed:250, opacity:0.8, overlayClose:false,iframe:true ,width:500, height:250, href:'login.php'});}

/*function showtab(){
var shwtab = document.getElementById('Vtabs'); shwtab.style.display = 'block';//desactiva tabs em caso de JS desligado
}
window.onload=showtab; 
*/






//JQUERY
$(document).ready(function() { //inicio doc GERAL



			$('#slides').slides({
				preload: true,
				preloadImage: 'css/imag/loader.gif',
				play: 5500,
				pause: 6000,
				hoverPause: false,
				pagination: false
			});


	//SEPARADORES
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		
		var $elem = $('#mainP');
		 $('html, body').animate({scrollTop: $elem.height()},1);//sroll ate os separadores
		
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});




//PESQUISA
	
	$('#loading').hide();
	$('#buscar').click(function(){
		$('#buscar').val('');
	});

	$('#buscar').keyup(function(){
		$('#sep').hide();
		$('#map_canvas').hide();
		$('.caixaImag').hide();
		$('.caixaTumb').hide();
		$('#pro').addClass('active');
		$('#hom, #emp, #con').removeClass();
		
		$('#loading').ajaxStart(function(){
			$('#loading').show();	
		});
		$('#loading').ajaxStop(function(){
			$('#loading').hide();	
		});
		$.post('motor_lista.php', {s: $('#buscar').val()},
		function(data){
			if ($('#buscar').val()!=''){
				$('#contlista').show();
				$('#contlista').empty().html(data);
			}
			else{
				$('#contlista').empty();
		
				$('#contlista').load('nop.php');
			}
		}
		);
	});
	
	
	//desactiva o enter
	  textboxes = $("#buscar");

   if ($.browser.mozilla) {
      $(textboxes).keypress(checkForEnter);
   } else {
      $(textboxes).keydown(checkForEnter);
   }

   function checkForEnter(event) {
      if (event.keyCode == 13) {
         currentTextboxNumber = textboxes.index(this);

         if (textboxes[currentTextboxNumber + 1] != null) {
           nextTextbox = textboxes[currentTextboxNumber + 1];
           nextTextbox.select();
      }

         event.preventDefault();
         return false;
      }
   }




			//ColorBox
			//$("a[rel='imag']").colorbox({transition:"fade", speed:250, opacity:0.8,close:"x" });
			$("a[rel='admin']").colorbox({transition:"none", speed:250, opacity:0.8, overlayClose:false,iframe:true ,width:550, height:450});
			$("a[rel='admin_x']").colorbox({transition:"none", speed:250, opacity:0.8, overlayClose:false,iframe:true ,width:550, height:650});
			$("a[rel='admin_m']").colorbox({transition:"none", speed:250, opacity:0.8, overlayClose:false,iframe:true ,width:800, height:620});
			


/*//ORDEM
$(function() {
		$(".caixaTumb ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
			var order = $(this).sortable("serialize") + '&action=updateRecordsListings'; 
			$.post("ordem.php", order, function(theResponse){
				//$("#contentRight").html(theResponse);
			}); 															 
		}								  
		});
	});
*/



}); //final load doc GERAL


