// VARS *******************************************************************************************
// Path to root directory - prepends to images
var path = { 'root' : '' };
var language = { 'root' : '/fr' };
if (local_path == null) {
	var local_path = { 'root' : '' };
}

// Images needed for rollovers
// May be extended later - Will be then reloaded using img.load()
var a_imgs;
function init_a_imgs(){
    a_imgs = [
	    {'id'		: 'nav_0',
	     'src'		: '/images' + language['root'] + '/nav' + local_path['root'] + '/0.gif',
	     'src_over'	: '/images' + language['root'] + '/nav/0_over.gif'},
	    {'id'		: 'nav_1',
	     'src'		: '/images' + language['root'] + '/nav' + local_path['root'] + '/1.gif',
	     'src_over'	: '/images' + language['root'] + '/nav/1_over.gif'},
	    {'id'		: 'nav_2',
	     'src'		: '/images' + language['root'] + '/nav' + local_path['root'] + '/2.gif',
	     'src_over'	: '/images' + language['root'] + '/nav/2_over.gif'},
	    {'id'		: 'nav_3',
	     'src'		: '/images' + language['root'] + '/nav' + local_path['root'] + '/3.gif',
	     'src_over'	: '/images' + language['root'] + '/nav/3_over.gif'},
	    {'id'		: 'webcam',
	     'src'		: '/images' + language['root'] + local_path['root'] + '/webcam.gif',
	     'src_over'	: '/images' + language['root'] + local_path['root'] + '/webcam_over2.gif'}
    ];


    // Loading Webcam Menu image
    a_imgs[a_imgs.length] = {
	    'id'		: 'menu_webcam',
	    'src'		: '/images' + language['root'] + local_path['root'] + '/menu_webcam.gif',
	    'src_over'	: '/images' + language['root'] + local_path['root'] + '/menu_webcam_over.gif'
    }
}

// IMG OBJECT ****************************************************************************
function img_object() {
	this.path		= path['root'];
	this.loaded		= false;
	this.bdd		= [];
	this.load		= img_load;
	this.roll		= img_roll;
}

function img_load() {
	init_a_imgs();
	if (!a_imgs.length) return;
	try {
		with (this) {
			for (i=0;i<a_imgs.length;i++) {
				bdd[a_imgs[i]['id']]		= new Array(2);
				bdd[a_imgs[i]['id']][0]		= new Image();
				bdd[a_imgs[i]['id']][0].src	= a_imgs[i]['src'];
				bdd[a_imgs[i]['id']][1]		= new Image();
				bdd[a_imgs[i]['id']][1].src	= a_imgs[i]['src_over'];
			}
			loaded = true;
		}
	} catch (e) {};
	
}

function img_roll(s_id,b_over) {
	if (this.loaded) {
		try {
			document.getElementById(s_id).src = this.bdd[s_id][b_over?1:0].src;
		} catch (e) {};
	}
}

var img = new img_object();

// MENU OBJECT ***************************************************************************
function menu_object() {
	this.count		= null;
	this.current	= null;
	this.opened		= false;

	this.set		= menu_set;
	this.init		= function (n_count, n_menu) {
					      this.count = n_count;
						  if (n_menu!=null) this.set(n_menu);
					  };
}

function menu_set(n_menu) {
	// Close opened menu
	if (this.current == n_menu) {
		this.opened = !this.opened;
		document.getElementById("menu_sub_"+n_menu).style.display = (this.opened) ? 'block' : 'none';
		return;
	}
	// No opened menu
	if (this.current!=null) {
		document.getElementById("menu_sub_"+this.current).style.display = 'none';
	}
	// Open current menu
	this.current	= n_menu;
	document.getElementById("menu_sub_"+this.current).style.display = 'block';
	this.opened 	= true;
}

var menu = new menu_object();

