secondChances = 0;

function google_ad_request_done(google_ads) {
  var s = '';
  var i;
  
  if (google_ads.length == 0) {
    document.getElementById(cur_google_id).className += ' secondChance mirago '+cur_google_direction;
    document.getElementById(cur_google_id).setAttribute('M3AdvertNumber', 2, 1);
    secondChances += 2;
    if(typeof miragoSet == "undefined") {
      window.addEventListener("load", function() {
        loadScript("http://cdn.www.mirago.de/feed/_resources/scripts/jsfeed-1.3.min.js", function(){
          getM3Adverts('Germany', secondChances, 'REF' , 'secondChance', '', '914055', '22,21,100,23,25,24,30,26,27,104,101,103,102,31,34,33,32', '', '', '','', '', '', '', '', '', '', '', '', '1', '', '1','', '', '', '', '0', '', '90', '53');
      })}, false);
      miragoSet = true;
    }
    return;
  }
  s = showAd();
  document.getElementById(cur_google_id).innerHTML = s;
  if(cur_google_id=="top" && google_ads[0].type!="text" && cur_google_direction=="horizontal" && window.innerWidth && parseInt(window.innerWidth)>1200) {
    document.getElementById(cur_google_id).style.cssFloat = 'left';
    document.getElementById(cur_google_id).style.marginRight = '20px';
    
    if(document.getElementById('attributeDiv')) {
      document.getElementById('attributeDiv').style.clear = 'left';
    } else {
      document.getElementById('textP').innerHTML += '<br style="clear:left;height:1px;line-height:1px;font-size:1px />';
    }
    
    if(document.getElementById('werbefrei_'+cur_google_id)) document.getElementById('werbefrei_'+cur_google_id).style.display = 'none';
  }
  return;
}

function showAd() {
  var s = '';
  if(google_ads[0].type!="html") {
    if(typeof google_title_pre != 'undefined') {
      s += google_title_pre;
      delete google_title_pre;
    }
    s += '<a href="' + google_info.feedback_url + '" style="text-decoration:none;color:#555;font-size:12px;padding-left:6px">Google-Anzeigen</a>';
    if(typeof google_title_after != 'undefined') {
      s += google_title_after;
      delete google_title_after;
    }
  }
  
  if (google_ads[0].type == "flash") {
    s += '<br>' + 
        '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
          ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' + 
          google_ad.image_width + '" HEIGHT="' + 
          google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' + 
          google_ad.image_url + '">' + 
          '<PARAM NAME="quality" VALUE="high" /><param name="wmode" value="opaque" />' + 
          '<PARAM NAME="AllowScriptAccess" VALUE="never" />' + 
          '<EMBED wmode="opaque" src="' + 
          google_ad.image_url + '" WIDTH="' + 
          google_ad.image_width + '" HEIGHT="' + 
          google_ad.image_height + 
          '" TYPE="application/x-shockwave-flash"' + 
          ' AllowScriptAccess="never" ' + 
          ' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
    
  } else if (google_ads[0].type == "image") {
     s += '<br> <a href="' + 
          google_ads[0].url + '" target="_blank" title="' + 
          google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'' +
          google_ads[0].visible_url + '\';return true"><img src="' +
          google_ads[0].image_url + '" width="' + 
          google_ads[0].image_width + '" height="' + 
          google_ads[0].image_height + '"></a><br />';
  } else if (google_ads[0].type == "html") {
    s += google_ads[0].snippet;
  } else {
    if (google_ads[0].bidtype == "CPC") {
      google_num += google_ads.length;
    }
    
    if(cur_google_direction=="horizontal") {
      if(typeof google_linebreaks == 'undefined') {
        google_linebreaks = Math.round(Math.random());
      }
      for(var i = 0; i < google_ads.length; ++i) {
        s += '<div';
        if(window.google_mouseover && google_mouseover=='1') {
          s += ' onmouseover="this.style.background=\'#fcc\'" onmouseout="this.style.background=\'';
          if(window.gg_color_bg) s += '#'+gg_color_bg;
          else s += '#fcfcfc';
          s += '\'"';
        }
        s += ' style="';
        if(google_ads.length==1) s += 'font-size:16px;';
        if(window.gg_color_text) s += 'color:#'+gg_color_text+';';
        
        if(document.getElementById(cur_google_id).className.indexOf("odd")<0 && document.getElementById(cur_google_id).className.indexOf("even")<0 && i==0){
          s += 'border-top:solid 1px #bbb;';
        }
        if(document.getElementById(cur_google_id).className.indexOf("odd")<0 && document.getElementById(cur_google_id).className.indexOf("even")<0 && i==google_ads.length-1){
          s += 'border-bottom:solid 1px #bbb;';
        }
        
        if(i>0) s += 'padding:9px 6px 4px;';
        else s += 'padding:4px 6px;';
        
        if(document.getElementById(cur_google_id).className.indexOf("odd")<0 && document.getElementById(cur_google_id).className.indexOf("even")<0) {
          if(window.gg_color_bg) s += 'background:#'+gg_color_bg;
          else s += 'background:#fcfcfc';
        }
        
        s += '"><a href="' +
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'' +
            google_ads[i].visible_url + '\';return true"';
        s += ' target="_blank"><b';
        if(window.gg_color_link) s += ' style="color:#'+gg_color_link+'"';
        s += '>' +
        google_ads[i].line1 + '</b></a><div style="padding-left:';
        if(google_ads.length==1) s += google_ads[i].line1.length * 9 + 9;
        else s += 25*8+20;
        s += 'px;margin-top:-20px">';
        s += google_ads[i].line2+' ';
        if(window.google_linebreaks && google_linebreaks>=1) s += '<br />';
        s += google_ads[i].line3+' ';
        s += '<br />';
        s += '<a style="text-decoration:none;';

        if(window.gg_color_url) s += 'color:#'+gg_color_url+';';
        s += '" href="' + 
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'' +
            google_ads[i].visible_url + '\';return true" target="_blank">'+google_ads[i].visible_url + '</a></div>';
        s += '</div>';
      }
    } else if(cur_google_direction=="vertical") {
      for(i = 0; i < google_ads.length; ++i) {
        s += '<div style="padding:4px 6px"><a href="' + 
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'' +
            google_ads[i].visible_url + '\';return true" target="_blank"><b>' + 
            google_ads[i].line1 + '</b></a><br />' +
            google_ads[i].line2 + '<br />' +
            google_ads[i].line3 + '<br /><a style="text-decoration:none;color:#333" href="' + 
            google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'' +
            google_ads[i].visible_url + '\';return true" target="_blank">' + 
            google_ads[i].visible_url + '</a></div>';
      }
    }
  }
  if(typeof google_body_after != 'undefined') {
    s += google_body_after;
    delete google_body_after;
  }
  return s;
}

var google_num = 0;
