function calculateCornerX(el){
    var width = parseInt(el.offsetWidth);
    var cornerX = (typeof(document.documentElement) == 'object' && typeof(document.documentElement.clientWidth) == 'number') ? ((typeof(window.innerWidth) == 'number')  ? pageXOffset : document.documentElement.scrollLeft) + (document.documentElement.clientWidth - width)/2 : document.body.scrollLeft + (document.body.clientWidth - width)/2;

    return cornerX;
}

function calculateCornerY( el ){
    var height = parseInt(el.offsetHeight);
    var clientHeight = (typeof(document.documentElement) == 'object' && typeof(document.documentElement.clientWidth) == 'number' 
      && (typeof(window.innerWidth) == 'number')  && document.documentElement.clientHeight   > window.innerHeight)
        ? window.innerHeight
        : document.documentElement.clientHeight

    var cornerY =
        (typeof(document.documentElement) == 'object' && typeof(document.documentElement.clientWidth) == 'number')
        ? ((typeof(window.innerWidth) == 'number')
           ? pageYOffset
           : document.documentElement.scrollTop) +
          (clientHeight - height)/2
        : document.body.scrollTop +
          (document.body.clientHeight - height)/2;
    return cornerY;
}



var clicked = null;
function showAlert(album_id){
  closeAlert();
  clicked = album_id;
  $('body_blocker').setStyle({visibility:"visible"});
  new Effect.Opacity('body_blocker', {
    from: 0.0,
    to: 0.7,
    duration: 1.8
  });

      var url = null;
      url = '/get_album.php?album_id='+clicked;
      new Ajax.Request(url, {
        onSuccess:function(transport){
          var data = eval(transport.responseText);
          var w = data[0].width+"px";
          var h = data[0].height+"px";
         
          $('window_alert').setStyle({width:data[0].width+'px',height:data[0].height+'px'});
          //$('window_alert').setStyle({top:calculateCornerY($('window_alert'))+"px", left:calculateCornerX($('window_alert'))+"px",visibility:"visible"});
          $('window_alert').setStyle({visibility:"visible"});
          $('window_alert').innerHTML = '<div style="cursor:pointer; float:right; font-size:12px;font-family:\'Trebuchet MS\',Arial; color:#EDEDED" onClick="javascript:closeAlert();">Close&nbsp;&nbsp;<img src="/images/x-close.png" border="0" style="width:15px; height:15px; vertical-align:middle;" /></div>'
            +"<div style=\"margin-top:15px;\">"+data[0].html+"</div>";
          $('box_container').setStyle({width:w,height:h});
          $('spary_content').setStyle({width:w});
         
        }
        
      });
}

function closeAlert(){
  $('window_alert').setStyle({visibility:"hidden",width:"0px",height:"0px"});
  $('body_blocker').setStyle({visibility:"hidden"});
  $('window_alert').innerHTML = "";
}

function changeMain(img,content){
  
  document.getElementById('mainPicture').src = '/images/null.gif';
  document.getElementById('mainPicture').src = img;
  document.getElementById('photoTitle').innerHTML = URLDecode(content);
}
function URLDecode(content)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = content;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
     if (ch == "+") {
         plaintext += " ";
       i++;
     } else if (ch == "%") {
      if (i < (encoded.length-2) 
          && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
          && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
        plaintext += unescape( encoded.substr(i,3) );
        i += 3;
      } else {
        alert( 'Bad escape combination near ...' + encoded.substr(i) );
        plaintext += "%[ERROR]";
        i++;
      }
    } else {
       plaintext += ch;
       i++;
    }
  } // while
   return  plaintext;
};


var pag = 0;
var move = 0;
var stop=false;
function scroll(coef){
  my_ul = document.getElementById("theList");
  move += coef;
  if(move > 0) return;
  //alert(parseInt(my_ul.style.width)+move);
  if( (parseInt(my_ul.style.width)+move) < 600) return;
  my_ul.style.marginLeft = move+'px' ;
  //alert(my_ul.style.marginLeft);
  if(!stop)
    timer = setTimeout("scroll("+coef+")", 80);
}
