if(document.all && !document.getElementById) {
    document.getElementById = function(id) { return document.all[id]; }
}
function search_get(keywords,searchform) {
    var k = document.getElementById(keywords).value;
    var ws = document.getElementById(searchform);
    location.search = '';
    //location.href = 'http://' + location.hostname + '/cerca/' + encodeURIComponent(k);
    ws.action = 'http://' + location.hostname + '/cerca/' + encodeURIComponent(k);
    ws.submit();
}
function search_blogo_get() {
    k = document.getElementById('searchkeywords').value;
    location.href = 'http://' + location.hostname + '/cerca/' + escape(k); //.replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

var lp_login;
var lp_comments;
var lp_bloglist;

function setUserData() {
    lp_login = $.cookie('lp_login');
    lp_bloglist = $.cookie('lp_bloglist');
    if (lp_login) {
        var username = lp_login.split(",")[0];
        $("div#commentuserfields").empty();
        $("p#registerp").remove();
        $("div#commentuserfields").append("Nickname: " + username.replace(/\+/g," ") + " (<a href=\"/user/profile\">Profilo</a>)");
        $("a#logoutlink").css({display: "block"});
        $("a#loginlink").css({display: "none"});
        $("a#profilelink").css({display: "block"});
        $("a#registerlink").css({display: "none"});
    } else {
        var lp_cookie = $.cookie('lp_identity');
        if (!lp_cookie)
            return;
        var php = new PHP_Serializer(true);
        var lp_identity = php.unserialize(lp_cookie);
        if (!lp_identity)
            return;
        for (var k in lp_identity) {
            var el = document.getElementById(k);
            if (el)
                el.value = decodeURIComponent(lp_identity[k]).replace(/\+/g," ");
        }
    }
}

$(document).ready(function() {
    $("a#loginlink").click(function() {
        if ($("div#headerlogin").css("display") == "none") {
            if ($.browser.safari) {
                $("div#headerlogin").slideDown("slow");
            } else {
                $("div#headerlogin").fadeIn('slow');
            }
        } else {
            $("div#headerlogin").fadeOut("slow");
        }
        return false;
    });
    $("a#newpassword").click(function() {
        $("form#newpasswordform").toggle()
        return false;
    });
    $("a#hideanon").click(function() {
        if ($("li.anoncomment").css("display") == "none") {
            if ($.browser.safari) {
                $("li.anoncomment").slideDown("slow");
            } else {
                $("li.anoncomment").fadeIn("slow");
            }
            $.cookie('lp_comments','', {expires: -1, path: '/'});
            $("a#hideanon").empty();
            $("#numanon").remove();
            $("a#hideanon").append('Nascondi i commenti anonimi');
        } else {
            numcomments = $('.anoncomment').size();
            if (numcomments == 1) {
                comment_phrase = "1 commento anonimo nascosto";
            } else {
                comment_phrase = numcomments + " commenti anonimi nascosti";
            }
            $("li.anoncomment").fadeOut("slow");
            $.cookie('lp_comments','hide', {expires: 30, path: '/'});
            $("a#hideanon").empty();
            $("a#hideanon").append('Mostra i commenti anonimi');
            $("a#hideanon").after("<span id=\"numanon\" style=\"text-transform:lowercase\"> - " + comment_phrase + "</span>");
        }
        return false;
    });
    if ($.cookie('lp_comments') == 'hide') {
        numcomments = $('.anoncomment').size();
        if (numcomments == 1) {
            comment_phrase = "1 commento anonimo nascosto";
        } else {
            comment_phrase = numcomments + " commenti anonimi nascosti";
        }
        $("li.anoncomment").css('display', 'none');
        $("a#hideanon").empty();
        $("a#hideanon").append('Mostra i commenti anonimi');
        $("a#hideanon").after("<span id=\"numanon\"> - " + numcomments + " commenti anonimi nascosti</span>");
    }
    $("a.chiudi-etichetta").bind('click',toggle_bloglist);
    $("a.apri-tab").bind('click',toggle_bloglist);
    setUserData();
    setUpCommentSubmit();
    rate_init();
});


function setUpCommentSubmit() {
    var form = $('#commentform').submit(function (e) {
        var tlen = $('#commentform textarea').val().length;
        var add_input = $("<input>").attr("type", "hidden").attr("name","commentdata").val(tlen);
        $(form).append($(add_input));
    });
}

function toggle_bloglist() {
    //$("div.network-panel").animate({width:'toggle'}, 'fast');
    if ($("div.network-panel div").css("display") == "none") {
        $("div.network-panel div").css('display', 'block');
        $.cookie('lp_bloglist','', {expires: -1, path: '/'});
        return false;
    } else {
        $("div.network-panel div").css('display', 'none');
        $.cookie('lp_bloglist','hide', {expires: 365, path: '/'});
        return false;
    }
}

// Post rating variables
var post_id = 0;
var post_rating = 0;
var ratings_max = 5;
// Comment rating variables
var comment_id = 0;
var rating = 0;
var is_being_rated = false;
var ajax_url = '/ajax/ajax.php';
var site_url = 'http://static.blogo.it/images/stars/';

// Process Ratings
var hover_stars = Array();
function rate_init() {
    $("img.rate-comment").bind('click',submit_rating);
    $("a.s_link").bind('click',submit_rating);
    $("div.post-ratings img").bind('click',submit_rating);
    $("div.post-ratings img").hover(
        function() {
            var rate_img_id = $(this).attr("id").split('-');
            var star_num = rate_img_id[2];
            for (i = 1; i <= star_num; i++) {
                hover_stars[i] = $("img#" + rate_img_id[0] + "-" + rate_img_id[1]+ "-" + i).attr("src");
                $("img#" + rate_img_id[0] + "-" + rate_img_id[1]+ "-" + i).attr("src", site_url + "rating_over.gif");
            }
        },
        function() {
            var rate_img_id = $(this).attr("id").split('-');
            var star_num = rate_img_id[2];
            for (i = 1; i <= star_num; i++)
                $("#" + rate_img_id[0] + "-" + rate_img_id[1]+ "-" + i).attr("src", hover_stars[i]);
        }
    );
}
// Preload img
if (document.images) {
    loading_pic = new Image(16,16);
    loading_pic.src = site_url + "loading.gif";
}

var img_loading = "<img src=\"" + loading_pic.src + "\" width=\"16\" height=\"16\" alt=\"Votazione in corso...\" title=\"Votazione in corso...\" />&nbsp;Votazione in corso...";
var post_rating_content;

function fun_ajax_post(){
    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: ajax_url,
            data: "id="+rate_id+"&rate="+rating+"&action=rp",
            beforeSend: function() {
                post_rating_content = $('#post-ratings-' + rate_id).html();
                $('#post-ratings-' + rate_id).html(img_loading);
            },
            success: function(msg) {
                $('#post-ratings-' + rate_id).html(msg);
            },
            error: function(msg) {
                $('#post-ratings-' + rate_id).html(post_rating_content + msg);
            }
        });
    });
}

