var activo=1;var last=0; var last_act=0;
var cod='';
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

//painel rotativo das frequencias
var Marquee = function(j,s,w) {
	   var self = this;
	   var jTarget = j;
	   var strText = s;
	   var intWidth = w;
	   var intPaddingLeft = 60;
	   var jText,intTextWidth;
	   var update = function() {
		 intPaddingLeft -= 2;
		 if (intPaddingLeft < -intTextWidth) {
			 intPaddingLeft += intTextWidth;
		 }
	   jText.css({'left':intPaddingLeft + 'px'});
	   };
	   var setup = function() {
		 jText = $('<div class="scrollingtext"></div>').html(strText);
		 jTarget.append(jText);
		 intTextWidth = $(jTarget).find('.scrollingtext').width();
		 jTarget.width(intWidth);
		 jText.text(strText + " " + strText);
		 update();
	   };
	   setup();
	   setInterval(update,30);
	   return self;
};


$(document).ready(function() {   
	
	//show imagens
	
	// edita
	
	$(".edita").hover(function()
	{		
		$(this).parent().css("border","1px dashed red");		
	}).mouseleave(function() {
    	$(this).parent().css("border","1px dashed #dadada");
	});
	
	
	$(".edita").click(function () 
	{			
		var id= $(this).attr('id');
		var area= $(this).attr('area');		
		window.open("/gestor/master.php?frontoffice_area="+area+"&id="+id);
	});
	
	$('.edita').each(function() 
	{
		//$(this).parent().css("position","absolute");
		$(this).parent().css("border","1px dashed #dadada");	
		var tp = $(this).offset();		
		//alert(tp.left);
		//$(this).css({ left: tp.left, top: tp.top, zIndex: '1101' });				
	});	
	

	
	// lingua
	
	$(".lingua_a").click(function () 
	{			
		$.post("/", { modo: "ajax", area: 'lingua', l: $(this).attr('ln') },function(data)
		{			
			window.location = '/';
		});
	});
	$('.overlay, .cmsbox_lg .fechar').click(function(){
		$('.overlay').hide();
		$('.cmsbox_lg').hide();
	})
	
	//hover menu
	var pid='';
	$('.te_menu').hover(function(){
		pid=$(this).attr('id_menu');
		$.post("/index.php", { modo: "ajax", acc: "mostra_menu", pid:pid},function(data)
		{
			if (data != '')
			{
				$('.hv_menu_ct').html(data);	
				$('#menu_'+pid+' .menu_bck').fadeIn();
				$('#mn_menu_'+pid).fadeIn();				
			}
		});	
	}, function(){
		$('#mn_menu_'+pid).hide();
		$('#menu_'+pid+' .menu_bck').hide();
		$('.hv_menu_ct').html('');
		pid=''
	})	
	
	
	//menu desdobravel
	$(".nivel_1").click(function () {		
		var el=$(this).attr('id');	
		var el1="#sec_"+el;
		if (last!=el1)
		{
			$('#sec_'+el).toggle();	
			el3 = $('#sec_'+el).attr('id2');
			
			if( el3 == 'false')
			{	
				var href=$(this).attr('rel');
				document.location=href;
			}
			$(this).addClass("nivel_1_act");
		}
		
		if (last!=0 && last!=el1 ) 
		{		
			$(last).toggle();		
			$(last_act).removeClass("nivel_1_act");
		}			
		last="#sec_"+el;
		last_act=this;
	}); 

	//pasta animaçao
	$(".nome_pasta").hover(function () 
	{			
		$('img', this).animate({ left: 5 },'fast','swing');	

	}, function(){
		$('img', this).animate({ left: 0 }, 'fast','swing');
	});
	
	//pesquisa erro
	$("#pesquisa_form").validate({ 
		rules: { 
			pesquisa_input: {
				required: true,
				minlength: 4
			} 
		},
		messages: {  
			pesquisa_input: "<div class='erro_pesquisa'>*Insira no minimo 4 caracteres</div>"
		}
	}); 

	//auto cad verificaçao
	$('.autocad_file').click(function(){
		fl=$(this).attr('fl')
		$('.overlay1').show();
		$('.cmsbox_ver').show();
		$('#id_validar').attr('fl',fl);
	})
	
	$('#id_validar').click(function(){
		cod=$('#cod_acesso').val();
		fl=$(this).attr('fl');
		if (cod == '')
		{
			$('.cod1').show()
		}
		else{
			$('.cod1').hide()
			$.post("/index.php", { modo: "ajax", acc: "verifica_autocad", cod:cod, fl:fl},function(data)
			{
				if (data != 'false')
				{
					window.location=data;
					$('#id_validar').attr('fl','');
					$('.cmsbox_ver input').val('');
					$('.cmsbox_ver').hide()
					$('.overlay1').hide()
				}
				else{
					$('.cod2').show()
				}
			});
		}
	})
	
	$('.cmsbox_ver .fechar').click(function(){
		$('.cmsbox_ver .validar').attr('fl','');
		$('.cmsbox_ver').hide()
		$('.overlay1').hide()
	})

	if($.browser.msie && $.browser.version<"7.0")
	{
		$(function(){
			
			$("<div>")
				.css({
					'position': 'absolute',
					'top': '0px',
					'left': '0px',
					backgroundColor: 'black',
					'opacity': '0.7',
					'width': '100%',
					'height': $('body').height(),
					zIndex: 5000
				})
				.appendTo("body");
				
			$("<div style='color:#000;background: url(/layout_images/browser.jpg)'><div style='float:left;padding-top:200px;padding-left:150px;'><li><a href='http://www.microsoft.com/windows/internet-explorer/default.aspx' style='color:#000'>Internet Explorer 8<a/></li><li><a href='http://www.mozilla.com/en-US/firefox/ie.html'  style='color:#000'>Firefox<a/></li><li><a href='http://www.google.com/chrome'  style='color:#000'>Chrome<a/></li><li><a href='http://www.apple.com/safari/'  style='color:#000'>Safari<a/></li></span></div></div>")
				.css({
					backgroundColor: 'white',
					'top': '50%',
					'left': '50%',
					marginLeft: -300,
					marginTop: -200,
					width: 579,
					paddingRight: 10,
					paddingLeft: 10,
					paddingTop: 10,
					height: 379,
					'position': 'absolute',
					zIndex: 6000
				})
				.appendTo("body");
		});		
	}

});


	

function replaceText(text){
	while(text.lastIndexOf("&") > 0){
		text = text.replace('&', '[i-Stats]');
	}
	return text;
}

var web_referrer = replaceText(document.referrer);
istat = new Image(1,1);
istat.src = "/counter.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+web_referrer+"&page="+location.href;
//istat.src = "/stats/"+screen.width+","+screen.colorDepth+","+web_referrer+","+location.href;
	function addLoadEvent(func) {	
	  var oldonload = window.onload;	
	  if (typeof window.onload != 'function') {	
	    window.onload = func;	
	  } else {	
	    window.onload = function() {	
	      if (oldonload) {	
	        oldonload();	
	      }	
	      func();	
	    }	
	  }
}	  