function insertFlash( strSrc, intWidth, intHeight, strAlt, strID ){
    var strFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
                    'width="' + intWidth + '" height="' + intHeight + '" title="' + strAlt + '"' + (strID != '' ? ' id="' + strID + '"' : '') + '>' +
                    '<param name="movie" value="' + strSrc + '" />'+
                    '<param name="quality" value="high" />'+
                    '<param name="wmode" value="transparent" />'+
                    '<param name="menu" value="false" />'+
                    '<embed src="' + strSrc + '" width="' + intWidth + '" height="' + intHeight + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"' + (strID != '' ? ' name="' + strID + '"' : '') + ' swLiveConnect="true"></embed>'+
                    '</object>';
    document.write(strFlash);
    document.close();
}

function insertFlashCartoG( strSrc, intWidth, intHeight, strAlt, strID, lg ){
    var strFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
                    'width="' + intWidth + '" height="' + intHeight + '" title="' + strAlt + '"' + (strID != '' ? ' id="' + strID + '"' : '') + '>' +
                    '<param name="movie" value="' + strSrc + '" />'+
                    '<param name="quality" value="high" />'+
                    '<param name="menu" value="false" />'+
                    '<embed src="' + strSrc + '" width="' + intWidth + '" height="' + intHeight + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" ' + (strID != '' ? ' name="' + strID + '"' : '') + ' swLiveConnect="true"></embed>'+
                    '</object>';
    document.write(strFlash);
    document.close();
}

var updateDropDownList = function(result, context){
    $get(context).innerHTML = result;
}

function getExportLecteurFlash(idtext,idprevisu,strSrc,ratio,intWidth, intHeight, idBtPrevisuOn,idtailles)
{
    intWidth=intWidth * ratio;
    intHeight=intHeight * ratio;
    var tb = document.getElementById(idtext);
    var strFlash = '<div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' +
                    'width="' + intWidth + '" height="' + intHeight + '" title="www.picardietourisme.com">' +
                    '<param name="movie" value="' + strSrc + '" />'+
                    '<param name="quality" value="high" />'+
                    '<param name="menu" value="false" />'+
                    '<param name="wmode" value="transparent" />'+
                    '<embed wmode="transparent" src="' + strSrc + '" width="' + intWidth + '" height="' + intHeight + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" name="www.picardietourisme.com" swLiveConnect="true"></embed>'+
                    '</object></div>';
                    
    if(document.getElementById(idtailles))
    {
        document.getElementById(idtailles).innerHTML = intWidth+'*'+intHeight;
    }         
    if (document.getElementById(idtext))
    {
        if (document.getElementById(idtext).value=="")
        {
            if (document.getElementById(idBtPrevisuOn))
                document.getElementById(idBtPrevisuOn).style.display='block';
        }
        document.getElementById(idtext).value = strFlash;
    }
    if (document.getElementById(idprevisu))
        document.getElementById(idprevisu).innerHTML = strFlash;
    
}

function updateDisplay(id)
{
    if (document.getElementById(id).style.display=='block')
    {
        document.getElementById(id).style.display='none';
    }
    else
    {
        document.getElementById(id).style.display='block';
    }
}

function changeNote(note){

	document.getElementById("spanChangeNote").className="note"+note;
	document.getElementById("spanNoteFinale").innerHTML="("+note+")";
	//document.getElementById(hidNote).value=note;
	document.getElementById("hidNote").value=note;
}

function saveVote(id){

note=document.getElementById("hidNote").value;

if(window.XMLHttpRequest) // Firefox 
	   xhr= new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
	   xhr= new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	 return; 
	}
var url=  "http://www.picardietourisme.com/aspx/nos-idees-de-weekend/nos-suggestions/saveVote.aspx?id="+id+"&note="+note;
xhr.open("GET",url,false);
    xhr.send("");
if (xhr.readyState == 4 && xhr.status == 200) {
          var contenu = xhr.responseText;
         // url=document.location
       document.location.reload();
       return(false);
          
    }else{
		alert("Problème lors de l'enregistrement de votre note.")
    }

}