function submit_rating(evt) {
    if(!is_being_rated) {
        is_being_rated = true;
        var tmp = evt.target.getAttribute('id');
        var id_split = tmp.split('-');
        var updown = id_split[0];
        rate_id = id_split[1];
        if (updown == 'rcu') {
            what = 'comment';
            rating = 1;
        } else if (updown == 'rcd') {
            what = 'comment';
            rating = -1;
        } else if (updown == 'rtu') {
            what = 'tip';
            rating = 1;
        } else if (updown == 'rp') {
            what = 'post';
            rating = id_split[2];
        } else {
            rating = 0;
        }
        if (!lp_login) {
            pop_login(rate_id, what);
            is_being_rated = false;
            return false;
        }
        if (what == 'comment')
            fun_ajax_comment();
        else if (what == 'post')
            fun_ajax_post();
        else if (what == 'tip')
            fun_ajax_tip();
        is_being_rated = false;
    } else {
        alert('Per favore, vota un solo commento per volta.');
    }
}

function fun_ajax_comment(){
    var karma = 0;
    var karma_msg = '';
    var result = '';
    var vote_error;
    $.ajax({
        type: "GET",
        url: ajax_url,
        data: "id="+rate_id+"&rate="+rating+"&action=rc",
        beforeSend: function() {
            if ($.browser.safari) {
                $("#ckb_" + rate_id).slideUp("fast");
            } else {
                $("#ckb_" + rate_id).fadeOut("fast");
            }
        },
        success: function(msg) {
            if (isNaN(msg))
                vote_error = true;
            else
                vote_error = false;
            if (vote_error) {
                $("#comment-" + rate_id).prepend("<div class=\"error_vote\">Errore - " + msg + "</div>");
            } else {
                karma = parseInt(msg);
                result = msg;
                if (Math.abs(karma) == 1)
                    karma_msg = "punto";
                else
                    karma_msg = "punti";
            }
        },
        complete: function() {
            if (!vote_error) {
                $('#comment_karma_' + rate_id).html(result);
                $('#comment_karma_text_' + rate_id).html(karma_msg);
               // $('#comment-ratings-' + rate_id).fadeOut("fast", $('#comment-ratings-' + rate_id).remove());
               $('#comment-ratings-' + rate_id).fadeOut("fast");
            }
            if ($.browser.safari) {
                $("#ckb_" + rate_id).slideDown("fast");
            } else {
                $("#ckb_" + rate_id).fadeIn("fast");
            }
        },
        error: function() {
            $("#ckb_" + rate_id).css({color:"red"})
        }
    });
}

function fun_ajax_tip(){
    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: ajax_url,
            data: "id="+rate_id+"&rate="+rating+"&action=vt",
            success: function(msg) {
                if (isNaN(msg)) {
                    $("#tip-" + rate_id + " div.s_corpo").prepend("<div class=\"error_vote\">Errore - " + msg + "</div>");
                } else {

                    $('#tip-ratings-' + rate_id).html(msg);
                }
            },
            complete: function() {
                $('#rtu-' + rate_id).fadeOut("fast", $('#rtu-' + rate_id).remove());
            }
        });
    });
}

function pop_login(id, what) {
    if (what == 'post') {
        $("#id" + id + " div.meta").before("<div id=\"pop-login\">Vota anche tu! <a href=\"/user/registration\">Registrati</a> o fai la <a href=\"/user/login\">login</a> <a href=\"javascript:unpop_login()\" id=\"close\"><img src=\"http://static.blogo.it/images/cancel.png\" alt=\"chiudi\" /></a></div>");
    } else if (what == 'comment') {
        $("#comment-" + id + " div.comment_head").prepend("<div id=\"pop-login-comment\">Vota anche tu! <a href=\"/user/registration\">Registrati</a> o fai la <a href=\"/user/login\">login</a> <a href=\"javascript:unpop_login_comment()\" id=\"close\"><img src=\"http://static.blogo.it/images/cancel.png\" alt=\"chiudi\" /></a></p></div>");
    }
}

var open_vids = new Array();
function pop_video(tip_id, embed_code) {
    if (!open_vids[tip_id]) {
        $("#tip-" + tip_id + " span.s_url").prepend("<div class=\"s_video\">" + decodeURIComponent(embed_code) + "</div>");
        open_vids[tip_id] = true;
    } else {
        $("#tip-" + tip_id + " div.s_video").remove();
        open_vids[tip_id] = false;
    }
}

function unpop_login(what) { $("#pop-login").remove(); }

// Process Comment Queue
function queue_comment(id) {
    comment_id = id;
    fun_ajax_comment_queue();
}

function fun_ajax_comment_queue(){
    $(document).ready(function(){
        $.ajax({
            type: "GET",
            url: ajax_url,
            data: "id="+comment_id+"&action=qc",
            success: function(msg){
                $('#comment-' + comment_id).fadeOut("slow", function() {
                        $('#comment-' + comment_id).remove();
                    });
            }

        });
    });
}

function pop_login_comment(comment_id) {
    $("#comment-" + comment_id).append("<div id=\"pop-login-comment\"><div><p>Vota anche tu! <a href=\"/user/registration\">Registrati</a> o fai la <a href=\"/user/login\">login</a> <a href=\"javascript:unpop_login_comment()\" id=\"close\"><img src=\"http://static.blogo.it/images/cancel.png\" alt=\"chiudi\" /></a></p></div>");
}

function unpop_login_comment() { $("#pop-login-comment").remove(); }

function show_comment(comment_id) {
    $('#comment-' + comment_id + "-alt").fadeOut("slow", function() {
        $("#comment-" + comment_id).fadeIn("slow")
    });
}
function hide_comment(comment_id) {
    $('#comment-' + comment_id).fadeOut("slow", function() {
        $("#comment-" + comment_id + "-alt").fadeIn("slow")
    });
}

