// Google map ------------
function initialize() {
    var map = new google.maps.Map2(document.getElementById("map"));
    map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
  }


function googleMapGenerator( container, marker ) {
	window.onload = function() {
		var gMarkers = new Array();
		var geocoder = new GClientGeocoder();
		
		if( marker.lat == "" || marker.lng == "" ) {
			geocoder.getLatLng( marker.address, function( point ) {
				if( point == null ) {
					$( container ).innerHTML = "Aucune localisation disponible.";
				} else {
					createMap( new GMarker( point ) );
				}
			} );
		} else {
			createMap( new GMarker( new GLatLng( marker.lat, marker.lng ) ) );
		}

			
		function createMap( gMarker ) {
			var map = new GMap2( document.getElementById( container ) );
			map.setCenter( new GLatLng( 0, 0 ), 1 );
			map.addControl( new GSmallMapControl() );
			
			map.addOverlay( gMarker );
			map.setCenter( gMarker.getLatLng(), 16 );
		}
	}
}

//-------------------------------------
$( document ).ready( function() {
  checkMT();
} );

function checkMT() {
	var mts = $( 'a' );
	for( var i = 0; i < mts.length; i++ ) {
		var mt = mts[ i ].toString();
		var mto = mts[ i ];
		if( mt.substr( 7, 2 ) == 'mt' ) {
			mt = mt.substr( 10, ( mt.length - 10 ) );
			pos = mt.indexOf( '/' );
			var part3 = mt.substring( 0, pos );
			mt = mt.substr( (pos + 1), ( mt.length - ( pos + 1 ) ) );
			pos = mt.indexOf( '/' );
			var part1 = mt.substring( 0, pos );
			mt = mt.substr( (pos + 1), ( mt.length - ( pos + 1 ) ) );
			pos = mt.indexOf( '/' );
			var body = mt.substring( 0, pos );
			mto.href = 'mailto:' + part1 + '@' + mt.substr( (pos + 1), ( mt.length - ( pos + 1 ) ) ) + '.' + part3;
			if( mto.rel == 'body' ) {
				mto.innerHTML = part1 + '@' + mt.substr( (pos + 1), ( mt.length - ( pos + 1 ) ) ) + '.' + part3;
			}
		}
	}
}

function changeSidebarMenu( form_name ){
	$( '.sidebar_form' ).css( "display", "none");
	$( form_name ).css( "display", "block");
}

function switchDisplay( class_name ){
	if( $( class_name ).is(":hidden") ){
		$( class_name ).slideDown();
	} else {
		$( class_name ).slideUp();
	}
}

function changeForm2(){
	$( '#start_menu' ).fadeOut("slow");
	setTimeout("$( '#contest_menu' ).fadeIn(\"slow\")",1000);
}

var box = false;

function partners(){
	if( box == false ){
		$( '#close' ).css( 'display' , 'block' );
		$( '#partners' ).css( 'display' , 'block' );
		$( '#partner_title' ).css( 'width' , '490px' );
		$( '.white a' ).css( 'width' , '400px' );
		
		box = true;
	} else {
		$( '#close' ).css( 'display' , 'none' );
		$( '#partners' ).css( 'display' , 'none' );
		$( '.white a' ).css( 'width' , '121px' );
		$( '#partner_title' ).css( 'width' , '165px' );
		box = false;
	}
}

/***************************************************************
*
*	Top navigation rollover display
*
***************************************************************/

var tempo = 1;
var menuItemOpened = false;
var menuItemCloser = false;
var currentOpenItem = false;

function temporizeCloseItem( menuItem ) {
	// Si aucune menu n'est ouvert
	if( !menuItemOpened ) {
		// On ferme le menu sélectionné 
		$( '#' + menuItem ).fadeOut( 100 );
	}
}

