$(document).ready(function () {

    //rotators
    $("#content_rotator_2 > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 8000);

    //languge selector
    $('#langswitch span').click(function () {
        if ($(this).text() == 'English') {
            window.location = window.location.toString().replace('_es', '');
        } else {
            if (window.location.toString().indexOf('_es') < 0) {
                window.location = window.location.toString() + '_es'
            }
        }
    });

    $('a.langswitch').click(function () {
        if ($(this).text() == 'English') {
            window.location = window.location.toString().replace('_es', '');
        } else {
            if (window.location.toString().indexOf('_es') < 0) {
                window.location = window.location.toString() + '_es'
            }
        }
    });
    
    if (window.location.toString().indexOf('_es') < 0) {
        $('#langswitch span').each(function (i, val) {
            if ($(val).text() == 'English') {
                $(val).addClass('alang');
            } else {
                $(val).removeClass('alang');
            }
        });
    } else {
        $('#langswitch span').each(function (i, val) {
            if ($(val).text() == 'English') {
                $(val).removeClass('alang');
            } else {
                $(val).addClass('alang');
            }
        });
    }
    
    //top zcode
    var zmessage = 'Enter Zip to Get a Quote';
    if ($('#zipsearch_es').length > 0) {
        zmessage = 'Entre Codigo Postal';
    }

    if ($('#zcode').val() == '' || $('#zcode').val() == zmessage) {
        $('#zcode').val(zmessage);
        $('#zcode').css({
            'color': '#666666'
        });
    }

    $('#zcode').focus(function () {
        if ($('#zcode').val() == zmessage) {
            $('#zcode').val('');
            $('#zcode').attr({
                maxlength: '5'
            });
        }
        $('#zcode').css({
            'color': '#333333'
        });
    });

    $('#zcode').blur(function () {
        if ($('#zcode').val() == '') {
            $('#zcode').css({
                'color': '#666666'
            });
            $('#zcode').attr({
                maxlength: ''
            });
            $('#zcode').val(zmessage);
        }
    });

    $('#zcode').keypress(function (e) {
        if ((e.which != 8 && e.which != 13) && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
});
