/* SACD 2008 */
/* COMMON JAVASCRIPT FUNCTIONS */

/* ENABLE ROLLOVER ON TARGETED IMAGES (ALL BROWSERS) */
function imgRollover(elt) {
    jQuery(elt).each( function() {
		jQuery(this).hover(
			function() {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-off","-on"));
			},
			function () {
				jQuery(this).attr("src", jQuery(this).attr("src").replace("-on","-off"));
			}
		);
	});
}

/* SAME HEIGHT FOR SAME CLASS ELEMENTS */
function sameHeight(elt) {
	var heightBlockMax=0;
	jQuery(elt).each(function(){ if( jQuery(this).height() > heightBlockMax ) heightBlockMax = jQuery(this).height(); }); // get max height
	if (jQuery.browser.msie) {
		if (parseInt(jQuery.browser.version) <= "6") {
			jQuery(elt).each(function(){ jQuery(this).css("height",heightBlockMax); }); // assign max height
		} else {
			jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
		}
	} else {
		jQuery(elt).each(function(){ jQuery(this).css("min-height",heightBlockMax); }); // assign max height
	}
	heightBlockMax=0;
}

/* FORM VALIDATION */
function formValidation(elt) {
	var currentForm = jQuery(elt).attr("id");
	currentForm = currentForm.split("F");
    jQuery(elt).RSV({
		errorFieldClass: "errorField",
		errorTextIntro: "Merci de corriger les erreurs suivantes :",
		rules: [
			"required,"+currentForm[0]+"LastName,Votre nom est obligatoire.",
			"required,"+currentForm[0]+"FirstName,Votre prénom est obligatoire.",
			"required,"+currentForm[0]+"JobName,Votre qualité est obligatoire.",
			"required,"+currentForm[0]+"Email,Votre email est obligatoire.",
			"valid_email,"+currentForm[0]+"Email,Une email valide est obligatoire."
		]
	});
}

/* SUCKERFISH DROPDOWN MENUS */
function mySuperfish(elt) {
	simpleScrollPane('.scrollPane');
	jQuery(elt).superfish({
		pathClass : 'current'
	}).find('ul').bgIframe();
}

/* SCROLLPANE IN DROPDOWN MENUS */
function simpleScrollPane(elt) {
	jQuery(elt).jScrollPane({scrollbarWidth : 12});
}

/* BOTTOM NAV AND LITTLE MEN POPUP */
function littleMenPopup(elt) {
	jQuery('.navMen').hide();
	jQuery(elt+' li a').hover(
		function () {
			var manToShow = jQuery(this).parent('li').attr('id');
			jQuery('#'+manToShow+'Man').show();
		},
		function () {
			jQuery('.navMen').hide();
		}
	);
}

/* BASIC HOME CAROUSEL */
function homeCarousel(elt) {
    jQuery(elt).cycle({
        fx: 'fade',
        speed: 1000,
	    timeout: 4000
    });
	jQuery(elt).addClass('carouselEnabled');
}

/* ACTIVITIES LISTING ROLLOVER */
function activitiesListing(elt) {
	jQuery('#activiteIllus li').addClass('offLeft');
	jQuery('#activiteIllus .item1').removeClass('offLeft');
	jQuery(elt+' .item1 a').addClass('activeItem');
	jQuery(elt+' li a').hover(
    	function() {
			jQuery('#activiteIllus li').addClass('offLeft');
			jQuery(elt+' li a').removeClass('activeItem');
			jQuery(this).addClass('activeItem');
    		var currentClass = jQuery(this).parent('li').attr('class');
			jQuery('#activiteIllus li.'+currentClass).removeClass('offLeft');
    	},
		function() {}
	);
}