// Share this - adapted from Alex King's Share this plugin
function akst_share(id, url, title) {
    var form = $("div#akst_form");
    if ($("div#akst_form").css("display") == "block" && post_id.value == id) {
        $("div#akst_form").css("display", "none");
        return;
    }

    var link = $('akst_link_' + id);
    var obj = document.getElementById('akst_link_' + id);
    var offset = findPos(obj);

    $("#akst_badzu").attr("href", akst_share_url("http://www.badzu.net/submit?action=it&link={url}&title={title}", url, title));
    $("#akst_delicious").attr("href", akst_share_url("http://del.icio.us/post?url={url}&title={title}", url, title));
	$("#akst_mailaction").attr("action", url + "#add_comment");
	$("#akst_oknotizie").attr("href", akst_share_url("http://oknotizie.alice.it/post?url={url}&title={title}", url, title));
    $("#akst_segnalo").attr("href", akst_share_url("http://segnalo.alice.it/post.html.php?url={url}&title={title}", url, title));
    $("#akst_digg").attr("href", akst_share_url("http://digg.com/submit?phase=2&url={url}&title={title}", url, title));
    $("#akst_stumble").attr("href", akst_share_url("http://www.stumbleupon.com/submit?url={url}&title={title}", url, title));
    //$("#akst_furl").attr("href", akst_share_url("http://furl.net/storeIt.jsp?u={url}&t={title}", url, title));
    $("#akst_facebook").attr("href", akst_share_url("http://www.facebook.com/sharer.php?u={url}&t={title}", url, title));
    $("#akst_netscape").attr("href", akst_share_url("http://www.netscape.com/submit/?U={url}&T={title}", url, title));
    $("#akst_yahoo_myweb").attr("href", akst_share_url("http://myweb2.search.yahoo.com/myresults/bookmarklet?u={url}&t={title}", url, title));
    $("#akst_google_bmarks").attr("href", akst_share_url("http://www.google.com/bookmarks/mark?op=edit&bkmk={url}&title={title}", url, title));
    $("#akst_reddit").attr("href", akst_share_url("http://reddit.com/submit?url={url}&title={title}", url, title));

    post_id.value = id;

    $("div#akst_form").css({left : (offset[0] + 16) + "px", top : (offset[1] - 150) + "px"});
    $("div#akst_form").css("display", "block");
}

function akst_share_url(base, url, title) {
    base = base.replace('{url}', url);
    return base.replace('{title}', title);
}

function akst_share_tab(tab) {
    var tab1 = document.getElementById('akst_tab1');
    var tab2 = document.getElementById('akst_tab2');
    var body1 = document.getElementById('akst_social');
    var body2 = document.getElementById('akst_email');

    switch (tab) {
        case '1':
            tab2.className = '';
            tab1.className = 'selected';
            body2.style.display = 'none';
            body1.style.display = 'block';
            break;
        case '2':
            tab1.className = '';
            tab2.className = 'selected';
            body1.style.display = 'none';
            body2.style.display = 'block';
            break;
    }
}

function akst_xy(id) {
    var element = $(id);
    var x = 0;
    var y = 0;
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}
//COMMENT ABUSE FUNCTIONS
$(function(){
$('a.comment_alert_send_button').click(function(ob){ob.preventDefault();});
    $('a.comment_alert_send_button').click(function(obj){
        var p=$(obj.target).offset();
        var box=$("div#comment_alert_send_box");
        if(box.css('display')!='none') box.hide();
        box.css({'left':(p.left+80), 'top':p.top, 'position': 'absolute','z-index':1000});
        box.slideDown("fast");
        var search_back=$(obj.target).parent();
        while(!search_back.is("li")){search_back=search_back.parent(); }
        var comment_text=$("div.comment_text p",search_back).text();
        var a=search_back.attr('id').split("-");
        var comment_id=a[1];
        var comment_number=$('.comment_link',$(obj.target).parent()).text().replace("#","");
        $("div#comment_alert_send_box #comment_alert_id").val(comment_id);
        $("div#comment_alert_send_box #comment_alert_number").val(comment_number);
        $("div#comment_alert_send_box #comment_text_alert").val(comment_text);
    });
});

function blogo_skin(image_url,sponsor_url,bg_color, image_url_track){
      var static_path='http://static.blogo.it/';
      var image_base_path=static_path+'sponsor/';
      var track_image='&nbsp;';

      document.write('<l'+'ink type="text/css" rel="stylesheet" href="'+static_path+'c/skin.css" /'+'>');

      $('body').css('background-image','url('+image_base_path+image_url+')');
      if(bg_color)
        $('body').css('background-color',bg_color);

      document.write('<a href="'+sponsor_url+'" target="_blank" id="bglink">Sponsor</a>');

      if(image_url_track)
        track_image='<img src="'+image_url_track+'" height="1" width="1" border="0" >';

      document.write('<a href="'+sponsor_url+'" target="_blank" style="text-align:center"><div id="leaderboard_sponsor" >'+track_image+'</div></a>');

      if($.browser.msie && $.browser.version<7)
        $("#link").hide();

}

/**
 * Object PHP_Serializer
 *  JavaScript to PHP serialize / unserialize class.
 * This class converts php variables to javascript and vice versa.
 * ---------------------------------------------
 * @author              Andrea Giammarchi
 */
