var activo=1;var last=0; var last_act=0;

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;
};


$(document).ready(function() {   

	$('#bt_print').click(function ()
	{			
		win = window.open();
		self.focus();
		win.document.open();
		win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
		win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
		win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
		win.document.write($('.titulo_corpo').text()+"<br><br>");
		win.document.write($('.texto_corpo').text());
		win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
		win.document.close();
		win.print();
		win.close();		
	});

	//comentarios
	$(".clike_img").click(function () 
	{			
		el=$(this).attr('id');				
		if ($.cookie(el)!="like")
		{		
			$.post("/", { modo: "ajax", acc: "like", id: el },function(data)
			{
					$("#cl_"+el).html(data);	
					$("#like_"+el).show();
			});	
			$.cookie(el, 'like', { expires: 10 });			
		}		
	});
	
	$("#submete_comentario").click(function () 
	{	
		
		$.post("/", { modo: "ajax", acc: "salva_comment", dados: $(this).parent().serialize() },function(data)
		{
					
					
		});			
		
	});
	

	$(".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;
	});  
		
	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");
	});		
	}

	
		//slidshow _ destaques
		$(".foto_d .desc").show();
			$(".foto_d .block").animate({ opacity: 0.85 }, 1 );	
			$('.texto_d ul li:first').addClass('active');
			$('.texto_d ul li:last').addClass('last');
			$('.texto_d ul li').click(function(){
				var imgAlt = $(this).find('img').attr('alt'); 
				var imgTitle = $(this).find('a').attr('href');
				var imgID = $(this).find('img').attr('id'); 
				var imgDesc = $(this).find('.block').html(); 
				var imgDescHeight = $('.foto_d').find('.block').height(); 
				if ($(this).is('.active')) { 
				return false;
				} else {
					$(".foto_d img").animate({ opacity: 0}, 250 );
					$(".foto_d .block").animate({ opacity: 0, marginBottom: -imgDescHeight, padding:10, width: 656 }, 250 , function() {
					$(".foto_d .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250 );
					$(".foto_d a img").attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 250 );
					$(".foto_d a").attr({ href: imgID});
					});
				}
			$('.texto_d ul li').removeClass('active'); 
			$(this).addClass('active');
			return false;
				}) .hover(function(){
				$(this).addClass('hover');
				}, function() {
				$(this).removeClass('hover');
				});
			pauseClickNext = false;
			$('.foto_d').hover(
			function () {
			pauseClickNext = true;
			},
			function () {
			pauseClickNext = false;
			}
			);
			var clickNext = function(){
				if(!pauseClickNext) {
				/// find the next li after .active
				var $next_li = $('li.active').next('li');
				if($('li.active').hasClass('last') ){
				$('.texto_d ul li:first').trigger('click');
				} else {
				$next_li.trigger('click');
				}
				}
			};
			setInterval(clickNext, 10000);
});
	

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 = "http://www.insignare.pt/counter.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+web_referrer+"&page="+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();	
	    }	
	  }
}	  
