$(document).ready(function () {

    /*$('#search-field').keyup(function () {
        var cleanedText = $('#search-field').val().replace('%', '');
        cleanedText = cleanedText.replace('*', '');
        cleanedText = cleanedText.replace('?', '');
        $('#search-field').val(cleanedText);
    });*/

    // Conditionally call the workaround for IE8 form submit
    //if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 8) {
    $('#search-field').keydown(function (e) {
        if (e.keyCode == 13) //enter
        {
            if ($('#search-field').val().length == 0 || $('#search-field').val() == 'Search for Author, Title, ISBN, or Keywords')
                return false;
            //$('#header-search').attr('action', '/searchresults/startx0xsizex5xsortx5/' + $('#search-field').val());
            window.location = '/searchresults/startx0xsizex5xsortx5/' + removesc($('#search-field').val());
        }
    });
    //};


    /* using this for select field overlap fix - google chrome doesn't like activeXOverlap function */
    var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

    /* ie 6 form select field overlap fix - see jquery-select-overlap.js and lt-ie7.css files */
    if (isIE6) {
        $(function () {
            $('.overlap-fix').activeXOverlap();
        });
    }

    jQuery.fn.activeXOverlap = function () {

        $(this).each(function (i) {
            var h = $(this).outerHeight();
            var w = $(this).outerWidth();
            var iframe = '<!--[if IE 6]>' +
						  '<iframe src="javascript:false;" style="height: ' +
						  h +
						  'px; width: ' +
						  w +
						  'px" class="selectOverlap">' +
						  '</iframe>' +
						  '<![endif]-->'
            $(this).prepend(iframe);
        });
    }

    /* jquery cycle */
    $('#rotating-images').cycle({
        fx: 'fade',
        timeout: 6000,
        speed: 1000,
        delay: -2000,
        pause: 1,
        pager: '#rotating-images-pagination',
        pagerAnchorBuilder: function (idx, slide) {
            return '#rotating-images-pagination li:eq(' + idx + ') a';
        }
    });

    /* easy list splitter */
    $('.split-list').easyListSplitter({
        colNumber: 3,
        direction: 'vertical'
    });

    /* jcarousel */
    $('#carousel').jcarousel({
        wrap: 'circular',
        scroll: 1
        /*,
        animation: "fast",
        auto: 6
        */
    });

    /* form field default value toggle */
    $('.default-value').each(function () {
        var default_value = this.value;
        $(this).css('color', '#bababa'); /* this could be in the style sheet instead */
        $(this).focus(function () {
            if (this.value == default_value) {
                this.value = '';
                $(this).css('color', '#000');
            }
        });
        $(this).blur(function () {
            if (this.value == '') {
                $(this).css('color', '#bababa');
                this.value = default_value;
            }
        });
    });

    /* auto select value in form input fields */
    $('input[type=text]').focus(function () {
        $(this).select();
    });

    /* remove onfocus outline for button */
    $('button').focus(function () {
        $(this).blur();
    });

    $('#go-button').click(function () {
        if ($('#search-field').val().length == 0 || $('#search-field').val() == 'Search for Author, Title, ISBN, or Keywords')
            return false;
        //$('#header-search').attr('action', '/searchresults/startx0xsizex5xsortx5/' + $('#search-field').val());
        window.location = '/searchresults/startx0xsizex5xsortx5/' + removesc($('#search-field').val());
    });

    /* jquery mega menu */
    $('#global-nav, #utility-nav').megamenu();

    /* stop blinking cursor from showing through mega menu in ie6 */
    $('#utility-nav li#un-link03 a.mm-item-link').hover(function () {
        //alert("blah!");
        $('#search-field, #zip-field').blur();
    });

    /* conditionally apply DD_roundies */
    /* check if msie in one statement */
    if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 8) {
        // do nothing in ie8...
    } else {
        /* dynamically create rounded corners in all browsers except for ie8 - note: second argument in addRule() controls the values for topleft, topright, bottomright, and bottomleft */
        DD_roundies.addRule('#new-releases-scroll-bar, #new-nursing-titles-scroll-bar, .content-about, .content-mobile, .content-press, .content-product, .content-resource, .content-search, .content-static, .content-login02, #advanced-search, .content-subject', '0 0 0 32px', true);
        DD_roundies.addRule('#rep-locator, #ad-area, .module-wrap-189, .module-wrap-189b, .module-wrap-189c, .module-wrap-210, .module-wrap-210b, .module-wrap-229, .module-wrap-289, #follow-us', '0 22px 0 0', true);
        DD_roundies.addRule('.content-login02 div, #full-column form#createaccount div#account-details, #full-column form#createaccount div#order-preferences, #full-column form#manage-account-details div#account-details, #full-column form#orderpreferences div#order-preferences, #full-column div#purchase-history, #full-column div#my-reviews', '22px 22px 22px 22px', true);
        DD_roundies.addRule('#enter-promotional-code', '8px 8px 8px 8px', true);
        DD_roundies.addRule('.error-message', '4px 4px 4px 4px', true);
    }
    if (!jQuery.browser.msie) {
        /* apply DD_roundies first and last tabs in other browsers except for msie. note: the rounded corners on the tabs prevented the tab gradient background from changing properly when clicked in ie*/
        DD_roundies.addRule('#tabs ul#tabs-nav li.first', '22px 0 0 0', true);
        DD_roundies.addRule('#tabs ul#tabs-nav li.last', '0 22px 0 0', true);
    }

    /* expanding modules */
    $('.expand-189').click(function () {
        $('.module-189').toggleClass('big')
        $(this).toggleClass('reduce');
    });
    $('.expand-189b').click(function () {
        $('.module-189b').toggleClass('big');
        $(this).toggleClass('reduce');
    });
    $('.expand-189c').click(function () {
        $('.module-189c').toggleClass('big');
        $(this).toggleClass('reduce');
    });
    $('.expand-210').click(function () {
        $('.module-210').toggleClass('big');
        $(this).toggleClass('reduce');
    });
    $('.expand-210b').click(function () {
        $('.module-210b').toggleClass('big');
        $(this).toggleClass('reduce');
    });
    $('.expand-229').click(function () {
        $('.module-229').toggleClass('big');
        $(this).toggleClass('reduce');
    });
});

function abouttabclicks(cntid) { $('.abouttaba').removeClass('selected'); $('#abouttaba' + cntid).addClass('selected'); $('.abouttabc').hide(); $('#abouttabd' + cntid).show(); } function forgotclicks(fm) { $('#formtype').val('forgot'); $('#' + fm).submit(); } function validateemail(fm, fld, actiontype) { $('#' + fld).val(actiontype); $('#' + fm).submit(); } function sameaddresschecked(fldnm) { if ($('#' + fldnm).is(':checked')) $('.shippings').attr("disabled", true); else $('.shippings').removeAttr("disabled"); } function printconfirm() { $('#page-head').hide(); $('#page-foot').hide(); window.print(); } function removesc(stext) { okchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- ";    var sreturn= ""; for (var x = 0; x < stext.length; x++) { var c = stext.charAt(x); if(okchars.indexOf(c) >=0) sreturn += c;}return sreturn;}
    