function PHP_Serializer(UTF8) {

    /** public methods */
    function serialize(v) {
        // returns serialized var
        var s;
        switch(v) {
            case null:
                s = "N;";
                break;
            default:
                s = this[this.__sc2s(v)] ? this[this.__sc2s(v)](v) : this[this.__sc2s(__o)](v);
                break;
        };
        return s;
    };

    function unserialize(s) {
        // returns unserialized var from a php serialized string
        __c = 0;
        __s = s;
        return this[__s.substr(__c, 1)]();
    };

    function stringBytes(s) {
        // returns the php lenght of a string (chars, not bytes)
        return s.length;
    };

    function stringBytesUTF8(s) {
        // returns the php lenght of a string (bytes, not chars)
        var     c, b = 0,
            l = s.length;
        while(l) {
            c = s.charCodeAt(--l);
            b += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));
        };
        return b;
    };

    /** private methods */
    function __sc2s(v) {
        return v.constructor.toString();
    };

    function __sc2sKonqueror(v) {
        var f;
        switch(typeof(v)) {
            case ("string" || v instanceof String):
                f = "__sString";
                break;
            case ("number" || v instanceof Number):
                f = "__sNumber";
                break;
            case ("boolean" || v instanceof Boolean):
                f = "__sBoolean";
                break;
            case ("function" || v instanceof Function):
                f = "__sFunction";
                break;
            default:
                f = (v instanceof Array) ? "__sArray" : "__sObject";
                break;
        };
        return f;
    };

    function __sNConstructor(c) {
        return (c === "[function]" || c === "(Internal Function)");
    };

    function __sCommonAO(v) {
        var b, n,
            a = 0,
            s = [];
        for(b in v) {
            n = v[b] == null;
            if(n || v[b].constructor != Function) {
                s[a] = [
                    (!isNaN(b) && parseInt(b).toString() === b ? this.__sNumber(b) : this.__sString(b)),
                    (n ? "N;" : this[this.__sc2s(v[b])] ? this[this.__sc2s(v[b])](v[b]) : this[this.__sc2s(__o)](v[b]))
                ].join("");
                ++a;
            };
        };
        return [a, s.join("")];
    };

    function __sBoolean(v) {
        return ["b:", (v ? "1" : "0"), ";"].join("");
    };

    function __sNumber(v) {
        var     s = v.toString();
        return (s.indexOf(".") < 0 ? ["i:", s, ";"] : ["d:", s, ";"]).join("");
    };

    function __sString(v) {
        return ["s:", v.length, ":\"", v, "\";"].join("");
    };

    function __sStringUTF8(v) {
        return ["s:", this.stringBytes(v), ":\"", v, "\";"].join("");
    };

    function __sArray(v) {
        var     s = this.__sCommonAO(v);
        return ["a:", s[0], ":{", s[1], "}"].join("");
    };

    function __sObject(v) {
        var     o = this.__sc2s(v),
            n = o.substr(__n, (o.indexOf("(") - __n)),
            s = this.__sCommonAO(v);
        return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
    };

    function __sObjectIE7(v) {
        var     o = this.__sc2s(v),
            n = o.substr(__n, (o.indexOf("(") - __n)),
            s = this.__sCommonAO(v);
        if(n.charAt(0) === " ")
            n = n.substring(1);
        return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
    };

    function __sObjectKonqueror(v) {
        var o = v.constructor.toString(),
            n = this.__sNConstructor(o) ? "Object" : o.substr(__n, (o.indexOf("(") - __n)),
            s = this.__sCommonAO(v);
        return ["O:", this.stringBytes(n), ":\"", n, "\":", s[0], ":{", s[1], "}"].join("");
    };

    function __sFunction(v) {
        return "";
    };

    function __uCommonAO(tmp) {
        var a, k;
        ++__c;
        a = __s.indexOf(":", ++__c);
        k = parseInt(__s.substr(__c, (a - __c))) + 1;
        __c = a + 2;
        while(--k)
            tmp[this[__s.substr(__c, 1)]()] = this[__s.substr(__c, 1)]();
        return tmp;
    };

    function __uBoolean() {
        var b = __s.substr((__c + 2), 1) === "1" ? true : false;
        __c += 4;
        return b;
    };

    function __uNumber() {
        var sli = __s.indexOf(";", (__c + 1)) - 2,
            n = Number(__s.substr((__c + 2), (sli - __c)));
        __c = sli + 3;
        return n;
    };

    function __uStringUTF8() {
        var     c, sls, sli, vls,
            pos = 0;
        __c += 2;
        sls = __s.substr(__c, (__s.indexOf(":", __c) - __c));
        sli = parseInt(sls);
        vls = sls = __c + sls.length + 2;
        while(sli) {
            c = __s.charCodeAt(vls);
            pos += (c < 128) ? 1 : ((c < 2048) ? 2 : ((c < 65536) ? 3 : 4));
            ++vls;
            if(pos === sli)
                sli = 0;
        };
        pos = (vls - sls);
        __c = sls + pos + 2;
        return __s.substr(sls, pos);
    };

    function __uString() {
        var     sls, sli;
        __c += 2;
        sls = __s.substr(__c, (__s.indexOf(":", __c) - __c));
        sli = parseInt(sls);
        sls = __c + sls.length + 2;
        __c = sls + sli + 2;
        return __s.substr(sls, sli);
    };

    function __uArray() {
        var a = this.__uCommonAO([]);
        ++__c;
        return a;
    };

    function __uObject() {
        var     tmp = ["s", __s.substr(++__c, (__s.indexOf(":", (__c + 3)) - __c))].join(""),
            a = tmp.indexOf("\""),
            l = tmp.length - 2,
            o = tmp.substr((a + 1), (l - a));
        if(eval(["typeof(", o, ") === 'undefined'"].join("")))
            eval(["function ", o, "(){};"].join(""));
        __c += l;
        eval(["tmp = this.__uCommonAO(new ", o, "());"].join(""));
        ++__c;
        return tmp;
    };

    function __uNull() {
        __c += 2;
        return null;
    };

    function __constructorCutLength() {
        function ie7bugCheck(){};
        var o1 = new ie7bugCheck(),
            o2 = new Object(),
            c1 = __sc2s(o1),
            c2 = __sc2s(o2);
        if(c1.charAt(0) !== c2.charAt(0))
            __ie7 = true;
        return (__ie7 || c2.indexOf("(") !== 16) ? 9 : 10;
    };

    /** private variables */
    var     __c = 0,
        __ie7 = false,
        __b = __sNConstructor(__c.constructor.toString()),
        __n = __b ? 9 : __constructorCutLength(),
        __s = "",
        __a = [],
        __o = {},
        __f = function(){};

    /** public prototypes */
    PHP_Serializer.prototype.serialize = serialize;
    PHP_Serializer.prototype.unserialize = unserialize;
    PHP_Serializer.prototype.stringBytes = UTF8 ? stringBytesUTF8 : stringBytes;

    /** serialize: private prototypes */
    if(__b) { // Konqueror / Safari prototypes
        PHP_Serializer.prototype.__sc2s = __sc2sKonqueror;
        PHP_Serializer.prototype.__sNConstructor = __sNConstructor;
        PHP_Serializer.prototype.__sCommonAO = __sCommonAO;
        PHP_Serializer.prototype[__sc2sKonqueror(__b)] = __sBoolean;
        PHP_Serializer.prototype.__sNumber =
        PHP_Serializer.prototype[__sc2sKonqueror(__n)] = __sNumber;
        PHP_Serializer.prototype.__sString = PHP_Serializer.prototype[__sc2sKonqueror(__s)] = UTF8 ? __sStringUTF8 : __sString;
        PHP_Serializer.prototype[__sc2sKonqueror(__a)] = __sArray;
        PHP_Serializer.prototype[__sc2sKonqueror(__o)] = __sObjectKonqueror;
        PHP_Serializer.prototype[__sc2sKonqueror(__f)] = __sFunction;
    }
    else { // FireFox, IE, Opera prototypes
        PHP_Serializer.prototype.__sc2s = __sc2s;
        PHP_Serializer.prototype.__sCommonAO = __sCommonAO;
        PHP_Serializer.prototype[__sc2s(__b)] = __sBoolean;
        PHP_Serializer.prototype.__sNumber =
        PHP_Serializer.prototype[__sc2s(__n)] = __sNumber;
        PHP_Serializer.prototype.__sString = PHP_Serializer.prototype[__sc2s(__s)] = UTF8 ? __sStringUTF8 : __sString;
        PHP_Serializer.prototype[__sc2s(__a)] = __sArray;
        PHP_Serializer.prototype[__sc2s(__o)] = __ie7 ? __sObjectIE7 : __sObject;
        PHP_Serializer.prototype[__sc2s(__f)] = __sFunction;
    };

    /** unserialize: private prototypes */
    PHP_Serializer.prototype.__uCommonAO = __uCommonAO;
    PHP_Serializer.prototype.b = __uBoolean;
    PHP_Serializer.prototype.i =
    PHP_Serializer.prototype.d = __uNumber;
    PHP_Serializer.prototype.s = UTF8 ? __uStringUTF8 : __uString;
    PHP_Serializer.prototype.a = __uArray;
    PHP_Serializer.prototype.O = __uObject;
    PHP_Serializer.prototype.N = __uNull;
};

/**
 *
 *  Base64 encode / decode
 *  http://www.webtoolkit.info/
 *
 */
