/*
 Copyright (c) 2008 by EMMA-STIL mediendesign, http://www.emma-stil.de

 All rights reserved
*/


function showPopover(id, x, y, width, height) {
  var h = window.innerHeight;
  var w = window.innerWidth;
  var i=document.getElementById(id);
  if(document.all) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
    i = document.all[id];
  }
  if(!width) width=w+'px';
  if(!height) height= (h*2)+'px';
  if(i)
    {
      i.style.position='absolute';
      i.style.top=x;
      i.style.left=y;
      i.style.width=width;
      i.style.height=height;
      i.style.visibility='visible';
      i.style.paddingTop='120px';
      var selects = document.getElementsByTagName("select");
      for(var j=0;j<selects.length;++j)
        selects[j].style.visibility='hidden';
    }
  i.scrollIntoView(true);
}

function hidePopover(id) {
  var i=document.getElementById(id);
  if(document.all)
    i = document.all[id];
  if(i)
    {
      i.style.width='0px';
      i.style.height='0px';
      i.style.visibility='hidden';
      var selects = document.getElementsByTagName("select");
      for(var j=0;j<selects.length;++j)
        selects[j].style.visibility='visible';
    }
}

function imagePopOver(img_url)
{
  if(null != img_url) {
    if ($.browser.msie) $('select').hide();
    $(SRContext.popBg).show();
    $(SRContext.popFifty).show();
    $(SRContext.popBg).css("height", $(document).height());
    $(SRContext.popContent).hide();

    $(SRContext.popFifty).prepend(
      $('<img id="sr-popover-loading-img" style="position:absolute;top:-40px;left:-20px;" src="'+
        SRContext.LOADING_GIF +'" alt"Vorschau wird geladen. Klicken, um Vorschau zu beenden"/>'));


    $(SRContext.popFifty).prepend(
      $('<img id="sr-popover-preview-img" src="'+img_url+
        '" alt="Hier klicken, um Vorschau zu beenden" title="Hier klicken, um Vorschau zu beenden" border="0" align="center" style="width:1px;height:1px;" />').
        load(function(){
               $("#sr-popover-loading-img").hide();
               $(this).show();
               $(this).css({width: "", height: ""});
               var x = $(this).width() / 2;
               var y = $(window).height() - $(this).height() - ( ($(window).height() - $(this).height()) / 2 );
               y += $(window).scrollTop();
               $(this).css({border: "10px solid #333333",
                            position: "absolute",
                            left: "-"+x+"px",
                            top: ""+y+"px",
                            cursor: "pointer"});
               $(SRContext.popBg).css("height", $(document).height());
               $(this).click(function(){
                               $(SRContext.popFifty).hide();
                               $(SRContext.popBg).hide();
                               if ($.browser.msie) $('select').show();
                               $(this).remove();
                             });}));
  }
}

function htmlPopOver(elements_id)
{
  if($("#" + elements_id)) {
    elements_id = "#" + elements_id;
    if ($.browser.msie) $('select').hide();
    $(SRContext.popBg).show();
    $(SRContext.popFifty).show();
    $(SRContext.popBg).css("height", $(document).height());
    $(SRContext.popFifty).prepend($(SRContext.popContent));
    $(SRContext.popContent).show();
    $(SRContext.popContent).prepend(
      $('<table class="popContent" cellpadding="0" cellspacing="0" title="Hier klicken zum Verbergen" width="100%" border="0"><thead><tr>'+
        '<th style="text-align:right;padding-right:6px;cursor:pointer;"> schlie&szlig;en </th>'+
        '</tr></thead><tbody><tr><td class="popContent" style="padding:10px;">'+$(elements_id).html()+'</td></tr></tbody><tfoot><tr>'+
        '<th style="text-align: right; padding-right: 6px; cursor: pointer;"> &#160; </th>'+
        '</tr></tfoot></table>'));

    var off = $(SRContext.popFifty).offset();
    var x = $(SRContext.popFifty).width() / 2;
    var y = 0;
    if(SRContext.POP_OVER_HTML_FIXED_OFFSET) {
      y = SRContext.POP_OVER_HTML_FIXED_OFFSET;
    }
    else {
      y = $(window).height() - $(SRContext.popContent).height() - ( ($(window).height() - $(SRContext.popContent).height()) / 2 );
    }
    y += $(window).scrollTop();

    $(SRContext.popContent).css({position: "absolute",
                                 left: "-"+x+"px",
                                 top: ""+y+"px",
                                 cursor: "pointer"});


    $(SRContext.popContent).click(function(){
                                    $(SRContext.popFifty).hide();
                                    $(SRContext.popBg).hide();
                                    if ($.browser.msie) $('select').show();
                                    $(SRContext.popContent).empty();
                                    $(SRContext.popContent).css({top: "-800px", left: "-350px"});
                                    $(SRContext.popContent).remove();
                                  });
  }
}


function doAjax(url, func)
{
  if(null != func) $.getJSON(url, func);
  else $.getJSON(url);
}

