/*
*   site.js
*   Author: Medium
*   Choochoo Fly & Tackle
*   4/12/10
*/

(function($){
    var choochoo = {
        ready : function() {
            $('#id_name, #outfitted #id_email, #id_phone_area, #id_phone_first, #id_phone_second, #id_height_feet, #id_height_inches, #id_weight').addClass('reqd text');
            choochoo.selectElements();
            choochoo.placeholders();
            choochoo.sidebarGallery();
            if($.browser.msie)
              choochoo.zOutfitted();           
        },
        // Replace select elements with javascript
        selectElements : function() {
            if($('select').length && $('select').elect) {
                $('select').elect().each(function(i){
                    this.elect.con.css('z-index', 1000-i);
                });
            }
            $('ul.elect-options').mouseup(function(e){
              e.preventDefault();
              e.stopPropagation();
            });
        },
        // Placeholders for text inputs
        placeholders : function() {
            var inputs = $('input:text');
            inputs.each(function() {
                var input = $(this);
                var defaultText = input.val();
                input.focus(function() {
                    if(input.val() == defaultText) { input.val(''); }
                });
                input.blur(function() {
                    if($.trim(input.val()) == '') { input.val(defaultText); }
                });
            });
        },
        // Adjust the li height if it contains a gallery
        sidebarGallery : function () {
            $('li.sidebar-block div.image-gallery').each(function() {
                var ig = $(this);
                var images = ig.find('img');
                var num = images.size() % 2 == 1 ? parseInt(images.size()/2) + 1 : images.size()/2;
                var h = 130 * num;
                ig.parent('li').height(h+20);
            });
        },
        // Adjust z-index of outfitted versus all the others for ie7
        zOutfitted : function() {
          var o = $('#outfitted').closest('li.sidebar-block');
          o.css({'position': 'relative', 'z-index': 9999}).next().css({'position': 'relative'});
        }
    }
    $(document).ready(choochoo.ready);
})(jQuery)
