function _e(id) {return document.getElementById(id);}

var currentPanel='';
var searchText;
var searchCleared=false;
function openPanel(id) {
  if (id!=currentPanel) {
    var panels=new Array('galerie','noutati','sondaj','contact');
    for (i=0;i<panels.length;i++) {
      _e('panel-'+panels[i]).style.display='none';
    }
    _e('panel-'+id).style.display='block';
    currentPanel=id;
  }
}

function clearSearchBox(obj) {
  if (!searchCleared) {
    searchText=obj.value;
    obj.value='';
    obj.style.color='#2F3E5D';
    searchCleared=true;
    obj.onblur=function() {if (this.value=='') {this.style.color='#768BB6';this.value=searchText;this.onblur=null;searchCleared=false;}}
  }
}

function checkSondaj(f) {
  var checked=false;
  for (i=0;i<f.choice.length;i++) {
    if (f.choice[i].checked) {checked=true;break;}
  }
  if (checked) {
    f.submit();
  } else {
    alert('Va rugam alegeti o varianta.');
  }
}



// NEWS

var scrollspeed=1;
var origspeed=scrollspeed;
var obj;

function newsReScroll() {
  obj.scrollTop=0;
  setTimeout("newsScroll();",2000);
}

function newsScroll() {
  obj=document.getElementById("newsboxScroller");
  var olds=obj.scrollTop;obj.scrollTop+=scrollspeed;
  var news=obj.scrollTop;
  if (olds==news && scrollspeed!=0) { setTimeout("newsReScroll();",2000);return false; }
  setTimeout("newsScroll();",60);
}

function initNews() {
  obj=document.getElementById("newsboxScroller");
  obj.onmouseover=function() { scrollspeed=0; }
  obj.onmouseout=function() { scrollspeed=origspeed; }
  setTimeout("newsScroll();",2000);
}


function popGallery(file) {
  popper=window.open('photo.php?file='+file,'popper',"width=10,height=10,left="+(screen.width-120)/2+",top="+(screen.height-120)/2+",resizable=no,scrollbars=no");
}

function popVideo(id) {
  popper=window.open('video.php?id='+id,'popper',"width=10,height=10,left="+(screen.width-120)/2+",top="+(screen.height-120)/2+",resizable=no,scrollbars=no");
}


function resizeToStuff(x,wrapperID) {
  var oH=getRefToDivMod(wrapperID,x.document);if(!oH) return false;
  var oW=oH.clip?oH.clip.width:oH.offsetWidth;
  var oH=oH.clip?oH.clip.height:oH.offsetHeight;if(!oH) return false;
  x.moveTo(0,0);
  x.resizeTo(oW+200,oH+200);
  var myW=0, myH=0, d=x.document.documentElement, b=x.document.body;
  if (x.innerWidth) {myW=x.innerWidth;myH=x.innerHeight;}
  else if (d && d.clientWidth) {myW=d.clientWidth;myH=d.clientHeight;}
  else if (b && b.clientWidth) {myW=b.clientWidth;myH=b.clientHeight;}
  if (window.opera && !document.childNodes) myW+=16;
  x.resizeTo(oW+((oW+200)-myW),oH+((oH+200)-myH));
  var scW=screen.availWidth?screen.availWidth:screen.width;
  var scH=screen.availHeight?screen.availHeight:screen.height;
  oW=oW+((oW+200)-myW);oH=oH+((oH+200)-myH);
  x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));

  if (x.focus) x.focus();
  return false;
}

function getPageCoords (element) {
  var coords = {x : 0, y : 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}

function getRefToDivMod( divID, oDoc ) {
  if( !oDoc ) { oDoc = document; }
  if( document.layers ) {
    if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
      for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
        y = getRefToDivMod(divID,oDoc.layers[x].document); }
      return y; } }
  if( document.getElementById ) { return oDoc.getElementById(divID); }
  if( document.all ) { return oDoc.all[divID]; }
  return document[divID];
}

function getOffsets (evt) {
  var target = evt.target;
  if (typeof target.offsetLeft == 'undefined') {
    target = target.parentNode;
  }
  var pageCoords = getPageCoords(target);
  var eventCoords = {
    x: window.pageXOffset + evt.clientX,
    y: window.pageYOffset + evt.clientY
  };
  var offsets = {
    offsetX: eventCoords.x - pageCoords.x,
    offsetY: eventCoords.y - pageCoords.y
  }
  return offsets;
}

