﻿$(document).ready(
    function () {
        adjustStyle();
        $(window).resize(function () {
            adjustStyle();
        });

        $('a.lang').click(function () {
            $.ajax(
                  {
                      url: "/ajax/SwitchLanguage.ashx",
                      type: "POST",
                      data: {
                          url: location.href
                      },
                      cache: false,
                      dataType: 'text',
                      timeout: 10000,
                      error: function (XMLHttpRequest, textStatus, errorThrown) {
                          alert(textStatus)
                      },
                      success: function (newurl) {
                          location.href = newurl;
                      }
                  }
            );
        });
    }
);

function trackGAEvent(ec, ev, el) {
    try {
        _gaq.push(['_trackEvent', ec, ev, el]);
    } catch (e) { }
}

function adjustStyle() {
    var vp = getViewport();
    if (vp.width <= 1024) {
        $('body').addClass('w1024');
        $('.footer').css('position', 'relative');
    }
    else {
        $('body').removeClass('w1024');

        if (vp.height >= 800 && $('link[href*="approach.css"]').length == 0) {
            $('.footer').css('bottom', '0px');
            $('.footer').css('position', 'fixed');
        }
        else {
            $('.footer').css('position', 'relative');
        }
    }
}

function getViewport(){
    var e = window
    var a = 'inner';

    if (!('innerWidth' in window)) {
        a = 'client';
        e = document.documentElement || document.body;
    }

    return { width: e[a + 'Width'], height: e[a + 'Height'] };
}