var Base64 = {

  // private property
  _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

  // public method for encoding
  encode : function (input) {
    var output = "";
    var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
    var i = 0;

    input = Base64._utf8_encode(input);

    while (i < input.length) {

      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
        enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
        enc4 = 64;
      }

      output = output +
      this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
      this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

    }

    return output;
  },

  // public method for decoding
  decode : function (input) {
    var output = "";
    var chr1, chr2, chr3;
    var enc1, enc2, enc3, enc4;
    var i = 0;

    input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

    while (i < input.length) {

      enc1 = this._keyStr.indexOf(input.charAt(i++));
      enc2 = this._keyStr.indexOf(input.charAt(i++));
      enc3 = this._keyStr.indexOf(input.charAt(i++));
      enc4 = this._keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
        output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
        output = output + String.fromCharCode(chr3);
      }

    }

    output = Base64._utf8_decode(output);

    return output;

  },

  // private method for UTF-8 encoding
  _utf8_encode : function (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

      var c = string.charCodeAt(n);

      if (c < 128) {
        utftext += String.fromCharCode(c);
      }
      else if((c > 127) && (c < 2048)) {
        utftext += String.fromCharCode((c >> 6) | 192);
        utftext += String.fromCharCode((c & 63) | 128);
      }
      else {
        utftext += String.fromCharCode((c >> 12) | 224);
        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
        utftext += String.fromCharCode((c & 63) | 128);
      }

    }

    return utftext;
  },

  // private method for UTF-8 decoding
  _utf8_decode : function (utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while ( i < utftext.length ) {

      c = utftext.charCodeAt(i);

      if (c < 128) {
        string += String.fromCharCode(c);
        i++;
      }
      else if((c > 191) && (c < 224)) {
        c2 = utftext.charCodeAt(i+1);
        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
        i += 2;
      }
      else {
        c2 = utftext.charCodeAt(i+1);
        c3 = utftext.charCodeAt(i+2);
        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
        i += 3;
      }

    }

    return string;
  }
}


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();

function extractParamFromUri(uri, paramName) {
  if (!uri) {
    return;
  }
  var uri = uri.split('#')[0];  // Remove anchor.
  var parts = uri.split('?');  // Check for query params.
  if (parts.length == 1) {
    return;
  }
  var query = decodeURI(parts[1]);

  // Find url param.
  paramName += '=';
  var params = query.split('&');
  for (var i = 0, param; param = params[i]; ++i) {
    if (param.indexOf(paramName) === 0) {
      return unescape(param.split('=')[1]);
    }
  }
}


// ROI Tracking
function getVisitorInfo() {
  var roiOptions = {
        localCookieName: 'roi_track',
        localCookieDuration: 0,
        remoteCookieAPI: 'http://app.blogo.it/cookie/index.php',
        remoteCookieName: 'roi_track',
        sourceParameter: 'source',
        keywordParameter: 'q',
        remoteCookieDuration: 0
      },
      visitorInfo = {source: '', keyword: '', paid: false, justLanded: true},
      cookieDomain = document.domain.substring(document.domain.indexOf('.')),
      campaignSource = extractParamFromUri(window.location.href, roiOptions.sourceParameter),
      campaignKeywords = campaignSource ? extractParamFromUri(window.location.href, roiOptions.keywordParameter) : '',
      localCookie = $.cookie(roiOptions.localCookieName);
  if (campaignSource) {
    //console.log("Paid visitor");
    visitorInfo.source = campaignSource;
    visitorInfo.keyword = campaignKeywords;
    visitorInfo.paid = true;
  } else {
    // check cookie
    if (localCookie) {
      var php = new PHP_Serializer(true);
      var cookieInfo = php.unserialize(localCookie);
      visitorInfo.source = cookieInfo.source || '';
      visitorInfo.keyword = cookieInfo.keyword || '';
      visitorInfo.paid = cookieInfo.paid || false;
    }
  }
  if (!localCookie) {
    var php = new PHP_Serializer(true);
    $.cookie(roiOptions.localCookieName, php.serialize(visitorInfo),{path:'/', domain: cookieDomain});
  } else {
    //console.log(localCookie);
    visitorInfo.justLanded = false;
  }
  return visitorInfo;
}

function searchSessionKeywords() {
  var searchKeywords = $.cookie('lp_search_keywords');
  return searchKeywords;
}

var roiTrackingChannels = {
      search: {free: '9851819319', paid: '0908133493'},
      content: {free: '4482300483', paid: '2536128555'}
    },
    visitorInfo = getVisitorInfo();

function getOvtInfo(blogname, paid) {
  var clientId = {free: '0000045', paid: '0000061'}
  var secret = {free: 'blogo', paid: 'blogo2'}
  var siteIdFree = {
        '02blog': 679,
        '06blog': 681,
        'appblog': 682,
        'artsblog': 684,
        'autoblog': 623,
        'automocionblog': 686,
        'autosblog': 687,
        'bebeblog': 689,
        'benessereblog': 690,
        'betsblog': 692,
        'blogapuntate': 693,
        'blogbelavida': 695,
        'blogdolcevita': 697,
        'blogvoip': 699,
        'booksblog': 701,
        'calcioblog': 703,
        'carangoblog': 705,
        'cineblog': 706,
        'cinemaniablog': 707,
        'clickblog': 709,
        'comicsblog': 711,
        'cotilleoblog': 712,
        'criadesignblog': 714,
        'crimeblog': 716,
        'dasmariasblog': 717,
        'deluxeblog': 718,
        'designerblog': 720,
        'downloadblog': 721,
        'ecoblog': 723,
        'ecologiablog': 725,
        'eletronicoblog': 726,
        'eurocarblog': 727,
        'fashionblog': 729,
        'finanzablog': 627,
        'fliperamablog': 631,
        'fofocandoblog': 632,
        'gadgetblog': 633,
        'gamesblog': 635,
        'gossipblog': 637,
        'gustoblog': 639,
        'happyblog': 641,
        'melablog': 643,
        'mobileblog': 644,
        'motoblog': 646,
        'motorsportblog': 647,
        'motosblog': 649,
        'ossblog': 650,
        'outdoorblog': 651,
        'petsblog': 653,
        'pinkblog': 655,
        'queerblog': 626,
        'seriestvblog': 658,
        'softblog': 624,
        'soldiblog': 660,
        'somnacaixablog': 661,
        'soundsblog': 662,
        'strassblog': 664,
        'tecnologiablog': 665,
        'topmusicablog': 667,
        'toysblog': 669,
        'travelblog': 670,
        'tvblog': 672,
        'twowheelsblog': 673,
        'viajandaun': 675,
        'videojuegoblog': 677,
        'yachtandsail': 678
      },
      siteIdPaid = {
        'autoblog': 879,
        'automocionblog': 891,
        'autosblog': 881,
        'bebeblog': 883,
        'benessereblog': 885,
        'deluxeblog': 887,
        'designerblog': 889,
        'eurocarblog': 893,
        'fashionblog': 895,
        'pinkblog': 897,
        'soldiblog': 899,
        'travelblog': 901
      },
      ovtInfo = {client_id: null, site_id: null, secret: null};
  if (paid && siteIdPaid[blogname]) {
    ovtInfo.client_id = clientId['paid'];
    ovtInfo.secret = secret['paid'];
    ovtInfo.site_id = siteIdPaid[blogname];
  } else {
    ovtInfo.client_id = clientId['free'];
    ovtInfo.secret = secret['free'];
    ovtInfo.site_id = siteIdFree[blogname] || 0;
  }
  return ovtInfo;
}

