/**
 *  Client : Ville de Fouesnant-les Gl&eacute;nan
 *  Projet : OUE451 - Refonte du portail web de la ville
 *           Site de la Mairie de la ville - JS
 *  Auteur : Julien Roulette
 *
 *  Fonctionnalité : Fonctions js des pages intérieures
 *
 */


// change le texte situé sous les pictos des blocs services (météo, kioske, travaux etc.)
function chgtxt(text){
    if(!text) text='&nbsp;';
    var newtext = MM_findObj('soustitres-actions');
    newtext.innerHTML = text;
}

// change la classe du div en "inner" dont on fournit l'id
function chgClassDiv(iddiv) {
    var testobj = MM_findObj(iddiv);
    testobj.className='inner';
}

// trouve un objet dom dans la page courante
function MM_findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// définit la hauteur "automatique" de l'iframe "Service Public"
function autofitIframe(id){ // v.1.0
//copyright 2004 Eddie Traversa http://www.dhtmlnirvana.com/
    if (!window.opera && !document.mimeType && document.all && document.getElementById){
        parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px"
    }
    else if(document.getElementById) {
        hauteur = this.document.body.scrollHeight + 50;
        parent.document.getElementById(id).style.height=hauteur+"px"
    }
}

// affiche la webcam de la ville (code fourni par Fouesnant)
function afficheWebcam(){
    // Set the BaseURL to the URL of your camera
    var BaseURL = "http://193.252.210.246/";
    
    // DisplayWidth & DisplayHeight specifies the displayed width & height of the image.
    // You may change these numbers, the effect will be a stretched or a shrunk image
    var DisplayWidth = "480";
    var DisplayHeight = "360";
    var textstring = escape("       Fouesnant : Direct depuis la cale de Beg Meil ")
    
    // This is the path to the image generating file inside the camera itself
    var File = "axis-cgi/mjpg/video.cgi?resolution=480x360&clock=0&date=0&text=1&textstring=" + textstring;
    // No changes required below this point
    var output = "";
    if ((navigator.appName == "Microsoft Internet Explorer") &&
       (navigator.platform != "MacPPC") && (navigator.platform != "Mac68k"))
    {
      // If Internet Explorer under Windows then use ActiveX 
      output  = '<OBJECT ID="Player" width='
      output += DisplayWidth;
      output += ' height=';
      output += DisplayHeight;
      output += ' CLASSID="CLSID:DE625294-70E6-45ED-B895-CFFA13AEB044" ';
      output += 'CODEBASE="';
      output += BaseURL;
      output += 'activex/AMC.cab#version=4,1,4,0">';
      output += '<PARAM NAME="MediaURL" VALUE="';
      output += BaseURL;
      output += File + '">';
      output += '<param name="MediaType" value="mjpeg-unicast">';
      output += '<param name="ShowStatusBar" value="0">';
      output += '<param name="ShowToolbar" value="0">';
      output += '<param name="AutoStart" value="1">';
      output += '<param name="StretchToFit" value="1">';
      output += '<BR><B>Axis Media Control</B><BR>';
      output += 'The AXIS Media Control, which enables you ';
      output += 'to view live image streams in Microsoft Internet';
      output += ' Explorer, could not be registered on your computer.';
      output += '<BR></OBJECT>';
    } else {
      // If not IE for Windows use the browser itself to display
      theDate = new Date();
      output  = '<IMG SRC="';
      output += BaseURL;
      output += File;
      output += '&dummy=' + theDate.getTime().toString(10);
      output += '" HEIGHT="';
      output += DisplayHeight;
      output += '" WIDTH="';
      output += DisplayWidth;
      output += '" ALT="Webcam de la ville de Fouesnant-les Gl&eacute;nan">';
    }
    document.write(output);
    document.Player.ToolbarConfiguration = "play,+snapshot,+fullscreen"
    
    // Remove the // below to use the code for Motion Detection. 
      // document.Player.UIMode = "MDConfig";
      // document.Player.MotionConfigURL = "/axis-cgi/operator/param.cgi?ImageSource=0"
      // document.Player.MotionDataURL = "/axis-cgi/motion/motiondata.cgi";
}
