function tmt_winLaunch(theURL,winName,targetName,features) {
eval(winName+"=window.open('"+theURL+"','"+targetName+"','"+features+"')")
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {v=args[i+2];
    if (obj.style) {obj=obj.style;v=(v=='show')?'visible':(v='hide')?'hidden':v;}
    obj.visibility=v;}
}

function MM_preloadImages() { //v3.0
  var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;if(!d) d=document;if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}
}
function dpSmartLink(u,n,w,h,p) { // v1.4 by David Powers
  var a,j,k,x,y,f='';if(!n){n='';}if(w){f+='width='+w+',';}if(h){f+='height='+h+',';}
  if(p){p=p.split(':');if(p[0]!='z'){p[0]=='c'?(x=(screen.width-w)/2):x=p[0];f+='left='+x+',';}
  if(p[1]!='z'){if(p[0]=='c'){y=(screen.height-h-p[1])/2;if(navigator.appName.indexOf('Op')!=-1){
  y-=96;y=y<0?0:y;}}else{y=p[1];}f+='top='+y+',';}}a=arguments.length;if(a>5){for (k=5;k<a;k++){
  switch(arguments[k]){case 'all':f+='toolbar,menubar,location,scrollbars,status,resizable,';break;
  case 't':f+='toolbar,';break;case 'm':f+='menubar,';break;case 'l':f+='location,';break;
  case 'sc':f+='scrollbars,';break;case 's':f+='status,';break;case 'r':f+='resizable,';}}}
  if(f.charAt(f.length-1)==','){f=f.slice(0,-1);}j=window.open(u,n,f);j.focus();
  document.MM_returnValue=false;
}