function displayMenuItem( menuItem ) {
	// Si le menu ouvert est différent de celui à ouvrir
	if( currentOpenItem != menuItem ) {
		
		// On stock le menu à fermer
		var itemToClose = currentOpenItem;
		
		// On remet à zero le menu ouvert courant
		menuItemOpened = false;
		
		// On ferme le menu ouvert
		$( '#' + itemToClose ).fadeOut( 100 );
	}
	
	// Si aucun autre menu est ouvert
	if( !menuItemOpened ) {
		
		// On affiche le menu
		$( '#' + menuItem ).fadeIn( 100 );
		currentOpenItem = menuItem;
		
		// Si une tempo de fermeture de menu a été lancée
		if( menuItemCloser ) {
			window.clearTimeout( menuItemCloser );
			menuItemCloser = false;
		}
		
		// On renseigne le menu ouvert
		menuItemOpened = menuItem;
	}
}

function hideMenuItem( menuItem ) {
	
	// Si un menu est ouvert
	if( menuItemOpened ) {
		// On lance la temporisation de fermeture du menu
		menuItemOpened = false;
		menuItemCloser = window.setTimeout( "temporizeCloseItem( '" + menuItem + "' )", tempo );
	}
}

/* --------- SLIDESHOW ----------- */

var currentPicture = 0;
function switchPicture() {
	$( "#picture" + currentPicture ).fadeOut( 250, function() {
		currentPicture += 1;
		if( currentPicture == pictureCount ) {
			currentPicture = 0;
		}
		$( "#picture" +currentPicture ).fadeIn( 250, function() {
			setTimeout( "switchPicture()", 5000 );
		} );
	} );
}

var currentSlideshow = 1;
function slideshow() {
	currentSlideshow = Math.max( ( currentSlideshow + 1) % 5, 1);
	
	$( '#slideshow' ).attr( { src: "/wp-content/themes/tendancesbiere/images/slideshow/" + currentSlideshow + ".jpg" } );
	setTimeout( "slideshow()", 5000 );
}

var currentSlideshowBdC = 1;
function slideshowBdC() {
	currentSlideshowBdC = Math.max( (currentSlideshowBdC + 1) % 6, 1);
	
	$( '#slideshow-bdc' ).attr( { src: "/wp-content/themes/tendancesbiere/images/slideshow/bdc/" + currentSlideshowBdC + ".png" } );
	setTimeout( "slideshowBdC()", 5000 );
}

var currentSlideshowEC = 1;
function slideshowEC() {
	currentSlideshowEC += 1;
	if( currentSlideshowEC > 3 ) {
		currentSlideshowEC = 1;
	}
	
	$( '#slideshow-ec' ).attr( { src: "/wp-content/themes/tendancesbiere/images/slideshow/etienne_coralie/slide_" + currentSlideshowEC + ".png" } );
	setTimeout( "slideshowEC()", 5000 );
}

/* -------- PAGE QCM ---------------*/
function changeForm( form_id, tag ) {
	if( !$( '#menu_' + form_id ).hasClass( 'filter_on' ) ) {
		$( '#forms' ).fadeIn();
		$( '.menu_filter' ).removeClass( 'filter_on' );
		$( '.menu_filter' ).addClass( 'filter_off' );
		$( '.form' ).css( "display", "none");
		
		$( '#menu_' + form_id ).removeClass("filter_off");
		$( '#menu_' + form_id ).addClass("filter_on");
		$( '#form_' + form_id ).css( "display", "block");
		
		pageTracker._trackPageview( tag );
	}
}

var radiosToCheck = new Array();
function addRadioToCheck( qcmId, questionId ) {
	if( !radiosToCheck[ qcmId ] ) radiosToCheck[ qcmId ] = new Array();
	
	
	radiosToCheck[ qcmId ].push( questionId );
}

function isComplete( qcmId ) {
	var isComplete = true;
	for( var i=0 ; i < radiosToCheck[ qcmId ].length ; i++) {
		if( $('input[name=answer-' + radiosToCheck[ qcmId ][i] + ']:checked').length == 0)
			isComplete = false;
	}
	
	if( !isComplete) 

    Shadowbox.open({
        content:    '<table width="100%" height="100%"><tr><td valign="middle" align="center" style="font-weight:normal;font-style:italic;color:#CE2221;">Vous devez répondre à toutes les questions</td></tr></table>',
        player:     "html",
        title:      "Information",
        height: 80
    });
  
		
	return isComplete;
}