$j = jQuery.noConflict();
var special_font = [
            '#page_header_title h1',
            'div[class$=content] h2:not([class="faqh2"],[class="screen_reader"])',
            '.nav_root_item .rpText',
            '.tout .tout_content h3'
	    ];
var text_trademark = ["QT Rewards Discover Debit Card"];
$j(function ($) {
    //catchFontSize($j('a.screen_reader:first'));

    var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1&username=quiktrip';
    if (window.addthis) {
        window.addthis = null;
    }
    $j.getScript(script, function () {
        addthis.ost = 0;
        addthis.init();
        addthis.addEventListener('addthis.ready', add_this);
        addthis.addEventListener('addthis.menu.open', add_this);
    });

    for (i in text_trademark) {
        $j('div *:contains("' + text_trademark[i] + '")')
        .andSelf()
        .contents()
        .filter(function () {
            if (this.nodeType === 3) {
                return this;
            }
        })
        .filter(function () {
            // Only match when contains 'simple string' anywhere in the text
            if (this.nodeValue.indexOf(text_trademark[i]) != -1) {
                return this;
            }
        })
        .each(function () {
            var nodeValue = this.nodeValue;
            var word = "Discover";
            var to_add = '<sup>&#174;</sup>';
            var str = nodeValue.substr(0, nodeValue.indexOf(word) + word.length) + to_add + nodeValue.substr(nodeValue.indexOf(word) + word.length);
            //console.debug(str);
            $j(this).parent().html(str);
        });
    }

    for (i in special_font) {
        $j(special_font[i]).each(function () {
            $j(this).addClass('custom_font').addClass('typeface-js');
            if (!$j(this).hasClass('rpText')) {
                var elm_copy = $j(this).clone();
                elm_copy.removeClass("custom_font typeface-js").addClass('font_print').insertAfter($j(this));
            }
            //console.debug(elm_copy);
        });
    }
    var typeface = skin_path + "js/typeface-0.14.js";

    if (!is_user) {
        $j.getScript(skin_path + "js/helvetica_neue_lt_std_77_bold_condensed.typeface.js", function () {

            _typeface_js.renderDocument();
        });
    }
    //Stop Nav from running any JS

    $j('.nav_main a').keyup(function () {
        $j(this).children('span').eq(0).addClass('fake_focus');
    }).keydown(function () {
        $j(this).children('span').eq(0).removeClass('fake_focus');
    }).click(function (e) {
        e.stopPropagation();
    }).each(function () {
        $j(this).removeClass('rpExpandable');
    });

    $('#dnn_dnnSEARCH_txtSearch').val('Search'); //add the search text to the search input
    $("#dnn_dnnSEARCH_txtSearch").focus(function () { //clear the default text out of the search input
        if ($(this).val() == "Search") {
            $(this).val('');
        }
    }).blur(function () {
        if ($(this).val() == "") {
            $(this).val("Search");
        }
    });
});
function googleEventTrack(category, action, label, value) {
    if (window._gaq) {
        _gaq.push([category, action, label, value]);
    }
}
function catchFontSize(elm) {
    var initialSize = elm.css('fontSize');
    $j(window).resize(function (e) {
        var newSize = elm.css('fontSize');
        if (initialSize != newSize) {
            location.reload(true);
        }
    });
}
function name_add_this() {
    var add_this_div = $j('#_atssh');
    if (add_this_div.length > 0) {
        add_this_div.children('iframe').attr('title', 'Share with Add This');
    }
}
function add_this(evt) {
    switch (evt.type) {
        case "addthis.ready":
            var add_this_div = $j('#_atssh');
            if (add_this_div.children('iframe').length > 0) {
                add_this_div.children('iframe').attr('title', 'Share with Add This');
            }
            break;
        case "addthis.menu.open":
            if (evt.data.pane == "email") {
                var add_this_email = $j('#at20mc');
                if (add_this_email.length > 0) {
                    add_this_email.find('#at_to').focus();
                }
            }
    }
    
}
function qtprint() {
    for (i in special_font) {
        $j(special_font[i]).each(function () {
            $j(this).removeClass('typeface-js');
        });
    }
    window.print();
}
jQuery.fn.reverse = function() {
    return this.pushStack(this.get().reverse(), arguments);
};
String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}
function setValidationFocus($validationGroup) {
    if (typeof (Page_Validators) != "undefined") {
        for (var i = 0; i < Page_Validators.length; i++) {
            var val = Page_Validators[i];
            if (val != null) {
                if (val.validationGroup == $validationGroup) {
                    if (!val.isvalid) {
                        var controlId = val.controltovalidate;
                        var control = $j('#' + controlId);
                        if (control != null) {
                            control.focus();
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
