﻿//¤¤¤ ON LOAD EVENTS ¤¤¤

$(document).ready(function() {

    //.simplehover - Rollover effect on links
    $("a.simplehover img, img.simplehover").mouseover(function() {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function() {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });


    //fadehover - Rollover effect on links and images with FADE
    $("a.fadehover img, img.fadehover").mouseover(function() {
        $(this).stop(true, true).fadeTo(0, 0.5, function() {
            $(this).attr("src", $(this).attr("src").replace("-off.", "-on.")).fadeTo(500, 1);
        });
    }).mouseout(function() {
        $(this).stop(true, true).fadeTo(50, 0.5, function() {
            $(this).attr("src", $(this).attr("src").replace("-on.", "-off.")).fadeTo(50, 1);
        });
    });


    //Effect on thumbnails images.
    $("a.imagehover img, img.imagehover").mouseover(function() {
        $(this).fadeTo(0, 0.35);
        $(this).fadeTo(500, 1);
    });


    //Forms - Validation
    $("form").validity(function() {
        $(".txtname").require();
        $(".txttopic").require();
        $(".txtemail").require().match("email");
        $(".txttelephone").require().match("phone");
    });

    //Forms - French Language Pack for jValidity
    if (ReturnLanguage() == "fr") { $.extend($.validity.messages, { require: "Ce champ est requis.", phone: "Ce champ doit être de format ###-###-####", email: "Ce champ doit être un adresse courriel" }); }


    //Forms - Add effect when you just sent an form request. 
    $(".form-confirmation").effect("pulsate", { times: 3 }, 1000);

    //Make some input controls pretty. All those with the class .uniform
    $(".uniform").uniform();


    //¤¤ NOW WEBSITE CUSTOM ¤¤¤¤¤¤¤¤¤¤

    VerticalCenteringForIE();

    $('#sidebar').scrollFollow({offset: 60});

});


//¤¤¤ FUNCTIONS & UTILITIES ¤¤¤

function ReturnLanguage() {
    language = $(location).attr('href').substr($(location).attr('href').indexOf('/', 7) + 1, 2);
    return language;
}

function VerticalCenteringForIE() {
    $(".category-image").load(function() {
        $(this).css("top", ($(this).parent().height() - $(this).height()) / 2);
    }).each(function() {
        if (this.complete) $(this).trigger("load"); //Patch for IE cached images
    });
}

//parse URL to get values  - To retrieve example : var i = getUrlVars()["i"];
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