/* REFERENCES CAROUSEL (REF, EXTRAS, ACTIVITIES, ETC) */
function refCarousel(elt) {
	// get total number of items
	var elementQuantity = jQuery(elt+' li').size();
	if (elementQuantity < 10) { elementQuantity = '0'+elementQuantity; }
	// display the counter
	jQuery('#counter').html('<strong>1</strong>/'+elementQuantity);
	// launch carousel
    jQuery(elt).cycle({
        fx: 'fade',
        speed: 300,
	    timeout: 0,
	    after:   onAfter,
	    next:   '.next',
	    prev:   '.prev'
    });
	function onAfter(curr, itemLength) {
        var currentId = this.id;
		var currentElement = currentId.split("f");
		// update counter
		jQuery('#counter').html('<strong>'+currentElement[1]+'</strong>/'+elementQuantity);
	}
	jQuery(elt).parent('div').addClass('carouselEnabled');
}

/* FAVORITES CAROUSEL AND CONTENT UPDATE */
function favCarousel(elt) {
	// launch carousel
    jQuery(elt).jCarouselLite({
        scroll: 1,
        btnNext: ".next",
        btnPrev: ".prev",
		visible: 4,
	    speed: 500
    }).addClass('carouselEnabled');
	myAjax();
}

function myAjax(){
    jQuery('#favInfos').wrap('<div id="favInfosContainer"></div>');

	function pageload(hash) {
        if(hash.substr(hash.length-3, hash.length) == "php") {
			jQuery("#favInfosContainer").load(hash.substr(0,hash.length-3) + ".php #favInfos",'',function(){
				jQuery('#favInfosContainer').show('normal');
				jQuery('#load').fadeOut('normal');
			});
		}
        else if(hash) {
			jQuery("#favInfosContainer").load(hash + ".html #favInfos",'',function(){
				jQuery('#favInfosContainer').show('normal');
				jQuery('#load').fadeOut('normal');
			 });
		}
		/*else {
			jQuery("#favInfosContainer").load("-Coups-de-coeur-.html #favInfos", '', function(){}); //default
		}*/
	}
	jQuery.historyInit(pageload);

	jQuery('#favCarousel li a').click(function(){

        var hash = jQuery(this).attr('href');
		hash = hash.replace(/^.*#/, '');
        if (hash.substr(hash.length-3, hash.length) == "php") {
			hash = hash.substr(0, hash.length-4) + "php";
		}
        else {
			hash = hash.substr(0,hash.length-5);
		}
		jQuery('#favInfosContainer').hide('fast',function(){jQuery.historyLoad(hash)});
		jQuery('#load').remove();
		jQuery('#content').append('<span id="load">LOADING...</span>');
		jQuery('#load').fadeIn('normal');
		return false;

	});
}

jQuery(document).ready(function() {

    /* ADD hasJS CLASS TO BODY FOR ABS/REL POSITIONNING */
	jQuery("body").addClass("hasJS");

    /* HIDE QUICK LINKS */
	jQuery('#quickAccess').addClass('offLeft');

    /* SUCKERFISH DROPDOWN MENUS */
    if (jQuery('ul#mainNav').size() > 0) { initMainNav = mySuperfish("ul#mainNav"); }

    /* BOTTOM NAV AND LITTLE MEN POPUP */
    if (jQuery('ul#secondNav').size() > 0) { initLittleMenPopup = littleMenPopup("ul#secondNav"); }

    /* HOME CAROUSEL */
    if (jQuery('#homeCarousel').size() > 0) { initHomeCarousel = homeCarousel('#homeCarousel'); }

    /* REF CAROUSEL */
    if (jQuery('#refCarousel').size() > 0) { initRefCarousel = refCarousel('#refCarousel ul'); }

    /* FAVORITES CAROUSEL */
    if (jQuery('#favCarousel').size() > 0) { initFavCarousel = favCarousel('#favCarousel'); }

    /* ACTIVITIES LISTING ROLLOVER */
    if (jQuery('#activitiesListing').size() > 0) { initActivitiesListing = activitiesListing('#activitiesListing'); }

    /* FORM VALIDATIONS */
    if (jQuery('#questionsForm').size() > 0) { initFormValidation = formValidation('#questionsForm'); }
    if (jQuery('#networkForm').size() > 0) { initFormValidation = formValidation('#networkForm'); }

    /* SAME HEIGHT ON ACTUS ELEMENTS */
    if (jQuery('#actusList li').size() > 0) { initSameHeight = sameHeight('#actusList li'); }

});























/* END */