function getAdsenseCodes(blog, country, context, paid) {
  var countryCodeAfcFree = {
        'it_IT': '7632590267',
        'es_ES': '7510946194',
        'en_US': '5493180734',
        'fr_FR': '1033271775',
        'pt_BR': '3733723970'
      },
      countryCodeAfcPaid = {
        'it_IT': '8168553510',
        'es_ES': '2447284723',
        'en_US': '8570089917',
        'fr_FR': '8570089917',
        'pt_BR': '5794917992'
      },
      countryCodeAfsFree = {
        'it_IT': '2454216970',
        'es_ES': '5158436792',
        'en_US': '7635611262',
        'fr_FR': '3460493052',
        'pt_BR': '3868137859'
      },
      countryCodeAfsPaid = {
        'it_IT': '5733425467',
        'es_ES': '4128452330',
        'en_US': '6948242957',
        'fr_FR': '6082505945',
        'pt_BR': '0445838791'
      }
      blogCodeAfcFree = {
        'autoblog': '4650855297',
        'motoblog': '8983385539',
        'tvblog': '1757995103',
        'travelblog': '2101912669',
        'ecoblog': '9898582492',
        'fashionblog': '2831097237',
        'deluxeblog': '1174092992',
        'pinkblog': '0745408683',
        'benessereblog': '8804971351',
        'designerblog': '8752676224',
        'gadgetblog': '8756504740',
        'melablog': '2361497146',
        'mobileblog': '1532837802',
        'soldiblog': '5784051710',
        'calcioblog': '3425069773',
        'clickblog': '1732184105',
        'gustoblog': '6278939335',
        '02blog': '4685479695',
        'toysblog': '0632989763',
        'outdoorblog': '5109749127',
        'soundsblog': '6902161342',
        'comicsblog': '8900918513',
        'blogvoip': '7746132661',
        'appblog': '7055535934',
        '06blog': '4787730198',
        'finanzablog': '3823022929',
        'motorsportblog': '4451100115',
        'booksblog': '4291721197',
        'ossblog': '3738013643',
        'oroscopoblog': '9839583012',
        'englishblog': '6283922071',
        'blogo': '3124754951',
        'bebeblog': '6893540548',
        'cineblog': '6036416398',
        'crimeblog': '2309446930',
        'betsblog': '4537497730',
        'happyblog': '4341401204',
        'polisblog': '7391226793',
        'petsblog': '7472212122',
        'softblog': '3109518752',
        'artsblog': '3313055108',
        'queerblog': '3355327365',
        'downloadblog': '0007008910',
        'blogapuntate': '2514730801',
        'gamesblog': '4702339431',
        'gossipblog': '0433724211'
      },
      blogCodeAfcPaid = {
        'autoblog': '3177529076',
        'motoblog': '8613082918',
        'tvblog': '0783310466',
        'travelblog': '7668934177',
        'ecoblog': '9555889628',
        'fashionblog': '7850496411',
        'deluxeblog': '6232322057',
        'pinkblog': '6616638641',
        'benessereblog': '1017835620',
        'designerblog': '7265185002',
        'gadgetblog': '4742336936',
        'melablog': '8089069886',
        'mobileblog': '7858960517',
        'soldiblog': '9101554799',
        'calcioblog': '0580794774',
        'clickblog': '7520468570',
        'gustoblog': '4489836417',
        '02blog': '7369234040',
        'toysblog': '7970537650',
        'outdoorblog': '4362583623',
        'soundsblog': '4444935347',
        'comicsblog': '2051665338',
        'blogvoip': '2524691531',
        'appblog': '0646206680',
        '06blog': '4935268217',
        'finanzablog': '5124844220',
        'motorsportblog': '0410576337',
        'booksblog': '5753049726',
        'ossblog': '6726572115',
        'oroscopoblog': '1386961726',
        'englishblog': '1218766739',
        'blogo': '4958474292',
        'bebeblog': '8252102503',
        'cineblog': '8749446607',
        'crimeblog': '2999098642',
        'betsblog': '1202654098',
        'happyblog': '7273533208',
        'polisblog': '3030303192',
        'petsblog': '0235160327',
        'softblog': '6912777382',
        'artsblog': '3732722724',
        'queerblog': '9509569151',
        'downloadblog': '5935681454',
        'blogapuntate': '1492720910',
        'gamesblog': '9119608137',
        'gossipblog': '9074850534'
      },
      blogCodeAfsFree = {
        'autoblog': '3870755722',
        'motoblog': '7641443041',
        'tvblog': '3971947999',
        'travelblog': '4325269477',
        'ecoblog': '6098832922',
        'fashionblog': '4193340851',
        'deluxeblog': '8275775460',
        'pinkblog': '0173384881',
        'benessereblog': '6621936553',
        'designerblog': '1099958307',
        'gadgetblog': '1533983792',
        'melablog': '8835939584',
        'mobileblog': '6572586121',
        'soldiblog': '9549018455',
        'calcioblog': '1387347049',
        'clickblog': '8733630919',
        'gustoblog': '8224918192',
        '02blog': '6998919668',
        'toysblog': '4678402935',
        'outdoorblog': '7149953482',
        'soundsblog': '9016154848',
        'comicsblog': '2910965306',
        'blogvoip': '9900050417',
        'appblog': '3472001690',
        '06blog': '8222110657',
        'finanzablog': '0752495921',
        'motorsportblog': '5827105901',
        'booksblog': '9282709123',
        'ossblog': '3482040505',
        'oroscopoblog': '8873763666',
        'englishblog': '9117759165',
        'blogo': '2988116172',
        'bebeblog': '8744156821',
        'cineblog': '9640781167',
        'crimeblog': '3104402752',
        'betsblog': '2055281671',
        'happyblog': '0631639604',
        'polisblog': '2663955927',
        'petsblog': '9879488236',
        'softblog': '2048484368',
        'artsblog': '7854443122',
        'queerblog': '5859817780',
        'downloadblog': '9035786480',
        'blogapuntate': '9663699649',
        'gamesblog': '5150914366',
        'gossipblog': '7118612360'
      },
      blogCodeAfsPaid = {
        'autoblog': '7270213676',
        'motoblog': '4279648412',
        'tvblog': '0661867919',
        'travelblog': '2760307563',
        'ecoblog': '6045258150',
        'fashionblog': '7704856721',
        'deluxeblog': '7025063877',
        'pinkblog': '1121209447',
        'benessereblog': '7254208527',
        'designerblog': '3093098943',
        'gadgetblog': '7224558571',
        'melablog': '9825622550',
        'mobileblog': '9032081987',
        'soldiblog': '0056350355',
        'calcioblog': '2530349331',
        'clickblog': '9131269172',
        'gustoblog': '4455351236',
        '02blog': '6458887304',
        'toysblog': '9942557526',
        'outdoorblog': '8303827594',
        'soundsblog': '4214476222',
        'comicsblog': '5545096195',
        'blogvoip': '7598107619',
        'appblog': '9895641075',
        '06blog': '5361265125',
        'finanzablog': '0674623292',
        'motorsportblog': '1078734302',
        'booksblog': '9794897992',
        'ossblog': '7608154094',
        'oroscopoblog': '9807524889',
        'englishblog': '7704856721',
        'blogo': '8122746230',
        'bebeblog': '2199290527',
        'cineblog': '8834559361',
        'crimeblog': '3454785165',
        'betsblog': '5455644291',
        'happyblog': '8703078382',
        'polisblog': '7777690480',
        'petsblog': '4915717124',
        'softblog': '2307753787',
        'artsblog': '9431826108',
        'queerblog': '0451511458',
        'downloadblog': '8463701200',
        'blogapuntate': '8524347240',
        'gamesblog': '5756180432',
        'gossipblog': '9851897405'
      },
      countryCodes = null, blogCodes = null,
      adsenseChannels = {country: '', blog: ''};
  if (context == 'search') {
    countryCodes = paid ? countryCodeAfsPaid : countryCodeAfsFree;
    blogCodes = paid ? blogCodeAfsPaid : blogCodeAfsFree;
  } else {
    countryCodes = paid ? countryCodeAfcPaid : countryCodeAfcFree;
    blogCodes = paid ? blogCodeAfcPaid : blogCodeAfcFree;
  }
  adsenseChannels.country = countryCodes[country] ? countryCodes[country] : '';
  adsenseChannels.blog = blogCodes[blog] ? blogCodes[blog] : '';
  return adsenseChannels;
}

