jQuery(document).ready(function() {
    resize_content();
    jQuery('#wrapper_menu ul').superfish();
    $('#select_other_websites').jSelect_lien();

    var opacity = 0.7, toOpacity = 1.0, duration = 100;
    //set opacity ASAP and events
    $('img.fade_over').css('opacity',opacity).hover(function() {
            $(this).fadeTo(duration,toOpacity);
        }, function() {
            $(this).fadeTo(duration,opacity);
        }
    );
});
$(window).resize(function(){
    resize_content();
});

function resize_content() {
    create_stripes();
    var W = $( window ).width();
    var limit_width = 996 + 41 + 41;
    if (W < limit_width) {
        $('#menu_gauche').hide();
        $('#menu_droite').hide();
    } else {
        $('#menu_gauche').show();
        $('#menu_droite').show();
    }
    //alert(W);
}

function create_stripes() {
    var W = $( window ).width();
    $('body').append('<div id="stripes"></div>');
    $('#stripes').width(W);
}

function intval (mixed_var, base) {

    var type = typeof( mixed_var );

    if (type === 'boolean') {        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}

function diaporama_toggle(el, id) {
    $('div#diapo_3 > div').hide(); // On cache le niveau 3
    $('div#diapo_help').hide();
    if (!$(el).attr('rel')) {
        $('div#diapo_2 > div > div').removeClass('selected');
    }
    $(el).parents('div:first').addClass('selected').siblings().removeClass('selected');
    $(id).toggle('fade').removeClass('selected').siblings().hide(); // On affiche celle du niveau souhaité + on cache les autres
    return false;
}

	// Cross-browser xml parsing
	// (xml & tmp used internally)
	function parseXML ( data , xml , tmp ) {

		if ( window.DOMParser ) { // Standard
			tmp = new DOMParser();
			xml = tmp.parseFromString( data , "text/xml" );
		} else { // IE
			xml = new ActiveXObject( "Microsoft.XMLDOM" );
			xml.async = "false";
			xml.loadXML( data );
		}

		tmp = xml.documentElement;

		if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
			jQuery.error( "Invalid XML: " + data );
		}

		return xml;
	}
