﻿$(document).ready(function () {

    //sets the selected tab according to pagename, if tab exists
    if (getCurrentPageName().length != 0) {
        $("#tab_" + getCurrentPageName()).addClass("active");
    }

    var mouse_is_insideflyoutpanel; 

    $(".trigger").click(function () {
        $(".panel").toggle("fast");
        $(this).toggleClass("active");
        return false;
    });

    $('table.comparison').hover(function () {
        mouse_is_insideflyoutpanel = true;
    }, function () {
        mouse_is_insideflyoutpanel = false;
    });

    $('.trigger').hover(function () {
        mouse_is_insideflyoutpanel = true;
    }, function () {
        mouse_is_insideflyoutpanel = false;
    });

    $("body").mouseup(function () {
        if (!mouse_is_insideflyoutpanel) {
            $('.panel').hide("fast");
            $(".trigger").removeClass("active");
        }
    });
});

// Gets current pagename
function getCurrentPageName() {
    var sPath = window.location.pathname;
    var pageName = sPath.substr(1, sPath.lastIndexOf('.') - 1);

    return pageName;
}

//Google analyitics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2131177-4']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

function getQueryString() {
    var result = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m;
        
    while (m = re.exec(queryString)) {
        result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
    }
        
    return result;
}