// Bleah
function setUpPartnerAdServer() {
  var siteCodes = {
      'www.crimeblog.it': 'SAu26wWE-XG3ypWxxQ2dSQ',
      'www.polisblog.it': 'SAu26wWE-XGbDyhP0G_rUw',
      'www.soldiblog.it': 'llRJvxlWo_XDs-KRNDwpDw',
      'www.finanzablog.it': 'llRJvxlWo_VKcLUdtRGbqw',
      'www.travelblog.it': 'EfLSZHJ0cC8i_wokZ9lzDA',
      'www.autoblog.it': 'sd-HLnIYfDXth6UUCp8XDA',
      'www.motoblog.it': 'sd-HLnIYfDW2Wyvt87NKow',
      'www.bebeblog.it': 'BaAntUdzhTDYuiZj26Az9g',
      'www.benessereblog.it': 'BaAntUdzhTABQ1IpciCbcg',
      'www.benessereblog.it': 'BaAntUdzhTDP4Se_M0G6Gw',
      'www.pinkblog.it': 'BaAntUdzhTDP4Se_M0G6Gw',
      'www.fashionblog.it': 'BaAntUdzhTBBw95mIuQEcA',
      'www.queerblog.it': 'BaAntUdzhTDJbu7PXgq-lg',
      'www.deluxeblog.it': 'BaAntUdzhTAz3K1L9oj66w',
      'www.ecoblog.it': 'BaAntUdzhTDkMwSdnGXswA',
      'www.downloadblog.it': 'atsdOTz1HZpNU-Dg0L8kw',
      'www.blogvoip.it': 'aatsdOTz1HZ98godlgPLhg',
      'www.ossblog.it': 'aatsdOTz1HaRmrpUcP06aA',
      'www.gamesblog.it': 'aatsdOTz1HZGowj9Gm4XaQ',
      'www.melablog.it': 'aatsdOTz1HZSOpMyRzkxmA',
      'www.mobileblog.it': 'aatsdOTz1Hbedy2QHw8cAA',
      'www.gadgetblog.it': 'aatsdOTz1HY83aEhw8Djqw',
      'www.clickblog.it': 'aatsdOTz1HbUTuUJO4coLw',
      'www.motorsportblog.it': 'dcnhPwh4QiVmmOfIUE7eJQ',
      'www.outdoorblog.it': 'dcnhPwh4QiVJAk9zl5Rfjg',
      'www.calcioblog.it': 'dcnhPwh4QiUR_jfTwjptpw',
      'blog.yachtandsail.it': 'dcnhPwh4QiWPlA7AvOXK2A',
      'www.betsblog.it': 'dcnhPwh4QiX3DfD1xh7OwA',
      'www.tvblog.it': 'hTUBm7y0FXNfUa2XbCc5Pg',
      'www.gossipblog.it': 'hTUBm7y0FXPRF5rWkgWJrA',
      'www.artsblog.it': 'hTUBm7y0FXOERjal_PYm5w',
      'www.blogapuntate.it': 'hTUBm7y0FXPkyFypp8HLwQ',
      'www.cineblog.it': 'hTUBm7y0FXPXdzsINKneQg',
      'www.soundsblog.it': 'hTUBm7y0FXOq1xHLNKsY2Q',
      'www.softblog.it': 'aatsdOTz1HZpNU-Dg0L8kw',
      'www.06blog.it': '3pnAY6iz9T0MhZJ315vsJA',
      'www.booksblog.it': '3pnAY6iz9T3ud6PuicvkiQ',
      'www.comicsblog.it': '3pnAY6iz9T1KM0TZLBZVww',
      'www.designerblog.it': '3pnAY6iz9T0-EzGoiVyWIw',
      'www.gustoblog.it': '3pnAY6iz9T2mmwHezApynQ',
      'www.happyblog.it': '3pnAY6iz9T31tyCus21fRw',
      'www.petsblog.it': '3pnAY6iz9T1falZ6-DiXdA',
      'www.toysblog.it': '3pnAY6iz9T3OxjYLFv7luw',
      'www.02blog.it': '3pnAY6iz9T1z_BXctw0CnQ',
      'www.fofocandoblog.com': 'itg_kY-amx5LbB5RrgNXtw',
      'www.cotilleoblog.com': 'RrnIJPVjygpS1Fv8WlFOYg',
      'www.ecologiablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.automocionblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.videojuegoblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.cinemaniablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.seriestvblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.topmusicablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.automovelblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.eletronicoblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.criadesignblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.viajandoblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.blogbelavida.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.dasmariasblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.somnacaixablog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.fliperamablog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.pipocablog.com': 'ntgtEg5vRa5EVX4LY0vb1A'
    },
    siteCode = siteCodes[window.location.hostname] ? siteCodes[window.location.hostname] : null;
  if (siteCode) {
    var cookieDomain = document.domain.substring(document.domain.indexOf('.')),
        localCookie = $.cookie('lp_organic'),
        refVisitor = document.referrer ? true : false;
    if (refVisitor || localCookie) {
      var src = 'http://partneradserver.com/ta/xcid,' + siteCode + '==?w=1&h=1';
      document.write('<s'+'cr'+'ipt type="text/javascript" src="'+src+'">'+'</s'+'cri'+'pt>');
    }
    if (localCookie == null) {
      var lp_organic = refVisitor ? 0 : 1;
      $.cookie('lp_organic', lp_organic, {path: '/', domain: cookieDomain});
    }
  }
}


