﻿//¤¤¤ 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();

    //Load client ribbon carousel : jquery.jcarousel.pack.js
    jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } };
    $('#ribboncarousel').jcarousel({ auto: 5, easing: 'BounceEaseOut', animation: 1000, wrap: 'last' });

    VerticalCenteringForIE();


    $('#slider').cycle({ fx: 'fade', timeout: 8000 });

});


//¤¤¤ 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
    });    
}
