/* Create a namespace */
var Uncrustables = {};

//try to eliminate IE 6 flicker
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/* Modal windows */
var myModalShow = function(hash) {
    hash.w.show();
};
var myModalHide = function(hash) {
    $("div#modal-pop").removeClass("jqmWindowWide");
    hash.w.hide();
    hash.o.remove();
}
Uncrustables.enableModalPop = function() {
$('#footer').before('<div id="modal-pop" class="jqmWindow"><div id="modal-pop-top"></div><div id="modal-pop-content"><div id="jqmAjaxTarget"></div><a href="#" class="jqmClose" onclick="pageTracker._trackEvent(\'why\', \'close\');">Close Window</a></div><div id="modal-pop-bot"></div></div>');
    $('#modal-pop').jqm({
        modal: true,
        ajax: '@href',
        trigger: 'a.open-modal',
        target: 'div#jqmAjaxTarget',
        toTop: true,
        onShow: myModalShow,
        onHide: myModalHide
    });

    $("a#termspop").click(function() {
        $("#modal-pop").addClass("jqmWindowWide");
    });

};

/* Initialize everything when page is ready */
$(document).ready(function() {
	$("#producttabsinner").tabs();
	Uncrustables.enableModalPop();
})


/*------------------------------------------------------------------------------
Get Query String Parameters
------------------------------------------------------------------------------*/

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

/* Homepage Facebook Twitter tabs */
$(document).ready(function() {
    $('#social_media div.tab:not(:first)').hide()

    $('.social_media_nav li').click(function(e) {
        $('#social_media div.tab').hide();
        $('.social_media_nav .current').removeClass("current");
        $(this).addClass('current');

        var clicked = $(this).find('a:first').attr('href');
        $('#social_media ' + clicked).show();
        e.preventDefault();
    }).eq(0).addClass('current');
});