function getAdServerUrl() {
  var siteCodes = {
      'www.crimeblog.it': 'SAu26wWE-XG3ypWxxQ2dSQ',
      'www.polisblog.it': 'SAu26wWE-XGbDyhP0G_rUw',
      'www.soldiblog.it': 'llRJvxlWo_XDs-KRNDwpDw',
      'www.finanzablog.it': 'llRJvxlWo_VKcLUdtRGbqw',
      'www.travelblog.it': 'EfLSZHJ0cC8i_wokZ9lzDA',
      'www.autoblog.it': 'sd-HLnIYfDXth6UUCp8XDA',
      'www.motoblog.it': 'sd-HLnIYfDW2Wyvt87NKow',
      'www.bebeblog.it': 'BaAntUdzhTDYuiZj26Az9g',
      'www.benessereblog.it': 'BaAntUdzhTABQ1IpciCbcg',
      'www.benessereblog.it': 'BaAntUdzhTDP4Se_M0G6Gw',
      'www.pinkblog.it': 'BaAntUdzhTDP4Se_M0G6Gw',
      'www.fashionblog.it': 'BaAntUdzhTBBw95mIuQEcA',
      'www.queerblog.it': 'BaAntUdzhTDJbu7PXgq-lg',
      'www.deluxeblog.it': 'BaAntUdzhTAz3K1L9oj66w',
      'www.ecoblog.it': 'BaAntUdzhTDkMwSdnGXswA',
      'www.downloadblog.it': 'atsdOTz1HZpNU-Dg0L8kw',
      'www.blogvoip.it': 'aatsdOTz1HZ98godlgPLhg',
      'www.ossblog.it': 'aatsdOTz1HaRmrpUcP06aA',
      'www.gamesblog.it': 'aatsdOTz1HZGowj9Gm4XaQ',
      'www.melablog.it': 'aatsdOTz1HZSOpMyRzkxmA',
      'www.mobileblog.it': 'aatsdOTz1Hbedy2QHw8cAA',
      'www.gadgetblog.it': 'aatsdOTz1HY83aEhw8Djqw',
      'www.clickblog.it': 'aatsdOTz1HbUTuUJO4coLw',
      'www.motorsportblog.it': 'dcnhPwh4QiVmmOfIUE7eJQ',
      'www.outdoorblog.it': 'dcnhPwh4QiVJAk9zl5Rfjg',
      'www.calcioblog.it': 'dcnhPwh4QiUR_jfTwjptpw',
      'blog.yachtandsail.it': 'dcnhPwh4QiWPlA7AvOXK2A',
      'www.betsblog.it': 'dcnhPwh4QiX3DfD1xh7OwA',
      'www.tvblog.it': 'hTUBm7y0FXNfUa2XbCc5Pg',
      'www.gossipblog.it': 'hTUBm7y0FXPRF5rWkgWJrA',
      'www.artsblog.it': 'hTUBm7y0FXOERjal_PYm5w',
      'www.blogapuntate.it': 'hTUBm7y0FXPkyFypp8HLwQ',
      'www.cineblog.it': 'hTUBm7y0FXPXdzsINKneQg',
      'www.soundsblog.it': 'hTUBm7y0FXOq1xHLNKsY2Q',
      'www.softblog.it': 'aatsdOTz1HZpNU-Dg0L8kw',
      'www.06blog.it': '3pnAY6iz9T0MhZJ315vsJA',
      'www.booksblog.it': '3pnAY6iz9T3ud6PuicvkiQ',
      'www.comicsblog.it': '3pnAY6iz9T1KM0TZLBZVww',
      'www.designerblog.it': '3pnAY6iz9T0-EzGoiVyWIw',
      'www.gustoblog.it': '3pnAY6iz9T2mmwHezApynQ',
      'www.happyblog.it': '3pnAY6iz9T31tyCus21fRw',
      'www.petsblog.it': '3pnAY6iz9T1falZ6-DiXdA',
      'www.toysblog.it': '3pnAY6iz9T3OxjYLFv7luw',
      'www.02blog.it': '3pnAY6iz9T1z_BXctw0CnQ',
      'www.fofocandoblog.com': 'itg_kY-amx5LbB5RrgNXtw',
      'www.cotilleoblog.com': 'RrnIJPVjygpS1Fv8WlFOYg',
      'www.ecologiablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.automocionblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.videojuegoblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.cinemaniablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.seriestvblog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.topmusicablog.com': 'KpG5zZ3mDEfSb7Kk4ykoGA',
      'www.automovelblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.eletronicoblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.criadesignblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.viajandoblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.blogbelavida.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.dasmariasblog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.somnacaixablog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.fliperamablog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.pipocablog.com': 'ntgtEg5vRa5EVX4LY0vb1A',
      'www.eurocarblog.com': 'n0CilEBRzmKiU93U_PFI9Q',
      'www.twowheelsblog.com': 'n0CilEBRzmKiU93U_PFI9Q=',
      'www.blogdolcevita.com': 'n0CilEBRzmKiU93U_PFI9Q=',
      'www.autosblog.fr': 'a8Exb4Px97HSGin7R-tsZw',
      'www.motosblog.fr': 'a8Exb4Px97HSGin7R-tsZw',
      'www.ladyblog.fr': 'a8Exb4Px97HSGin7R-tsZw',
      'www.strassblog.fr': 'a8Exb4Px97HSGin7R-tsZw',
      'www.sommelierblog.fr': 'a8Exb4Px97HSGin7R-tsZw'
    },
    base_prefix = 'trace',
    base_domain = '.com',
    siteCode = siteCodes[window.location.hostname] ? siteCodes[window.location.hostname] : null,
    src = '';
  if (siteCode) {
    var cookieDomain = document.domain.substring(document.domain.indexOf('.')),
        localCookie = $.cookie('lp_organic'),
        refVisitor = document.referrer ? true : false;
    if (refVisitor || localCookie) {
      var src = 'http://' + base_prefix + 'admanager' + base_domain + '/ta/xcid,' + siteCode + '==?w=1&h=1';
    }
    if (localCookie == null) {
      var lp_organic = refVisitor ? 0 : 1;
      $.cookie('lp_organic', lp_organic, {path: '/', domain: cookieDomain});
    }
  }
  return src;
}

