

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// tillmann.js
// Javascript functions for Tillmann Lauterbach website
//
// FASTBOIL                     1.0         10/01/2010
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var flashvars={dataSource:"default.php?fct=colxml"};
var params={
    width: "370",
    height: "490", 
    quality: "high", 
    pluginspage: "http://www.macromedia.com/go/getflashplayer", 
    align: "middle", 
    play: "true", 
    loop: "true", 
    scale: "showall", 
    wmode: "transparent",
    devicefont: "false", 
    bgcolor: "000000", 
    menu: "false", 
    allowFullScreen: "false", 
    allowScriptAccess: "sameDomain", 
    movie: "tlslideshow", 
    salign: ""
};
var attributes={};


var activeProject = 0;
function setSWF(idproject) {
  if (document.getElementById('tlslideshow')) {
    activeProject = idproject;
    swfobject.embedSWF("tl_collections.swf", "tlslideshow", "370", "490", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
  }
}

function onSWFInitialized() {
  if (activeProject>0) refreshSWFFor(activeProject);
}

function getSWFByName(value) {
  if (navigator.appName.indexOf("Microsoft") != -1) {
    return window[value];
  } else {
    return document[value];
  }
}

function refreshSWFFor(id){
  getSWFByName("tlslideshow").refreshViewFor(id);
}




var cPage = 0;
var timeoutContent;
var delayContent = 10;
var stepContent = 10;


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function setLayout
// Object : Setting div height
// FASTBOIL                     1.0         10/04/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

function clickLogo(idHomepage,mainWidth) {

  if (cPage==idHomepage) {
    // Current page is homepage
    // Closing the main div
    if (document.getElementById('tillmannfull')) {
      clearTimeout(timeoutContent);
      if (document.getElementById('tillmannfull').style.marginLeft=='-'+mainWidth+'px')
          showMain();
      else
          hideMain(mainWidth);
    }
  }
  else {
    // Displaying homepagepage
    menu(idHomepage);
  }
}



function menu(id) {
    hidediv('content_o');
    fbGetUrlDivContent(id);
    fbGetUrlDivBg(id);
}


function fbGetUrlDivContent(id) {
  if (document.getElementById('tillmannmain')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('tillmannmain');
    xReq.open("GET",'default.php?fct=mc&p='+id,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDivContent(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDivContent(xRequest,id) {
  if (xRequest.readyState==4) {
    clearTimeout(timeoutContent);
    document.getElementById('tillmannmain').innerHTML=xRequest.responseText;
    setPage(id);
    //Scroller.reset('content_i');
  }
}

function setPage(idPage) {
  if (document.getElementById('tlslideshow')) setSWF(document.getElementById('tlslideshow').innerHTML);
  cPage = idPage;
}

function fbGetUrlDivBg(id) {
  if (document.getElementById('tillmannfull')) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('tillmannfull');
    xReq.open("GET",'default.php?fct=fbg&p='+id,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDivBg(xReq);};
    xReq.send(null);
  }
}

function fbEventGetUrlDivBg(xRequest) {
  if (xRequest.readyState==4) {
    clearTimeout(timeoutContent);
    document.getElementById('tillmannfull').style.backgroundImage="url('/"+xRequest.responseText+"')";
    showdiv('content_o');
  }
}

function showMain() {
  myMarginStr = document.getElementById('tillmannfull').style.marginLeft;
  var reg = new RegExp("(px)", "g");
  cMargin = parseInt(myMarginStr.replace(reg,""));
  newMargin = cMargin+stepContent;
  if (newMargin>=0)
    document.getElementById('tillmannfull').style.marginLeft = '0px';
  else {
    document.getElementById('tillmannfull').style.marginLeft = (newMargin)+'px';
    timeoutContent = setTimeout('showMain()',delayContent);
  }
}

function hideMain(mainWidth) {
  myMarginStr = document.getElementById('tillmannfull').style.marginLeft;
  var reg = new RegExp("(px)", "g");
  cMargin = parseInt(myMarginStr.replace(reg,""));
  newMargin = cMargin-stepContent;
  if (newMargin<=(-mainWidth)) {
    document.getElementById('tillmannfull').style.marginLeft = '-'+mainWidth+'px';
  }
  else {
    document.getElementById('tillmannfull').style.marginLeft = (newMargin)+'px';
    timeoutContent = setTimeout('hideMain('+mainWidth+')',delayContent);
  }
}













//============================================================================//
//                            Ajax                                            //
//============================================================================//

function fbGetUrlDiv(id,url,innerhtml) {
  if (document.getElementById(id)) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById(id);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDiv(xRequest,anId) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
    }
}

function fbShowWaiting(obj,innerhtml) {
    obj.innerHTML=innerhtml;
}

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) // Firefox
    {
       return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
        {
            return(new ActiveXObject("Msxml2.XMLHTTP"));
        } 
        catch (e)
        {
            try
            {
                return(new ActiveXObject("Microsoft.XMLHTTP"));
            }
            catch (e)
            {
                alert("Your browser does not support XMLHTTPRequest...");
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
       alert("Your browser does not support XMLHTTPRequest...");
    }
}

function hidediv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
      if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layer[myId].visibility = 'hidden';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'hidden';
       }
    }
}

function showdiv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layers[myId].visibility = 'visible';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'visible';
        }
    }
}

