var liveString = "http://" + window.location.host;
        if (liveString.indexOf('localhost') > 0) {
            liveString = liveString + '/SPK_Web/webservices/';
        } else {
            liveString = liveString + '/';
        }

var contUsBodyWaterMark = "Message";
var contUsEmailWaterMark = "Courriel";
var contUsNameWaterMark = "Nom";
var contUsSendingMsg = "Envoi en cours...";
var contUsCompletedMsg = "Merci de votre intérêt!";
var contUsErrorMsg = "Cordonnier mal chaussé... Un problème est survenu, veuillez nous contacter par téléphone, merci.";
var contUsEmptyFieldsMsg = "Veuillez remplir tous les champs, merci.";

$(document).ready(function () {

    if ($("#nav").length > 0 && $("#nav").html().indexOf("Home") != -1) {
        contUsBodyWaterMark = "Message";
        contUsEmailWaterMark = "Email address";
        contUsNameWaterMark = "Name";
        contUsSendingMsg = "Sending...";
        contUsCompletedMsg = "Thanks for your interest!";
        contUsErrorMsg = "There was an error sending your request. Please contact us by phone.";
        contUsEmptyFieldsMsg = "All fields are mandatory.";
        $('body').addClass("en-body");
    }

    var path = location.pathname;

    $('a').filter(function () {
        return this.hostname && this.hostname !== location.hostname;
    })
  .click(function () {
      window.open(this.href);
      return false;
  });

   /* if ($(".en-body").length != 0) {
        $("#header-buttons-wrapper").prepend('<a id="lang-select" href="http://www.spektrummedia.com">FR</a>');
    } else {
        $("#header-buttons-wrapper").prepend('<a id="lang-select" href="http://en.spektrummedia.com">EN</a>');
    }*/

    var randomnumber = Math.floor(Math.random() * 6)

    if ($('#slider').length != 0) {
        $('#slider').cycle({
            fx: 'scrollUp',
            speed: 1500,
            timeout: 10000,
            pager: '#slider-nav',
            startingSlide: randomnumber + 1
        });
    }

    if ($('#home-articles-list').length != 0) {
        $('#home-articles-list').cycle({
            fx: 'fade',
            speed: 1500,
            timeout: 0,
            pager: '#articles-nav',
            cleartype: true,
            cleartypeNoBg: true
        });
    }

    if ($('#portfolio-images-list').length != 0) {
        $('#portfolio-images-list').cycle({
            fx: 'fade',
            speed: 1000,
            timeout: 5000,
            pager: '#portfolio-nav'
        });
    }
    if ($('#team-members-list').length != 0) {
        $('#team-members-list').cycle({
            fx: 'fade',
            speed: 1000,
            prev: '#prev',
            next: '#next',
            timeout: 10000,
            cleartype: true,
            cleartypeNoBg: true

        });
    }

    $("span.nav-button").hover(
    function () {
        $(this).addClass("nav-button-hover");
    },
    function () {
        $(this).removeClass("nav-button-hover");
    }
  );

    $("#contact-link").click(
    function () {
        if (!$('#footer-wrapper').is(":animated")) {
            if (!$("#contact-link").hasClass("open")) {
                $('#footer-wrapper').animate({
                    height: '360px'
                }, 1000, function () {
                    $("#contact-link").addClass("open");
                });
            } else {
                $('#footer-wrapper').animate({
                    height: '69px'
                }, 1000, function () {
                    $("#contact-link").removeClass("open");
                });
            }
        }
        return false;
    }
  );

    // Contact

    if ($('#contact_message').length != 0 && $('#contact_email').length != 0 && $('#contact_name').length != 0) {

        $('#contact_message').watermark(contUsBodyWaterMark, { className: 'watermark' });
        $('#contact_email').watermark(contUsEmailWaterMark, { className: 'watermark' });
        $('#contact_name').watermark(contUsNameWaterMark, { className: 'watermark' });

    }

    $("#contact-close").click(
      function () {
          if (!$('#footer-wrapper').is(":animated")) {
              if (!$("#contact-link").hasClass("open")) {
                  $('#footer-wrapper').animate({
                      height: '360px'
                  }, 1000, function () {
                      $("#contact-link").addClass("open");
                  });
              } else {
                  $('#footer-wrapper').animate({
                      height: '69px'
                  }, 1000, function () {
                      $("#contact-link").removeClass("open");
                  });
              }
          }
          return false;
      }
    );

    $('#send-email').click(function () {
        var message = cleanupValue($('#contact_message').val());
        var name = cleanupValue($('#contact_name').val());
        var email = cleanupValue($('#contact_email').val());
        if (message != '' && message != 'Message') {
            $('#contact_form').html('<p class="waiting-text">' + contUsSendingMsg + '</p>');
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: liveString + "webservices/spk.asmx/ContactUs",
                data: "{ message:  '" + message + "', name: '" + name + "', email: '" + email + "'}",
                dataType: "json",
                success: function (data) {
                    if (data.d == 'thx') {
                        //réussite
                        $('#contact_form').html(contUsCompletedMsg);
                    } else if (data.d == 'error') {
                        //fail
                        $('#contact_form').html(contUsErrorMsg);
                    } else {
                        $('#contact_form').html(contUsEmptyFieldsMsg);
                    }
                }
            });
        }
        return false;
    });

    // Contact

    // Evaluation

    $("#rating ul li a").hover(
        function () {
            $(".rating-subtext").hide();
            var elemId = $(this).attr("id");
            $("#rating-subtext-" + elemId.substring(elemId.length - 1)).show();
        },
        function () {
            $(".rating-subtext").hide();
        }
    );

    // Evaluation

    if (window.location.toString().indexOf("/en") != -1) {

        $("#slider div:nth-child(1)").click(function () {
            window.location = "http://www.spektrummedia.com/en/downloads";
            return false;
        });
        $("#slider div:nth-child(2)").click(function () {
            window.location = "http://www.spektrummedia.com/en/portfolio/quebec-international";
            return false;
        });
        $("#slider div:nth-child(3)").click(function () {
            window.location = "http://www.spektrummedia.com/en/services";
            return false;
        });
        $("#slider div:nth-child(4)").click(function () {
            window.location = "http://www.spektrummedia.com/en/portfolio/solutia-telecom";
            return false;
        });
        $("#slider div:nth-child(5)").click(function () {
            window.location = "http://www.spektrummedia.com/en/downloads";
            return false;
        });
        $("#slider div:nth-child(6)").click(function () {
            window.location = "http://www.spektrummedia.com/en/portfolio/ax6-immobilier";
            return false;
        });
        $("#slider div:nth-child(7)").click(function () {
            window.location = "http://www.spektrummedia.com/en/downloads";
            return false;
        });
        $("#slider div:nth-child(8)").click(function () {
            window.location = "http://www.spektrummedia.com/en/portfolio/cookning";
            return false;
        });

    } else {
      
        $("#slider div:nth-child(1)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/downloads";
            return false;
        });
        $("#slider div:nth-child(2)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/realisations/quebec-international";
            return false;
        });
        $("#slider div:nth-child(3)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/services/";
            return false;
        });
        $("#slider div:nth-child(4)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/realisations/solutia-telecom";
            return false;
        });
        $("#slider div:nth-child(5)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/downloads";
            return false;
        });
        $("#slider div:nth-child(6)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/realisations/ax6-immobilier";
            return false;
        });
        $("#slider div:nth-child(7)").click(function () {
            window.location = "http://www.spektrummedia.com/fr/downloads";
            return false;
        });
        $("#slider div:nth-child(8)").click(function () {
            window.location = "http://spektrummedia.com/fr/realisations/cookning";
            return false;
        });

    }

    // Trigger mouse move event over the 'menu_holder'.
    $("#portfolio-menu-slider").mousemove(function (e) {
        // Enable scroll function only when the height of the 'slider' or menu is greater than the 'menu_holder'.
        if ($(this).height() < $("#portfolio-menu").height()) {
            // Calculate the distance value from the 'menu_holder' y pos and page Y pos.
            var distance = e.pageY - $(this).offset().top;
            // Get the percentage value with respect to the Mouse Y on the 'menu_holder'.
            var percentage = distance / $(this).height();
            // Calculate the new Y position of the 'slider'.
            var targetY = -Math.round(($("#portfolio-menu").height() - $(this).height()) * percentage);
            // With jQuery easing funtion from easing plugin.
            $('#portfolio-menu').animate({ top: [targetY + "px", "easeOutCirc"] }, { queue: false, duration: 200 });
            // Without easeing function. by default jQuery have 'swing'.
            //$('#slider').animate({top: [targetY+"px", "easeOutCirc"]}, { queue:false, duration:200 });
        }
    });
    //stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
    if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
        $("#footer").css("position", "relative");
    };
});

function cleanupValue(stringValue)
{
    var myRegExp = new RegExp("'","g");
    var myResult = stringValue.replace(myRegExp, " ");
    return myResult;
}



