﻿document.write('<style type="text/css">'
 + '.modalTipContent { display:none; }'
 + '.tooltip { visibility: hidden; }'
 + '</style>');

(function ($) {

    // set default colorbox settings
    $.extend($.fn.colorbox.settings, { opacity: 0.65, transition: 'none', width: 500 });

    var isie6 = $.browser.msie && $.browser.version.substr(0, 1) < 7 ? true : false;

    $(document).ready(function () {

        if (!isie6) {
            $('select.styled, .checkoutBody select, .affiliateBody select, .createAccountBody select, .styledDropDown select').each(function (idx, el) {
                var text = $(el).find('option[value=' + $(el).val() + ']').text();
                $(el).addClass('styled');
                var className = "select";
                if ( $(this).hasClass('input-validation-error') ) {
                    className += " select-input-validation-error";
                }
                $(el).wrap('<span class="selectWrapper" />');
                $(el).before('<span class="' + className + '" style="width: ' + $(el).width() + 'px;"><span>' + text + '</span></span>');
            }).change(function () {
                var text = $(this).find('option[value=' + $(this).val() + ']').text();
                $(this).prev('.select').html('<span>' + text + '</span>');
            }).keydown(function(e) {
                if (e.keyCode == '38' || e.keyCode == '40') {
                    $(this).change();
                }
            }).focus(function() {
                $(this).prev('.select').addClass("selectActive");
            }).blur(function() {
                $(this).prev('.select').removeClass("selectActive");
            });
        }

        $('.toggleSelect select').bind('change', function() {
            $(this).children('option').each(function(idx, el) {
                if ($(this).attr('value') != '')
                    $('#' + $(this).attr('value')).hide();
            });
            if ($(this).val() != '')
                $('#' + $(this).val()).show();
        });
        $(document).ready(function(){
            $('.toggleSelect select').change();
        });

        $(".styledButton").mouseover(function () {
            $(this).addClass("styledButtonOver");
        }).mouseout(function () {
            $(this).removeClass("styledButtonOver");
        }).click(function() {
            //$(this).find('button[type=submit]').closest('form').submit();
        });

        $("input[type=password].iphoneStyle")
            .after('<span class="letterViewer" style="display:none;" />')
            .keypress(function (e) {
                var characterCode = e.which;
                if (characterCode >= 33 && characterCode <= 126) {
                    $(this).next(".letterViewer")
                        .html(String.fromCharCode(e.which))
                        .fadeIn(200, function () {
                            $(this).fadeOut(200);
                        });
                }
            });

        $('.labelInsideTextarea').labelInsideTextarea();
        $('.moreInformation').each(function (i, el) {
            $(el).hoverIntent({
                sensitivity: 3,
                interval: 1,
                timeout: 200,
                over: function () {
                    $(this).children('.moreInfoContent').fadeIn();
                },
                out: function () {
                    $(this).children('.moreInfoContent').fadeOut();
                }
            });
            $(el).children('.moreInfoContent').css({
                top: '-' + ($(el).children('.moreInfoContent').outerHeight()) + 'px'
            });
        });
        $('.tooltip').tooltip({ showBody: " - ", showURL: false }).each(function (i, el) {
            //var src = "#" + $(el).attr("href").split("#")[1];
            $(el).html("&nbsp;").css({
                  visibility: 'visible'
            });
        });

        $('a.inlineTooltip').tooltip({
            bodyHandler: function() { 
                return $($(this).attr("href")).html(); 
            }, 
            extraClass: "wideTooltip",
            showURL: false 
        }).html('&nbsp;');

        $('a.modalTip').each(function (idx, el) {
            $(el).colorbox({ inline: true, href: $(el).attr('href') });
        });

        $('select[name=NumberOfStars]').each(function (i, element) {
            var options = "";
            var $selectBox = $(this);
            $selectBox.hide();
            var $selectStars = $('<div class="selectStars">' + options + '</div>');
            $(this).children('option').each(function (i, el) {
                var val = $(el).val();
                if (val) {
                    var $star = $('<span class="star star' + val + '">' + val + '</span>').click(function () {
                        var prevVal = $selectBox.val();
                        $selectBox.val(val);
                        $(this).parent().removeClass('starSelected' + prevVal);
                        $(this).parent().addClass('starSelected' + val);
                        $(this).mouseout();
                    }).mouseover(function () {
                        $(this).addClass('starOver');
                        $(this).parent().addClass('selectStarsOver');
                    }).mouseout(function () {
                        $(this).removeClass('starOver');
                        $(this).parent().removeClass('selectStarsOver');
                    });
                    $selectStars.append($star);
                }
            });
            $(element).before($selectStars);
        });

    });

    $.fn.labelInsideTextarea = function () {
        return this.each(function () {
            var $container = $(this);
            var $label = $container.children("label");
            var $field = $('#' + $label.attr('for'));
            if ($field) {
                if ($field.val()) {
                    $label.hide();
                }
                $field.focus(function () {
                    $label.hide();
                }).blur(function () {
                    if (!$(this).val()) $label.show();
                });
            }
        });
    };
})(jQuery);

