//BY GWENAEL GODDE, FOR WATERMELON CORPORATION
//COPY, USE, MODIFICATION, REPRODUCTION NOT ALLOWED.


function screen_posy()//OK
{
  if (self.pageYOffset){return self.pageYOffset;}
  else if (document.documentElement && document.documentElement.scrollTop){return document.documentElement.scrollTop;}//ie6 shit
  else if (document.body.scrollTop){return document.body.scrollTop;}
  else {return 0;}//error
}

function screen_posx()//OK
{
  if (self.pageXOffset){return self.pageXOffset;}
  else if (document.documentElement && document.documentElement.scrollLeft){return document.documentElement.scrollLeft;}//ie6 shit
  else if (document.body.scrollLeft){return document.body.scrollLeft;}
  else {return 0;}//error
}

function screen_width()//OK
{
var turbo_width=window.innerWidth
if(turbo_width==undefined || turbo_width==0){turbo_width=document.body.clientWidth;}
return  turbo_width;
}


function page_height() 
{
  var elm = document.getElementById("page_finalbottom");
  var y = elm.offsetTop;
  return y;
}


function screen_height()//OK
{
var turbo_height=window.innerHeight
if(turbo_height==undefined || turbo_height==0){turbo_height=document.body.clientHeight;}
return  turbo_height;
}


var page_popup_bg_fade_status=0;
var page_popup_bg_fade_step=0;
var page_popup_horizontalsize=0;

var page_popup_width=20;
var page_popup_height=20;



function make_fade()
  {
    popupbgname=document.getElementById("superpopup_bg");
    if(popupbgname)
      {
         popuppic=document.getElementById("popup_piccontent");
         if(page_popup_bg_fade_step==0){popuppic.className="popupfading0";} 
         else if(page_popup_bg_fade_step==1){popuppic.className="popupfading1";} 
         else if(page_popup_bg_fade_step==2){popuppic.className="popupfading2";}
         else if(page_popup_bg_fade_step==3){popuppic.className="popupfading3";}

         var go=0;
         if(page_popup_bg_fade_status==0 && page_popup_bg_fade_step>0)
           {go=1;page_popup_bg_fade_step--;}
         else if(page_popup_bg_fade_status==1 && page_popup_bg_fade_step<3)
           {go=1;page_popup_bg_fade_step++;}

         if(go==1)
           {setTimeout("make_fade()", 50);}
         else if(page_popup_bg_fade_status==0) //Kill popup bg
          {
            popupbgname.style.visibility="hidden";
            popupbgname.style.width="0px";
            popupbgname.style.height="0px";
            popupbgname.style.left="0px";
            popupbgname.style.top="0px";
            popupbgname.innerHTML="";

            popupname=document.getElementById("superpopup");
            popupname.style.visibility="hidden";

          }
      }
  }


function page_popup_align()
  {
    if(page_popup_bg_fade_status==1)
      {
        popupbgname=document.getElementById("superpopup_bg");
        popupname.style.left=(0+screen_width()/2-page_popup_width/2-8)+"px";
        popupname.style.top=(screen_posy()+screen_height()/2-page_popup_height/2)+"px";
      }
  }

function make_resize()
  {
    popupname=document.getElementById("superpopup");
    if(page_popup_horizontalsize<page_popup_width && page_popup_bg_fade_status==1){page_popup_horizontalsize+=Math.round(1+(page_popup_width-page_popup_horizontalsize)/4);popupname.style.width=page_popup_horizontalsize+"px";setTimeout("make_resize()", 50);}
  }


function make_visible(url,width,height)
  {
    if(page_popup_bg_fade_status==1){return;}
    page_popup_width=width;
    page_popup_height=height;
    page_popup_bg_fade_status=1;page_popup_horizontalsize=1;
    setTimeout("make_fade()", 50);
    setTimeout("make_resize()", 50);
    popup_iframedata=document.getElementById("popup_iframe");
    popup_iframedata.src = url;
    page_scroll_lock_tox=screen_posx();
    page_scroll_lock_toy=screen_posy();
    popupbgname=document.getElementById("superpopup_bg");
    popupbgname.style.visibility="visible";
    popupbgname.style.width="100%";
    popupbgname.style.height=(page_height())+"px";
    popupbgname.style.left="0px";
    popupbgname.style.top="0px";
    popupbgname.innerHTML="<img src=\"skin/popup_fadebg.png\" class=\"popupfading0\" id=\"popup_piccontent\" width=\"100%\" height=\"100%\" onclick=\"make_hidden();\"/>"; 
    popupname=document.getElementById("superpopup");
    popupname.style.visibility="visible";
    popupname.style.width="1px";//780
    popupname.style.height=page_popup_height+"px";
    page_popup_align();
    page_scroll_lock=1;
  }


function make_hidden()
  {
    if(page_popup_bg_fade_status==0){return;}
    page_popup_bg_fade_status=0;
    setTimeout("make_fade()", 50);
    popupname=document.getElementById("superpopup");
    popupname.style.top="0px";
    popupname.style.height="0px";
    popupname.style.width="0px";
    popupname.style.left="0px";

    popupname=document.getElementById("popup_iframe");
    popupname.src="blank.html";

    page_scroll_lock=0;
  }


function id_posy(myid) //not sure if compatible with all browsers... ummm...
{
  var elm = document.getElementById(myid);
  var y = elm.offsetTop;
  var level = elm;
  while (level.offsetParent && level.offsetParent != document.body){level = level.offsetParent;y += level.offsetTop;}
  return y;
}

function id_posx(myid) //not sure if compatible with all browsers... ummm...
{
  var elm = document.getElementById(myid);
  var x = elm.offsetLeft;
  var level = elm;
  while (level.offsetParent && level.offsetParent != document.body){level = level.offsetParent;x += level.offsetLeft;}
  return x;
}

var scroll_to;
var scroll_tox;
var scroll_toy;

function scroll_processy()
{
  var scroll_y=screen_posy();
  var newscroll=0;
  if(scroll_y>scroll_toy){scroll_y-=Math.round(1+(scroll_y-scroll_toy)/8);newscroll=1;}
  else if(scroll_y<scroll_toy){scroll_y+=Math.round(1+(scroll_toy-scroll_y)/8);newscroll=1;}
  window.scrollTo(0, scroll_y);
  if(newscroll){setTimeout("scroll_processy()", 50);}
}

function scroll_processx()
{
  var scroll_x=screen_posx();
  var newscroll=0;
  if(scroll_x>scroll_tox){scroll_x-=Math.round(1+(scroll_x-scroll_tox)/8);newscroll=1;}
  else if(scroll_x<scroll_tox){scroll_x+=Math.round(1+(scroll_tox-scroll_x)/8);newscroll=1;}
  window.scrollTo(scroll_x,0);
  if(newscroll){setTimeout("scroll_processx()", 50);}
}

function scroll_toid_y(myid)
  {scroll_tox=0;scroll_toy=id_posy(myid);scroll_to=1;scroll_processy();}

function scroll_toid_x(myid)
  {scroll_tox=id_posx(myid);scroll_toy=0;scroll_to=1;scroll_processx();}

function scroll_to_x(x)
  {scroll_tox=x;scroll_toy=0;scroll_to=1;scroll_processx();}

function scroll_to_y(y)
  {scroll_tox=0;scroll_toy=y;scroll_to=1;scroll_processy();}