function flvFPW1(){//v1.44
// Copyright 2002-2004, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);if (v3){v9.focus();}document.MM_returnValue=false;return v9;}

var isIOS = navigator.userAgent.match(/iPhone/i) !== null || navigator.userAgent.match(/iPad/i) !== null || navigator.userAgent.match(/iPod/i) !== null;

function showHTMLSpielerDetailPortrait2 (e) {
   if (e.success != true) {
      $(document).ready(function() {
         $("#"+e.id).html($("#imgSpielerDetailPortrait").html());
      });
   }
}
function showHTMLSpielerDetailPortrait (e) {
   if (e.success != true) {
      $(document).ready(function() {
          //
      });
   }
}
function showHTMLSpielerKurzPortrait (e) {
   if (e.success == true) {
      $(document).ready(function() {
         $("#"+e.id).parent().css("display", "block");
         $("#spielerthumbscontainer").css("display", "block");
      });
   } else {
      $(document).ready(function() {
//         $("#"+e.id).parent().html("html alternative");
//         $("#"+e.id).parent().css("display", "block");
      });
   }
}

function showHTMLPanelSport1Highlights (e) {
   if (e.success == true) {
      $(document).ready(function() {
         $("#panelSport1Highlights").css("display", "block");
      });
   }
}

function showContentHTML5Video (e, fi, bi, w, h) {
   if (e.success != true && fi != '') {
      $(document).ready(function() {
         $("#"+e.id).html('<video  width="'+w+'" height="'+h+'" controls="controls" poster="'+bi+'" src="'+fi+'" type="video/mp4">');
      });
   }
}
/*
function rotateFunkelsterne (id, oldrot, time) {
  if(isIOS) {
      var rot = oldrot + 180;
      $('#'+id+' img').css('-webkit-transition', 'all 1.0s ease').css('-webkit-transform', 'rotate('+rot+'deg)');
      setTimeout(function(){rotateFunkelsterne(id, rot, time);}, time);
  }
}
*/

var lazystart=new Array;
lazystart['videos']=0;
lazystart['news']=0;
lazystart['bilder']=0;
$(document).ready(function() {

   var footerSponsorenCont_aktiv=0;var footerSponsorenCont_pause=false;
   $("#footersponsoren").hover(function(){footerSponsorenCont_pause=true;},function(){footerSponsorenCont_pause=false;});
   function rotateFooterSponsoren() {
      if (footerSponsorenCont_pause==false) {
         $("#footersponsoren").fadeTo('slow',0.01,function(){
            footerSponsorenCont_aktiv++;if (footerSponsorenCont_aktiv>$(".footersponsorenCont").length){footerSponsorenCont_aktiv=1;}
            $("#footersponsoren").html($(".footersponsorenCont[rel='"+footerSponsorenCont_aktiv+"']").html());
            $("#footersponsoren").fadeTo('slow',1.00,function(){setTimeout(function(){rotateFooterSponsoren();},5000);});
         });
      } else {setTimeout(function(){rotateFooterSponsoren();},2000);}
   }
   rotateFooterSponsoren();
   
	$(".hoverImg").hover( function() {var imgName = $(this).attr('src');$(this).attr('src', imgName.replace('_off','_on'));}, function() {var imgName = $(this).attr('src');$(this).attr('src', imgName.replace('_on','_off'));});
	$(".hoverImg").each(function(i) {var imgName = $(this).attr('src');MM_preloadImages(imgName.replace('_off','_on'));});
	
	$("#spielerthumbscontainer a").click(function() {swfobject.embedSWF("/files/portraits/kurzportrait.swf?xmlf=/files/portraits/spielerdaten.xml&id="+$(this).attr('rel'), "flashSpielerKurzPortraitCont", "745", "325", "9.0.0", "", null, {quality: "high", wmode: "transparent"}, null, showHTMLSpielerKurzPortrait);});
	
	$("#funkellinks").each(function(){var funkelID = $(this).attr('id');swfobject.embedSWF("/flash/funkelstern_links.swf", $(this).attr('id'), "50", "50", "9.0.0", "", null, {quality: "high", wmode: "transparent"}, null, function(){/*if(isIOS){setTimeout(function(){rotateFunkelsterne(funkelID, 0, 8000);}, 5000);}*/});});
	$("#funkelrechts").each(function(){var funkelID = $(this).attr('id');swfobject.embedSWF("/flash/funkelstern_rechts.swf", $(this).attr('id'), "50", "50", "9.0.0", "", null, {quality: "high", wmode: "transparent"}, null, function(){/*if(isIOS){setTimeout(function(){rotateFunkelsterne(funkelID, 0, 12000);}, 9000);}*/});});
	
	$('#spielepanelcountdown').countdown();
	
	if($.browser.msie&&parseInt($.browser.version)<=7){$("#topinhaltscontainer").before('<div id="ie6warning">Sie verwenden den veralteten Internet Explorer - die BBC-Webseite ist <strong>nicht</strong> kompatibel mit dieser Browserversion! Wir empfehlen Ihnen den Download eines <strong>aktuellen und sichereren Browsers</strong>, z. B. <a href="http://www.microsoft.com/germany/windows/internet-explorer/default.aspx" target="_blank">Internet Explorer&reg;</a>, <a href="http://www.mozilla.org/de/firefox/" target="_blank">Firefox&reg;</a>, <a href="http://www.apple.com/de/safari/" target="_blank">Safari</a>, <a href="http://www.google.com/chrome" target="_blank">Chrome</a>, <a href="http://www.opera.com/" target="_blank">Opera</a>.</div>'+"\n");}


    /*var canvasEncoding = typeof HTMLCanvasElement != undefined ? true : false;*/
    var canvasEncoding = false;
    function ImageToLocalStorage(img, src, name, set) {
        var ts = Math.round((new Date()).getTime() / 1000);
        var maxStoreTime = 3600;
        if (!localStorage['time_'+src] || localStorage['time_'+src] < ts-maxStoreTime) {
            localStorage[src] = '';
            localStorage['time_'+src] = '';
        }
        // pruefe ob bild im speicher ohne fehler
        if (localStorage[src] && /^data:image/.test(localStorage[src])) {
            img.attr('src', localStorage[src]);
        } else {
            //img.attr('src', src);
            if (localStorage[src] !== 'pending') {
                localStorage[src] = 'pending';
                if (canvasEncoding) {
                    localStorage[src] = ImageEncodeBase64(img);
                } else {
                    $.ajax({
                        url: '/img.php?set='+set+'&src=' + name,
                        success: function (data) {
                            img.attr('src', data);
                            localStorage[src] = data;
                            var ts2 = Math.round((new Date()).getTime() / 1000);
                            localStorage['time_'+src] = ts2;
                        },
                        error: function () {
                            localStorage[src] = 'error';
                            img.attr('src', src);
                        }
                    });
                }
            }
        }
    }
    /*
    function supports_html5_storage() {
        try {
            return 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) {
            return false;
        }
    }
    */
   var oldIE = false;
   if($.browser.msie&&parseInt($.browser.version)<=7){
       oldIE = true;
   }
    $(".footersponsorenCont img[data-src]").each(function(i){
        //try {
        //$(this).attr('src') = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
        //if (typeof(localStorage) != 'undefined' && localStorage) {
        if (!oldIE) {
            if (localStorage) {
                var set = 'footersponsoren';
                var img = $(this);
                var src = $(this).attr('data-src');
                var name = $(this).attr('rel');
                ImageToLocalStorage(img, src, name, set);
            } else {
                $(this).attr('src') = $(this).attr('data-src');
            }
        } else {
            $(this).attr('src') = $(this).attr('data-src');
        }
        //} catch (e) {
        //    $(this).attr('src') = $(this).attr('data-src');
        //}
    });

/*
var flashSpielerKurzPortraitHTML = $("div.flashSpielerKurzPortraitInvisible").html();
$("div.flashSpielerKurzPortraitInvisible").html='';
$("div.flashSpielerKurzPortraitInvisible").live("inview", function(event, isVisible) {
  if (isVisible) {
    $(this).html(flashSpielerKurzPortraitHTML);
    $(this).removeClass('flashSpielerKurzPortraitInvisible');
  }
});
*/

/*
$('div#flashSpielerKurzPortrait').bind('inview', function(event, isInView, visiblePartX, visiblePartY) {
  if (isInView) {
    $('div#flashSpielerKurzPortrait').show();
    // element is now visible in the viewport
    
    if (visiblePartY == 'top') {
      // top part of element is visible
    } else if (visiblePartY == 'bottom') {
      // bottom part of element is visible
    } else {
      // whole part of element is visible
    }
    
  //} else {
    // element has gone out of viewport
  }
});
*/
            $(".kurzportraitswitch").click(function() {
                $.ajax({
                    url: $(this).attr('rel'),
                    success: function(data){
                        $(data).children('img').load(function() {
                            $('#flashSpielerKurzPortrait').fadeTo('fast', 0.1, function() {
                                $('#flashSpielerKurzPortrait').html(data).fadeTo('fast', 1.0);
                            });
                        });
                    }
                });
            });

            $(".lazybutton").live('click', function() {
                var opt = $(this).attr('rel').split(';')[0];
                var limit = parseInt($(this).attr('rel').split(';')[1]);
                var start = lazystart[opt] + limit;
                lazystart[opt] = start;
                var url = start+'/'+$(this).attr('href');
                var btn = $(this);
                fetchLazyButtonContent(url, btn, opt, start);
                return false;
            });
            function fetchLazyButtonContent(url, btn, opt, i) {
                $.ajax({url: url, success: function(data){
                        btn.fadeOut('fast', function() {
                            btn.remove();
                            if (opt == 'bilder') {
                                $(data).appendTo('#lazy'+opt);
                            } else {
                                $('#lazy'+opt).append('<div id="lazy'+opt+'cont_'+i+'" style="display:none;">'+data+'</div>');
                                $('#lazy'+opt+'cont_'+i+' img').load(function() {
                                    $('#lazy'+opt+'cont_'+i).slideDown('slow');
                                });
                            }
                        });
                }});
            }
            
            $("#icaltooltipInit").tooltip({events: {tooltip: "focus mouseover,blur mouseout"}, position: 'top center', relative: true, tip: '#icaltooltip', effect: 'fade', offset: [10, 0]});
            var icaltooltip = $("#icaltooltipInit").data('tooltip');
            $("#icaltooltipInit").click(function() {if (icaltooltip.isShown()) {icaltooltip.hide();} else {icaltooltip.show();}});
});
