function gebid(id) {
	return document.getElementById(id) ;
}

function get_cookie( cookie_name ) {
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

// --- start slideshow pro controls
/*
	Passes the ID of the album from the XML file
	we want SlideShowPro inside the SWF to load
*/

function wopen(url, name, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  name, 
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}

function sspToggleDisplayMode() {
	thisMovie("ssp").sspToggleDisplayMode();
}

function sspLoadAlbum(album) {
	thisMovie("ssp").sspLoadAlbum(album);
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
	    return document[movieName]
	}
}

function load_slideshow(id) {
	if($('slideshow')!=null) {
		var so = new SWFObject("/images/slideshow/slideshow.swf", "ssp", "657", "329", "8", "#000000");
		
		so.addParam("allowScriptAccess", "always");
		so.write("slideshow");
		
	}
}

function show_slideshow(id) {
	new Effect.Appear('slideshow', {duration: 0.5});
	
	// if the slideshow is hidden, load the flash first
	if(!$('slideshow').visible()) {
		setTimeout('load_slideshow();', 500);
		setTimeout('sspLoadAlbum(\''+id+'\');', 3000);
	}
	else {
		sspLoadAlbum(id) ;
	}
}

// --- end slideshow pro controls

function toggle_services(event) {
	var clicked_id 		= Event.element(event).id ;
	var id_to_toggle	= clicked_id + '-text' ;
	
	// chage bullet
	if($(id_to_toggle).visible())
		$(clicked_id).removeClassName('active') ;
	else
		$(clicked_id).addClassName('active') ;

	// toggle
	new Effect.toggle(id_to_toggle, 'blind', {duration: .5}) ;
}

function init_services_links() {
	if($('services-conseil')!=null)
		Event.observe('services-conseil', 	'click', toggle_services);
		
	if($('services-achat')!=null)
		Event.observe('services-achat', 	'click', toggle_services);
	
	if($('services-expertise')!=null)
		Event.observe('services-expertise',	'click', toggle_services);
	
	if($('services-ventes-publiques')!=null)
		Event.observe('services-ventes-publiques',	'click', toggle_services);
	
	if($('services-materiel')!=null)
		Event.observe('services-materiel', 	'click', toggle_services);
	
	if($('services-catalogue')!=null)
		Event.observe('services-catalogue', 'click', toggle_services);
}

function target_blank() {
    $$('a:([rel~=new])').each(function(link) {
      link.onclick = function(){window.open(this.href); return false;};
    });
}

function set_language_cookie() {
	var lg = document.location.pathname.substr(1,2) ;
	document.cookie = "lg="+lg+"; expires=13/06/2099 00:00:00;";
}

// start javascript slideshow
var slides = new Array('intro-coin-1', 'intro-coin-2', 'intro-coin-3', 'intro-coin-4', 'intro-coin-5') ;
var i = 0;
var last_index = slides.length  ;
var wait = 5000;

function SlideShow() {
	Effect.Fade(slides[i], { duration:1.5, from:1.0, to:0.0 }); 
	i++;
 	if (i == last_index) i = 0; 
		Effect.Appear(slides[i], { duration:1.5, from:0.0, to:1.0 });
 } 

// the onload event handler that starts the fading. 
function start_js_slideshow() {
	if($('intro-coin')!=null)
		setInterval('SlideShow()',wait);
}

// end javascript slideshow

function init() {
	set_language_cookie() ;
	// load_slideshow() ;
	init_services_links() ;
	start_js_slideshow() ;
	target_blank() ;
}

Event.observe(window, 'load', init) ;

