/*
 * jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz
 *
 * http://www.heise.de/extras/socialshareprivacy/
 * http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html
 *
 * Copyright (c) 2011 Hilko Holweg, Sebastian Hilbig, Nicolas Heiringhoff, Juergen Schmidt,
 * Heise Zeitschriften Verlag GmbH & Co. KG, http://www.heise.de
 *
 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php
 *
 * Spread the word, link to us if you can.
 */
(function ($) {

    "use strict";

	/*
	 * helper functions
	 */ 

    // abbreviate at last blank before length and add "\u2026" (horizontal ellipsis)
    function abbreviateText(text, length) {
        var abbreviated = decodeURIComponent(text);
        if (abbreviated.length <= length) {
            return text;
        }

        var lastWhitespaceIndex = abbreviated.substring(0, length - 1).lastIndexOf(' ');
        abbreviated = encodeURIComponent(abbreviated.substring(0, lastWhitespaceIndex)) + "\u2026";

        return abbreviated;
    }

    // returns content of <meta name="" content=""> tags or '' if empty/non existant
    function getMeta(name) {
        var metaContent = $('meta[name="' + name + '"]').attr('content');
        return metaContent || '';
    }
    
    // create tweet text from content of <meta name="DC.title"> and <meta name="DC.creator">
    // fallback to content of <title> tag
    function getTweetText() {
        var title = getMeta('DC.title');
        var creator = getMeta('DC.creator');

        if (title.length > 0 && creator.length > 0) {
            title += ' - ' + creator;
        } else {
            title = $('title').text();
        }

        return encodeURIComponent(title);
    }

    // build URI from rel="canonical" or document.location
    function getURI() {
        var uri = document.location.href;
        var canonical = $("link[rel=canonical]").attr("href");

        if (canonical && canonical.length > 0) {
            if (canonical.indexOf("http") < 0) {
                canonical = document.location.protocol + "//" + document.location.host + canonical;
            }
            uri = canonical;
        }

        return uri;
    }

    function cookieSet(name, value, days, path, domain) {
        var expires = new Date();
        expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
        document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain;
    }
    function cookieDel(name, value, path, domain) {
        var expires = new Date();
        expires.setTime(expires.getTime() - 100);
        document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain;
    }

    // extend jquery with our plugin function
    $.fn.socialSharePrivacy = function (settings) {
        var defaults = {
            'services' : {
                'facebook' : {
                    'status'            : 'on',
                    'dummy_img'         : 'socialshareprivacy/images/dummy_facebook.png',
                    'txt_info'          : '2 Klicks f&uuml;r mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie k&ouml;nnen Ihre Empfehlung an Facebook senden. Schon beim Aktivieren werden Daten an Dritte &uuml;bertragen &ndash; siehe <em>i</em>.',
                    'txt_fb_off'        : 'nicht mit Facebook verbunden',
                    'txt_fb_on'         : 'mit Facebook verbunden',
                    'perma_option'      : 'on',
                    'display_name'      : 'Facebook',
                    'referrer_track'    : '',
                    'language'          : 'de_DE',
                    'action'            : 'recommend'
                }, 
                'twitter' : {
                    'status'            : 'on', 
                    'dummy_img'         : 'socialshareprivacy/images/dummy_twitter.png',
                    'txt_info'          : '2 Klicks f&uuml;r mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie k&ouml;nnen Ihre Empfehlung an Twitter senden. Schon beim Aktivieren werden Daten an Dritte &uuml;bertragen &ndash; siehe <em>i</em>.',
                    'txt_twitter_off'   : 'nicht mit Twitter verbunden',
                    'txt_twitter_on'    : 'mit Twitter verbunden',
                    'perma_option'      : 'on',
                    'display_name'      : 'Twitter',
                    'referrer_track'    : '', 
                    'tweet_text'        : getTweetText,
                    'language'          : 'en'
                },
                'gplus' : {
                    'status'            : 'on',
                    'dummy_img'         : 'socialshareprivacy/images/dummy_gplus.png',
                    'txt_info'          : '2 Klicks f&uuml;r mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie k&ouml;nnen Ihre Empfehlung an Google+ senden. Schon beim Aktivieren werden Daten an Dritte &uuml;bertragen &ndash; siehe <em>i</em>.',
                    'txt_gplus_off'     : 'nicht mit Google+ verbunden',
                    'txt_gplus_on'      : 'mit Google+ verbunden',
                    'perma_option'      : 'on',
                    'display_name'      : 'Google+',
                    'referrer_track'    : '',
                    'language'          : 'de'
                }
            },
            'info_link'         : 'http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html',
            'txt_help'          : 'Wenn Sie diese Felder durch einen Klick aktivieren, werden Informationen an Facebook, Twitter oder Google in die USA &uuml;bertragen und unter Umst&auml;nden auch dort gespeichert. N&auml;heres erfahren Sie durch einen Klick auf das <em>i</em>.',
            'settings_perma'    : 'Dauerhaft aktivieren und Daten&uuml;ber&shy;tragung zustimmen:',
            'cookie_path'       : '/',
            'cookie_domain'     : document.location.host,
            'cookie_expires'    : '365',
            'css_path'          : 'socialshareprivacy/socialshareprivacy.css',
            'uri'               : getURI
        };

        // Standardwerte des Plug-Ings mit den vom User angegebenen Optionen ueberschreiben
        var options = $.extend(true, defaults, settings);

        var facebook_on = (options.services.facebook.status === 'on');
        var twitter_on  = (options.services.twitter.status  === 'on');
        var gplus_on    = (options.services.gplus.status    === 'on');

        // check if at least one service is "on"
        if (!facebook_on && !twitter_on && !gplus_on) {
            return;
        }

        // insert stylesheet into document and prepend target element
        if (options.css_path.length > 0) {
            $('head').append('<link rel="stylesheet" type="text/css" href="' + options.css_path + '" />');
        }
        $(this).prepend('<ul class="social_share_privacy_area"></ul>');
        var context = $('.social_share_privacy_area', this);

        // canonical uri that will be shared
        var uri = options.uri;
        if (typeof uri === 'function') {
            uri = uri();
        }

        return this.each(function () {

            //
            // Facebook
            //
            if (facebook_on) {
                var fb_enc_uri = encodeURIComponent(uri + options.services.facebook.referrer_track);
                var fb_code = '<iframe src="http://www.facebook.com/plugins/like.php?locale=' + options.services.facebook.language + '&amp;href=' + fb_enc_uri + '&amp;send=false&amp;layout=button_count&amp;width=120&amp;show_faces=false&amp;action=' + options.services.facebook.action + '&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:145px; height:21px;" allowTransparency="true"></iframe>';
                var fb_dummy_btn = '<img src="' + options.services.facebook.dummy_img + '" alt="Facebook &quot;Like&quot;-Dummy" class="fb_like_privacy_dummy" />';

                context.append('<li class="facebook help_info"><span class="info">' + options.services.facebook.txt_info + '</span><span class="switch off">' + options.services.facebook.txt_fb_off + '</span><div class="fb_like dummy_btn">' + fb_dummy_btn + '</div></li>');

                var $container_fb = $('li.facebook', context);

                $('li.facebook div.fb_like img.fb_like_privacy_dummy,li.facebook span.switch', context).live('click', function () {
                    if ($container_fb.find('span.switch').hasClass('off')) {
                        $container_fb.addClass('info_off');
                        $container_fb.find('span.switch').addClass('on').removeClass('off').html(options.services.facebook.txt_fb_on);
                        $container_fb.find('img.fb_like_privacy_dummy').replaceWith(fb_code);
                    } else {
                        $container_fb.removeClass('info_off');
                        $container_fb.find('span.switch').addClass('off').removeClass('on').html(options.services.facebook.txt_fb_off);
                        $container_fb.find('.fb_like').html(fb_dummy_btn);
                    }
                });
            }

            //
            // Twitter
            //
            if (twitter_on) {
                var text = options.services.twitter.tweet_text;
                if (typeof text === 'function') {
                    text = text();
                }
                // 120 is the max character count left after twitters automatic url shortening with t.co
                text = abbreviateText(text, '120');

                var twitter_enc_uri = encodeURIComponent(uri + options.services.twitter.referrer_track);
                var twitter_count_url = encodeURIComponent(uri);
                var twitter_code = '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url=' + twitter_enc_uri + '&amp;counturl=' + twitter_count_url + '&amp;text=' + text + '&amp;count=horizontal&amp;lang=' + options.services.twitter.language + '" style="width:130px; height:25px;"></iframe>';
                var twitter_dummy_btn = '<img src="' + options.services.twitter.dummy_img + '" alt="&quot;Tweet this&quot;-Dummy" class="tweet_this_dummy" />';

                context.append('<li class="twitter help_info"><span class="info">' + options.services.twitter.txt_info + '</span><span class="switch off">' + options.services.twitter.txt_twitter_off + '</span><div class="tweet dummy_btn">' + twitter_dummy_btn + '</div></li>');

                var $container_tw = $('li.twitter', context);

                $('li.twitter div.tweet img,li.twitter span.switch', context).live('click', function () {
                    if ($container_tw.find('span.switch').hasClass('off')) {
                        $container_tw.addClass('info_off');
                        $container_tw.find('span.switch').addClass('on').removeClass('off').html(options.services.twitter.txt_twitter_on);
                        $container_tw.find('img.tweet_this_dummy').replaceWith(twitter_code);
                    } else {
                        $container_tw.removeClass('info_off');
                        $container_tw.find('span.switch').addClass('off').removeClass('on').html(options.services.twitter.txt_twitter_off);
                        $container_tw.find('.tweet').html(twitter_dummy_btn);
                    }
                });
            }

            //
            // Google+
            //
            if (gplus_on) {
                // fuer G+ wird die URL nicht encoded, da das zu einem Fehler fuehrt
                var gplus_uri = uri + options.services.gplus.referrer_track;
                
                // we use the Google+ "asynchronous" code, standard code is flaky if inserted into dom after load
                var gplus_code = '<div class="g-plusone" data-size="medium" data-href="' + gplus_uri + '"></div><script type="text/javascript">window.___gcfg = {lang: "' + options.services.gplus.language + '"}; (function() { var po = document.createElement("script"); po.type = "text/javascript"; po.async = true; po.src = "https://apis.google.com/js/plusone.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s); })(); </script>';
                var gplus_dummy_btn = '<img src="' + options.services.gplus.dummy_img + '" alt="&quot;Google+1&quot;-Dummy" class="gplus_one_dummy" />';

                context.append('<li class="gplus help_info"><span class="info">' + options.services.gplus.txt_info + '</span><span class="switch off">' + options.services.gplus.txt_gplus_off + '</span><div class="gplusone dummy_btn">' + gplus_dummy_btn + '</div></li>');

                var $container_gplus = $('li.gplus', context);

                $('li.gplus div.gplusone img,li.gplus span.switch', context).live('click', function () {
                    if ($container_gplus.find('span.switch').hasClass('off')) {
                        $container_gplus.addClass('info_off');
                        $container_gplus.find('span.switch').addClass('on').removeClass('off').html(options.services.gplus.txt_gplus_on);
                        $container_gplus.find('img.gplus_one_dummy').replaceWith(gplus_code);
                    } else {
                        $container_gplus.removeClass('info_off');
                        $container_gplus.find('span.switch').addClass('off').removeClass('on').html(options.services.gplus.txt_gplus_off);
                        $container_gplus.find('.gplusone').html(gplus_dummy_btn);
                    }
                });
            }

            //
            // Der Info/Settings-Bereich wird eingebunden
            //
            context.append('<li class="settings_info"><div class="settings_info_menu off perma_option_off"><a href="' + options.info_link + '"><span class="help_info icon"><span class="info">' + options.txt_help + '</span></span></a></div></li>');

            // Info-Overlays mit leichter Verzoegerung einblenden
            $('.help_info:not(.info_off)', context).live('mouseenter', function () {
                var $info_wrapper = $(this);
                var timeout_id = window.setTimeout(function () { $($info_wrapper).addClass('display'); }, 500);
                $(this).data('timeout_id', timeout_id);
            });
            $('.help_info', context).live('mouseleave', function () {
                var timeout_id = $(this).data('timeout_id');
                window.clearTimeout(timeout_id);
                if ($(this).hasClass('display')) {
                    $(this).removeClass('display');
                }
            });

            var facebook_perma = (options.services.facebook.perma_option === 'on');
            var twitter_perma  = (options.services.twitter.perma_option  === 'on');
            var gplus_perma    = (options.services.gplus.perma_option    === 'on');

            // Menue zum dauerhaften Einblenden der aktiven Dienste via Cookie einbinden
            // Die IE7 wird hier ausgenommen, da er kein JSON kann und die Cookies hier ueber JSON-Struktur abgebildet werden
            if (((facebook_on && facebook_perma)
                || (twitter_on && twitter_perma)
                || (gplus_on && gplus_perma))
                    && (!$.browser.msie || ($.browser.msie && $.browser.version > 7.0))) {

                // Cookies abrufen
                var cookie_list = document.cookie.split(';');
                var cookies = '{';
                var i = 0;
                for (; i < cookie_list.length; i += 1) {
                    var foo = cookie_list[i].split('=');
                    cookies += '"' + $.trim(foo[0]) + '":"' + $.trim(foo[1]) + '"';
                    if (i < cookie_list.length - 1) {
                        cookies += ',';
                    }
                }
                cookies += '}';
                cookies = JSON.parse(cookies);

                // Container definieren
                var $container_settings_info = $('li.settings_info', context);

                // Klasse entfernen, die das i-Icon alleine formatiert, da Perma-Optionen eingeblendet werden
                $container_settings_info.find('.settings_info_menu').removeClass('perma_option_off');

                // Perma-Optionen-Icon (.settings) und Formular (noch versteckt) einbinden
                $container_settings_info.find('.settings_info_menu').append('<span class="settings">Einstellungen</span><form><fieldset><legend>' + options.settings_perma + '</legend></fieldset></form>');


                // Die Dienste mit <input> und <label>, sowie checked-Status laut Cookie, schreiben
                var checked = ' checked="checked"';
                if (facebook_on && facebook_perma) {
                    var perma_status_facebook = cookies.socialSharePrivacy_facebook === 'perma_on' ? checked : '';
                    $container_settings_info.find('form fieldset').append(
                        '<input type="checkbox" name="perma_status_facebook" id="perma_status_facebook"'
                            + perma_status_facebook + ' /><label for="perma_status_facebook">'
                            + options.services.facebook.display_name + '</label>'
                    );
                }

                if (twitter_on && twitter_perma) {
                    var perma_status_twitter = cookies.socialSharePrivacy_twitter === 'perma_on' ? checked : '';
                    $container_settings_info.find('form fieldset').append(
                        '<input type="checkbox" name="perma_status_twitter" id="perma_status_twitter"'
                            + perma_status_twitter + ' /><label for="perma_status_twitter">'
                            + options.services.twitter.display_name + '</label>'
                    );
                }

                if (gplus_on && gplus_perma) {
                    var perma_status_gplus = cookies.socialSharePrivacy_gplus === 'perma_on' ? checked : '';
                    $container_settings_info.find('form fieldset').append(
                        '<input type="checkbox" name="perma_status_gplus" id="perma_status_gplus"'
                            + perma_status_gplus + ' /><label for="perma_status_gplus">'
                            + options.services.gplus.display_name + '</label>'
                    );
                }

                // Cursor auf Pointer setzen fuer das Zahnrad
                $container_settings_info.find('span.settings').css('cursor', 'pointer');

                // Einstellungs-Menue bei mouseover ein-/ausblenden
                $($container_settings_info.find('span.settings'), context).live('mouseenter', function () {
                    var timeout_id = window.setTimeout(function () { $container_settings_info.find('.settings_info_menu').removeClass('off').addClass('on'); }, 500);
                    $(this).data('timeout_id', timeout_id);
                }); 
                $($container_settings_info, context).live('mouseleave', function () {
                    var timeout_id = $(this).data('timeout_id');
                    window.clearTimeout(timeout_id);
                    $container_settings_info.find('.settings_info_menu').removeClass('on').addClass('off');
                });

                // Klick-Interaktion auf <input> um Dienste dauerhaft ein- oder auszuschalten (Cookie wird gesetzt oder geloescht)
                $($container_settings_info.find('fieldset input')).live('click', function (event) {
                    var click = event.target.id;
                    var service = click.substr(click.lastIndexOf('_') + 1, click.length);
                    var cookie_name = 'socialSharePrivacy_' + service;

                    if ($('#' + event.target.id + ':checked').length) {
                        cookieSet(cookie_name, 'perma_on', options.cookie_expires, options.cookie_path, options.cookie_domain);
                        $('form fieldset label[for=' + click + ']', context).addClass('checked');
                    } else {
                        cookieDel(cookie_name, 'perma_on', options.cookie_path, options.cookie_domain);
                        $('form fieldset label[for=' + click + ']', context).removeClass('checked');
                    }
                });

                // Dienste automatisch einbinden, wenn entsprechendes Cookie vorhanden ist
                if (facebook_on && facebook_perma && cookies.socialSharePrivacy_facebook === 'perma_on') {
                    $('li.facebook span.switch', context).click();
                }
                if (twitter_on && twitter_perma && cookies.socialSharePrivacy_twitter === 'perma_on') {
                    $('li.twitter span.switch', context).click();
                }
                if (gplus_on && gplus_perma && cookies.socialSharePrivacy_gplus === 'perma_on') {
                    $('li.gplus span.switch', context).click();
                }
            }
        }); // this.each(function ()
    };      // $.fn.socialSharePrivacy = function (settings) {
}(jQuery));
/*
 * jquery.socialshareprivacy.js ende
 */



