var $buoop = {
    vs: { f: 2, o: 9.0, s:2, n:9 , i: 6 }
   ,reminder: 0
   ,l: "de"
   ,newwindow: true
};

$(document).ready(
    function () {
        // Popups
        $("a.popup").colorbox({
            onCleanup: function() {
                // Warenkorb?
                if($(this).hasClass("wako")) {
                    // Reload bring nichts wg. Wordpress Cache
                    // window.location.reload();
                    var cookie_inhalt = $.cookie("bestellung") || "Bestellung";
                    var link_href = "https://www.dtv.de/_warenkorb_hanser/index.cfm?bestellung=" + cookie_inhalt;
                    $("a.warenkorb.popup-wako").attr("href", link_href);
                    initWakoButton(link_href);
                    return false;
                }
                return true;
            }    
        });
        initWakoButton();
        $("a.external").attr("target","_blank");
        // Update your browser
        updateReminder();
        // Hoerproben
        $("a.hoerprobe").colorbox({
            href: $(this).attr("href")
            ,innerHeight: 250
            ,innerWidth: 410 
           ,iframe: true
        });
    }
);

function initWakoButton(href) {
    $("a.popup-wako").unbind("click").colorbox({
        href: href || $(this).attr("href")
       ,innerHeight: 600
       ,innerWidth: 800
       ,iframe: true
    });
}

function updateReminder() {
    if ($buoop.ol) $buoop.ol(); 
    var e = document.createElement("script"); 
    e.setAttribute("type", "text/javascript"); 
    e.setAttribute("src", "http://browser-update.org/update.js"); 
    document.body.appendChild(e); 
}

function hoerpop(flashfile, titel, autor) {
	var pfad = "http://www.hoerverlag.de/hoerprobe.php?isbn="+flashfile+"&titel="+titel+"&autor="+autor;
	// Colorbox
    $.fn.colorbox({
         href: pfad
        ,innerHeight: 250
        ,innerWidth: 410
        ,iframe: true
    });
}

/* Mail decryption */
function decryptThis(s) {
	var n=0;
	var r="mailto:";
	for(var i=0;i<s.length;i++) { 
		n=s.charCodeAt(i); 
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(2)); 
	}
	return r;
}

function doMailto(s) {
	location.href=decryptThis(s);
}
