/*
 This code was developed at DirectPerformance (www.directperformance.com.br) and is distributed under the Creative Commons - Attribution-NonCommercial 3.0. More details: http://creativecommons.org/licenses/by-nc/3.0/legalcode
 You can freely share, transmit and adapt, but you must attribute the work to the original author information and can not use for commercial purposes.
 Original Author: DirectPerformance - Website: www.directperformance.com.br - E-mail: contato@directperformance.com.br
 */
var dpc_location_pathname = location.pathname;
if (dpc_location_pathname) {
    dpc_location_pathname = dpc_location_pathname.toLowerCase();
}

var s60 = 60;

var aux_url = dpc_location_pathname + location.search;
aux_url.replace("//", "/");
if (aux_url.indexOf("?") == -1) 
    aux_url = aux_url + "?";
else 
    aux_url = aux_url + "&";

var keyHomePage = "BurnBlogHomePage_1=true";
var key60s = "BurnBlogPermaneceu60s_1=true";

function get_cluster(){var a=this.get_cookie("__utmv"),cluster=/^[^.]*\.(.*)/.exec(a);cluster=cluster&&cluster[1]?cluster[1]:'';return cluster}function dpc_read_cookie(a){var b=""+document.cookie;var c=b.indexOf(a);if(c==-1||a==""){return""}var d=b.indexOf(';',c);if(d==-1){d=b.length}return unescape(b.substring(c+a.length+1,d))}function dpc_ga_readcluster_var(a){var b=dpc_read_cookie("__utmv"),re=new RegExp('.*'+a+'=([^|]*).*','g'),cluster_var=re.exec(b);cluster_var=cluster_var&&cluster_var[1]?cluster_var[1]:false;return cluster_var}function dpc_ga_currentsession(){var a;a=dpc_read_cookie("__utma");var b;b=/[^.]*\.[^.]*\.[^.]*\.[^.]*\.([^.]*)\.[^.]*/.exec(a);b=b&&b[1]?b[1]:1;var c=new Date();c.setTime(b*1000);return c}function dpc_cluster_array(a){var b='|';var c='=';var p;p=a;var d;d=dpc_read_cookie('__utmv');d=/^[^\.]*\.(.*)/.exec(d);d=d&&d[1]?d[1]:'';var e=d;var f,itemVar;for(i=0;i<p.length;i+=2){name=p[i];value=p[i+1];if(name!=undefined&&value!=undefined&&name!=""&&value!=""){f=b+name+c;itemVar=f+value;if(e){var g='\\'+b+name+'\\'+c+'([^'+'\\'+b+']*)';g=new RegExp(g,'i');var h=g.exec(e);e=h&&h[1]?e.replace(g,itemVar):e+itemVar}else{e=itemVar}}}if(e){var j;j=String(e).split(b);if(j&&j[1]){for(x=0;x<j.length;x++){for(y=0;y<(j.length-1);y++){if(j[y]>j[y+1]){holder=j[y+1];j[y+1]=j[y];j[y]=holder}}}e=b+j.join(b);e=e.replace(b+b,b)}dpcTracker._setVar(e)}}
 
function dpc_cookie_get(Name) {
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		var offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			var end = document.cookie.indexOf(";", offset);

			if (end == -1) end = document.cookie.length;
			returnvalue = unescape(document.cookie.substring(offset, end));
		}
	}
	return returnvalue;
}

function check_visit_new(){
	var keySession = "dpc_currentsession";
	var currentsession = dpc_ga_currentsession().getTime();
	var cookiesession = dpc_cookie_get(keySession);
	if (currentsession == cookiesession){
		return false;
	}
	dpc_cookie_write("BurnBlogPermaneceu60s_1=false");
	dpc_cookie_write(keySession + "=" + currentsession);
	return true;
}	

function check_duration(){
    if (!dpc_cookie_check(key60s)) {
        var currentsession = dpc_ga_currentsession().getTime();
        var now = (new Date()).getTime();
        var duration = (now - currentsession) / 1000;
		
        if (duration >= s60) {
            jQuery('body').append('<img height="1" width="1" id="permaneceu60s" src="http://view.atdmt.com/action/ccatbn_BurnBlogPermaneceu60s_1" />');
            dpc_pageview(aux_url + key60s);
            dpc_cookie_write(key60s);
            return true;
        }
    }
    return false;
}

function dpc_cookie_check(key) {
	if (typeof document.cookie === "string") {
		var cookie = document.cookie;
		return (cookie.indexOf(key) >= 0);
	}
	return false;
}

function dpc_cookie_write(val) {
	if (typeof document.cookie === "string") {
		document.cookie = val;
	}
}

jQuery(document).ready(function(){
    //busca
    jQuery("input.gsc-search-button:submit").live('click', function(){
        dpc_pageview('/dpc_busca?dpc_q=' + jQuery('input.gsc-input').val());
    });
    //fotos
    jQuery('div.galleryImages a').mousedown(function(){
        dpc_pageview(jQuery(this).attr('href'));
    });
    //twitter follow
    jQuery('#buttonFollow').mousedown(function(){
        dpc_pageview('twitter/' + jQuery(this).text());
    });
    //envia comentario
    jQuery('#commentBts :submit').mousedown(function(){
        if (jQuery.trim(jQuery('#author').val()) !== '' && jQuery.trim(jQuery('#commentText').val()) !== '') {
            dpc_pageview(dpc_location_pathname + location.search + '/comentario-enviado');
        }
    });
    //Addthis
    jQuery('.at_item').live('mousedown', function(){
        dpc_pageview(dpc_location_pathname + location.search + '/addthis/' + jQuery(this).text());
    });
    //navegacao nas fotos
    jQuery('#fancy_left_ico').mousedown(function(){
        dpc_pageview(dpc_location_pathname + location.search + '/photonav/anterior');
    });
    jQuery('#fancy_right_ico').mousedown(function(){
        dpc_pageview(dpc_location_pathname + location.search + '/photonav/proxima');
    });
    
    // ======================
    // TAG de ATLAS
    if (check_visit_new()) {
        jQuery('body').append('<img height="1" width="1" id="visita1" src="http://view.atdmt.com/action/ccatbn_BurnBlogHomePage_1" />');
        dpc_pageview(aux_url + keyHomePage);
    }
		
	if (!check_duration()) {
		// Como ainda nao, liga um timer para 60s
		self.setTimeout("check_duration()", (s60 * 1000));
	}
});//fecha o ready