jQuery(document).ready(function($){
  if($('#socialshareprivacy-startseite').length > 0){
			$('#socialshareprivacy-startseite').socialSharePrivacy({
				services : {
					facebook : {
						'dummy_img' : '/tv/gfx/socialshareprivacy/dummy_facebook.png',
						'action' : 'recommend'
					}, 
					twitter : {
						'dummy_img' : '/tv/gfx/socialshareprivacy/dummy_twitter.png'
					},
					gplus : {
						'dummy_img' : '/tv/gfx/socialshareprivacy/dummy_gplus.png'
					}
				},
				
				uri : "http://www.tvino.de",
				'css_path' : ''

			});
  }
});





/**
*
*  MD5 (Message-Digest Algorithm)
*  http://www.webtoolkit.info/
*
**/

var MD5 = function (string) {

    function RotateLeft(lValue, iShiftBits) {
        return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
    }

    function AddUnsigned(lX,lY) {
        var lX4,lY4,lX8,lY8,lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
     }

     function F(x,y,z) { return (x & y) | ((~x) & z); }
     function G(x,y,z) { return (x & z) | (y & (~z)); }
     function H(x,y,z) { return (x ^ y ^ z); }
    function I(x,y,z) { return (y ^ (x | (~z))); }

    function FF(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function GG(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function HH(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function II(a,b,c,d,x,s,ac) {
        a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
        return AddUnsigned(RotateLeft(a, s), b);
    };

    function ConvertToWordArray(string) {
        var lWordCount;
        var lMessageLength = string.length;
        var lNumberOfWords_temp1=lMessageLength + 8;
        var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
        var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
        var lWordArray=Array(lNumberOfWords-1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount-(lByteCount % 4))/4;
        lBytePosition = (lByteCount % 4)*8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
        lWordArray[lNumberOfWords-2] = lMessageLength<<3;
        lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
        return lWordArray;
    };

    function WordToHex(lValue) {
        var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
        for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            WordToHexValue_temp = "0" + lByte.toString(16);
            WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
        }
        return WordToHexValue;
    };

    function Utf8Encode(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;
    };

    var x=Array();
    var k,AA,BB,CC,DD,a,b,c,d;
    var S11=7, S12=12, S13=17, S14=22;
    var S21=5, S22=9 , S23=14, S24=20;
    var S31=4, S32=11, S33=16, S34=23;
    var S41=6, S42=10, S43=15, S44=21;

    string = Utf8Encode(string);

    x = ConvertToWordArray(string);

    a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

    for (k=0;k<x.length;k+=16) {
        AA=a; BB=b; CC=c; DD=d;
        a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
        d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
        c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
        b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
        a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
        d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
        c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
        b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
        a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
        d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
        c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
        b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
        a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
        d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
        c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
        b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
        a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
        d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
        c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
        b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
        a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
        d=GG(d,a,b,c,x[k+10],S22,0x2441453);
        c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
        b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
        a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
        d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
        c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
        b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
        a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
        d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
        c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
        b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
        a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
        d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
        c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
        b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
        a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
        d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
        c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
        b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
        a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
        d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
        c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
        b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
        a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
        d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
        c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
        b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
        a=II(a,b,c,d,x[k+0], S41,0xF4292244);
        d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
        c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
        b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
        a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
        d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
        c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
        b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
        a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
        d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
        c=II(c,d,a,b,x[k+6], S43,0xA3014314);
        b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
        a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
        d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
        c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
        b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
        a=AddUnsigned(a,AA);
        b=AddUnsigned(b,BB);
        c=AddUnsigned(c,CC);
        d=AddUnsigned(d,DD);
    }

    var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);

    return temp.toLowerCase();
}

/** 
 * 
 * 
 * 
 *  MW START
 * 
 * 
 * **/

function showNormal(itemID) {
	$("#"+itemID+"Facts").slideUp("slow");
	$("#"+itemID+"Review").slideUp("slow");
	$("#normalViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_1").hide();
	$("#factsViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_2").show();
	$("#discussViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_3").show();
}

function showFacts(itemID) {
	$("#"+itemID+"Review").slideUp("slow");
	$("#"+itemID+"Facts").slideDown("slow");
	$("#factsViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_2").hide();
	$("#discussViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_3").show();
	$("#normalViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_1").show();
}

function showDiscuss(itemID) {
	$("#"+itemID+"Facts").slideUp("slow");
	$("#"+itemID+"Review").slideDown("slow");
	$("#discussViewHighlight"+itemID).show();
	$("#getter_"+itemID+"_3").hide();
	$("#normalViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_1").show();
	$("#factsViewHighlight"+itemID).hide();
	$("#getter_"+itemID+"_2").show();
}

function getterMouseOver(id) {
	document.getElementById(id).style.backgroundColor = "#e9e5db";
}

function getterMouseOut(id) {
	document.getElementById(id).style.backgroundColor = "#f5f3ec";
}

function hideBestellLayer(id) {
	$("#"+id).hide();
}

function showBestellAnzahlLayer(id) {
	$("#"+id).show();
}

function initWeintipHover(itemID) {
	$("#"+itemID+"subline").hover(
		function() {
			$('#'+itemID+'hendrik_thoma_weintipp').css({display: "block"});
		},
		function () {
			$('#'+itemID+'hendrik_thoma_weintipp').css({display: "none"});
		}
	);
}

var imageViewerWin;

function isOpen(win)
{
	return win && !win.closed; 
}

function closeOne(win)
{
	if(isOpen(win))
		win.close();
}

function closeAll()
{
	closeOne(imageViewerWin);
}

function openWindow(url, title, data) {
	window.open(url, title, data);
}

function openRecommendationWindow(url) {
	openWindow(url, "forwardingWin", "width=714,height=783,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no");
}


function openImageViewerWindow(url) 
{
	imageViewerWin = openWindow(url, "imageViewerWin", "width=600,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no")
	//imageViewerWin = openWindow(imageViewerWin,     url, "imageViewerWin",     "width=600,height=650,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no");
}

function openForwardingWindow(url) 
{
	openWindow(url, "forwardingWin", "width=630,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no");
}

function openOrderPrintWindow(url) 
{
	openWindow(url, "orderPrintWin", "width=850,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function openPrintWindow(url) 
{
	openWindow(url, "orderPrintWin", "width=660,height=430,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function ajaxHelpful(url, index) {
	$.get(url, '', function(responseText, textStatus, XMLHttpRequest) {
//    		document.getElementById('eval_quality'+index).innerHTML = responseText;
//    		document.getElementById('eval_question'+index).innerHTML = 'Vielen Dank f&uuml;r Ihre Meinung.';
    		$('#eval_quality'+index).html(responseText);
    		$('#eval_question'+index).html('Vielen Dank f&uuml;r Ihre Meinung.');
  		}
	);	
}

	function listOn(listItem) {
	listItem.style.background = '#F1ECEA';
	}
	function listOff(listItem) {
	listItem.style.background='#ffffff';
	}
	
	document.onkeydown = keyCheck;
	var sgCur = 0;
	var sgMax = 0;
	var isOverSuggest = false;
	var isSuggestOpened = true;
	var isSgOff = false;
	var isMLCTActivated = false;
	function is_ie(v) {
		var agt=navigator.userAgent.toLowerCase();
		var appVer = navigator.appVersion.toLowerCase();
		var is_minor = parseFloat(appVer);
		var is_major = parseInt(is_minor);
		var iePos = appVer.indexOf('msie');
		if (iePos !=-1) {
			is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
			is_major = parseInt(is_minor);
		}
		var is_ie = ((iePos!=-1));
		return (is_ie && is_major == v);
	}
	function clearSearch() {
		if (document.forms.search.searchField.value == 'Suche') 
			document.forms.search.searchField.value = '';
	}
	function search(text) {
		text = text.replace(/\+/g," ");
		if (!is_ie(7)) text = decodeURI(text); //FF IE6
			else text = unescape(text); //IE7
		if (!is_ie(6)) {
			text = unescape(text);//text.replace(/\%25/,"%");
		}
		document.getElementById('searchForm_searchField').style.color='#aaa';
		document.getElementById('searchForm_searchField').value = text;
		sendMLCT();
		document.forms.search.submit();
		var elem = document.getElementById('search_drops');
		elem.style.display = 'none';
		isSuggestOpened = false;
	}
	document.onmousedown = function() {
		if (!isOverSuggest) {
			var elem = document.getElementById('search_drops');
			if (elem != null) {
				elem.style.display = 'none';
				isSuggestOpened = false;
			}
		}
	}
	// keyboard nav
	function keyCheck(e) {
		if (isSuggestOpened == true) {
			var keyID = (window.event) ? event.keyCode : e.keyCode;
			var block = false;
			switch(keyID) {
				case 13:
				sgEnter();
				break;
				case 38:
				sgUp(); block = true;
				break;
				case 40:
				sgDown(); block = true;
				break;
				default:
				sgCur = 0;
				sgMax = getSgMax();
			}
			if (block) {
				if (window.event) window.event.returnValue = false;
				else e.preventDefault();
			}
		}
	}
	function sgDown() {
		if (sgCur == 0) {
			sgMax = getSgMax();
		}
		if (sgMax != 0) {
			if (document.getElementById('s'+(sgCur+1)) != null) {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+(sgCur+1));
				sgCur++;
			}
			else {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s1');
				sgCur = 1;
			}
		}
	}
	function sgUp() {
		if (sgCur == 0) {
			sgMax = getSgMax();
		}
		if (sgMax != 0) {
			if (document.getElementById('s'+(sgCur-1)) != null) {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+(sgCur-1));
				sgCur--;
			}
			else {
				if (document.getElementById('s'+sgCur) != null)
					sgOff('s'+sgCur);
				sgOn('s'+sgMax);
				sgCur = sgMax;
			}
		}
	}
	
	function sgEnter() {
		if (document.getElementById('s'+sgCur) != null) {
			var functionCall = document.getElementById('s'+sgCur).href;
			var start = functionCall.indexOf('\'')+1;
			var end = functionCall.lastIndexOf('\'');
			var result = functionCall.substring(start,end);
			isSgOff = true;
			search(result);
		}
	}
	function sgOn(id) {
		var el = document.getElementById(id);
		el.style.fontWeight = '700';
		el.style.color='#af2419';
	}
	function sgOff(id) {
		var el = document.getElementById(id);
		el.style.fontWeight = 'normal';
		el.style.color='#333333';
	}
	function getSgMax() {
		var c=0;
		while (document.getElementById('s'+(c+1)) != null)
			c++;
		return c;
	}
	function sendMLCT() {
		if (!isMLCTActivated)
			cmCreateManualLinkClickTag('/searchresult');
		isMLCTActivated = true;
	}
	function searchChange(url) {
		var searchString = document.getElementById('searchForm_searchField').value;
		$.get(url+'&searchString='+searchString, function(transport) { 
				var elem = document.getElementById('search_drops');
				if ((elem.style.display == 'none' || elem.style.display == '') && !isSgOff) {
					elem.style.display = 'block';
					sgCur = 0;
					isSuggestOpened = true;
				}
				elem.style.visibility = 'visible';
				document.getElementById('search_list').innerHTML = transport;
                                if (sgCur != 0)
                                        sgOn('s'+sgCur);
		}); 
	}

function showLabelIfEmpty(input,label) {
	if (input.value == '') {
		getEl(label).style.visibility='visible';
		getEl(label).style.zIndex=50;
	}
}
function hideLabelSetFocus(label,input) {
	getEl(label).style.visibility='hidden';
	getEl(label).style.zIndex=0;
	input.focus();
}

function showMenue2(menuename) {
	var elem = document.getElementById(menuename);
	var dropHeight = elem.offsetHeight;
	if (dropHeight > 180) {
		elem.style.height = '180px';
		elem.style.overflow = 'auto';
	}
	if ($('#'+menuename).is(':hidden')) {
		document.getElementById(menuename+'drop').style.display='block';
		$('#'+menuename).slideDown('fast');
	}
	else elem.style.display='block';
}
function hideMenue2(menuename) {
	$('#'+menuename).slideUp('fast',function() { deMenuHead(menuename) });
}
function toggleMenue2(menuename) {
	if (!($('#'+menuename).is(':visible'))) showMenue2(menuename);
		else hideMenue2(menuename);
}
var overIds = new Array();
function over(id) {
	document.getElementById(id).style.display = 'block';
	if (!overIds[id])
		overIds[id] = 1;
	else 
		overIds[id]++;
}
function out(id) {
	var action = 'performOut(\''+id+'\')';
	window.setTimeout(action, 1000);
}
function performOut(id) {
	if (!overIds[id]) {
	} else {
		overIds[id]--;
		if (overIds[id] < 2)
			hideMenue2(id);
	}
}
function deMenuHead(menuename) {
	document.getElementById(menuename+'drop').style.display='none';
}

/* jquery globals */

$(document).ready(function() {
  $("body").click(function (event) {
    var outsideCart = $(event.originalTarget).parents("#cart_popup").length == 0;
    if (outsideCart) {
        $("#cart_popup").hide();
    }
    alldown();
});
 });

/* top navigation logic */

function hoverCloseShow(closeId, showId, elem) {
	if (getEl(closeId) != null)
		hide(getEl(closeId));
	showById(showId);
	elem.blur();
	return false;
}

function activate(pop,head) {
alldown();
head.style.backgroundPosition = '0px 0px';
if (pop != null)
  if ($(pop).is(':hidden')) show(pop);
  else pop.style.display='block';
}

function getEl(str) {
return document.getElementById(str);
}

function alldown() {
var nav = document.getElementById('topnav');
var a = nav.getElementsByTagName("div");
var delayed = null;
for (var i=1;i<=a.length;i++) {
  if (a[i-1].className == "popup") {
    if ($(a[i-1]).is(':visible')) {
      hide(a[i-1]);
      delayed=a[i-1].parentNode;
    }
  }
}
deHead(nav,delayed);
}

function deHead(elm,except) {
var a = elm.getElementsByTagName("div");    
for (var j=1;j<=a.length;j++) {
  if (a[j-1].className == "tab") {
    if ((except == null) || !(a[j-1].parentNode == except))
      a[j-1].getElementsByTagName('a')[0].style.backgroundPosition = "0px -35px";
  }
}
}

/* equalize content box length */

//this does it for three or two
function sortNum(a,b) {
  return b-a
}
function equalHeight(one,two,three) {
  if (document.getElementById(one)) {
    var  obj=new Array(3);
    var option;
    if (document.getElementById(two)==null) 
      option=[one,three];
    else 
      option=[one,two,three];
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height="auto";
      obj[i]=document.getElementById(option[i]).offsetHeight;
      nh=obj.sort(sortNum);
    }
    nh1=nh.splice(1,2);
    for(var i=0; i<option.length; i++) {
      document.getElementById(option[i]).style.height=nh+"px";
    }
  }
}

window.onload=function(){
  equalHeight('equalleft','equalright','equalcontent');
}


  var tn_overIds = new Array();
  function tn_over(id) {
    document.getElementById(id).style.display = 'block';
    if (!tn_overIds[id])
      tn_overIds[id] = 1;
    else 
      tn_overIds[id]++;
  }
  function tn_out(id) {
    var action = 'tn_performOut(\''+id+'\')';
    window.setTimeout(action, 600);
  }
  function tn_performOut(id) {
    if (!tn_overIds[id]) {
    } else {
      tn_overIds[id]--;
      if (tn_overIds[id] < 2)
        hide(document.getElementById(id));
    }
  }

function showById(id) {
  if (getEl(id) != null)
	$("#" + id).slideDown("fast");
}
function show(elm) {
$(elm).slideDown("fast");
}
function hide(elm) {
$(elm).slideUp("fast",function() { deHead(elm.parentNode) });
}



/* home wine detail navigation logic */

function wineOpen(clink, ostr) {
var list = clink.parentNode.parentNode.parentNode;
var a = list.childNodes;
for (i=1;i<=a.length;i++) {
  if (a[i-1].className != null && a[i-1].className != "getterbox") {
    if (a[i-1].className == ostr) {
      for (j=1;j<=a[i-1].childNodes.length;j++) {
        if (a[i-1].childNodes[j-1].className != null) {
          a[i-1].childNodes[j-1].style.visibility='visible';
        }
      }
    }
    else {
      for (k=1;k<=a[i-1].childNodes.length;k++) {
        if (a[i-1].childNodes[k-1].className != null) {
          a[i-1].childNodes[k-1].style.visibility='hidden';
        }
      }
    }
  }
}
}


function logout(url) {
    $.ajax({
        type: "get",
        url: url,
        success: function(e) {
            $("#loginContainer").html(e);
        }
    });
  }


function isSafari() {
return ((navigator.userAgent.toLowerCase().indexOf('safari') != -1 )||(navigator.userAgent.toLowerCase().indexOf('applewebkit') != -1 ));
}
function isSafariAndIE() {
return ((navigator.userAgent.toLowerCase().indexOf('safari') != -1 )||(navigator.userAgent.toLowerCase().indexOf('applewebkit') != -1 ) ||(navigator.userAgent.toLowerCase().indexOf('msie') != -1 ));
}
function showMenue(menuename) {
var elem = document.getElementById(menuename);
elem.style.visibility = 'visible';
if (!isSafariAndIE()) elem.style.display = 'block';
var dropHeight = elem.offsetHeight;
if (dropHeight > 180) {
elem.style.height = '180px';
elem.style.overflow = 'auto';
}
}
function hideMenue(menuename) {
var elem = document.getElementById(menuename);
if (!isSafariAndIE()) elem.style.display = 'none';
elem.style.visibility = 'hidden';
}
function toggleMenue(menuename) {
var elem = document.getElementById(menuename);
if (elem.style.display == 'none' || elem.style.display == '' ) elem.style.display = 'block';
else if (!isSafariAndIE()) elem.style.display = 'none';
elem.style.visibility = (elem.style.visibility == 'hidden' || elem.style.visibility == '' ) ? 'visible' : 'hidden';
var dropHeight = elem.offsetHeight;
if (dropHeight > 180) {
elem.style.height = '180px';
elem.style.overflow = 'auto';
}
}
function listOn(listItem) {
listItem.style.background = '#F1ECEA';
}
function listOff(listItem) {
listItem.style.background='#ffffff';
}
function selectPulldown(formName, fieldName, value, changeId, changeText, submitOnChange, showPleaseWait) {
document.forms[formName].elements[fieldName].value = value;
document.getElementById(changeId).innerHTML = changeText;
if (showPleaseWait)
showPleaseWaitDialog();
if (submitOnChange)
document.forms[formName].submit();
}

function showNLPopup() {
        grayOut(true);
        document.getElementById('nwl_popup').style.display='block';
}
function hideNLPopup() {
        document.getElementById('nwl_popup').style.display='none';
        grayOut(false);
}
function disableNLPopup() {
    d = new Date();
    d.setMinutes(d.getMinutes() + 60 * 24 * 1005);
    document.cookie='showNLPopup=false;path=/;expires=' + d.toGMTString();
    hideNLPopup();
}

function grayOut(show) {
        var vis = (show == false) ? false : true;
        var zindex = 192;
        var opacity = 50;
        var opaque = (opacity / 100);
        var bgcolor = '#000000';
        var dark=document.getElementById('darkenScreenObject');
        if (!dark) {
          var tbody = document.getElementsByTagName("body")[0];
          var tnode = document.createElement('div');
              tnode.style.position='absolute';
              tnode.style.top='0px';
              tnode.style.left='0px';
              tnode.style.overflow='hidden';
              tnode.style.display='none';
              tnode.id='darkenScreenObject';
          tbody.appendChild(tnode);
          dark=document.getElementById('darkenScreenObject');
        }
        if (vis) {
           // Calculate the page width and height
         if(navigator.appName.indexOf("Explorer") == -1) {
             var pageWidth='100%';
             var pageHeight='100%';
             dark.style.position='fixed';
          } else if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
              var pageWidth = document.body.scrollWidth+'px';
              var pageHeight = document.body.scrollHeight+24+'px'; //24 for IE7
          } else if( document.body.offsetWidth ) {
            var pageWidth = document.body.offsetWidth+'px';
            var pageHeight = document.body.offsetHeight+24+'px';
          } else {
             var pageWidth='100%';
             var pageHeight='100%';
          }
          //set the shader to cover the entire page and make it visible.
          dark.style.opacity=opaque;
          dark.style.MozOpacity=opaque;
          dark.style.filter='alpha(opacity='+opacity+')';
          dark.style.zIndex=zindex;
          dark.style.backgroundColor=bgcolor;
          dark.style.width= pageWidth;
          dark.style.height= pageHeight;
          dark.style.display='block';
        } else {
          dark.style.display='none';
        }      
      }







