/* --- FLASH --- */
swfobject.embedSWF('swf/loader.swf', 'mapSWF', '100%', '100%', '9.0.115', 'swf/expressInstall.swf', {content: 'swf/map.swf', data: 'swf/map_data.xml'});


/* --- DOM READY --- */
$(function(){
    $('.focusable').focusable();
    $('.text.focusable').focusable('text');
    $('.placeholder').placeHolder();
    $('.profile .button-file').fileButton();
    $('.profile').profileEdit();
});


/* --- PLUGINS --- */
// hoverable
(function($){
$.fn.hoverable = function(settings){
    var classPrefix = settings ? settings + '-' : '';
    this.each(function(){
        var el = $(this);
        el.hover(
            function(){
                el.removeClass('hover');
                el.addClass(classPrefix + 'hover');
            },
            function(){
                el.removeClass(classPrefix + 'hover');
            }
        );
    });
    return this;
};
})(jQuery);


// focusable
(function($){
$.fn.focusable = function(settings){
    var classPrefix = settings ? settings + '-' : '';
    this.each(function(){
        var el = $(this);
        $('input', el).focus(function(){
            el.removeClass('focus');
            el.addClass(classPrefix + 'focus');
        }).blur(function(){
            el.removeClass(classPrefix + 'focus');
        });
    });
    return this;
};
})(jQuery);


// placeHolder
(function($){
$.fn.placeHolder = function(){
    this.each(function(){
        var label = $(this),
            labelFor = label.attr('for'),
            labelClass = label.attr('class'),
            labelText = label.html(),
            input = $('#'+labelFor);

        input.addClass(labelClass).val(labelText).focus(function(){
            input.removeClass(labelClass);
            if (input.val() == labelText) input.val('');
        }).blur(function(){
            if (input.val() == '') input.val(labelText).addClass(labelClass);
        });
    });
    return this;
};
})(jQuery);


// fileButton
(function($){
$.fn.fileButton = function(settings){
    this.each(function(){
        var el = $(this);
        el.css({
            'position': 'relative',
            'overflow': 'hidden'
        }).find('input:file').css({
            'height': '100%',
            'right': 5,
            'top': 0,
            'position': 'absolute',
            'cursor': 'pointer',
            'opacity': 0
        }).change(function(){
            el.siblings('.button-submit').hide().filter('button').show();
        });
    });
    return this;
};
})(jQuery);


// profileEdit
(function($){
$.fn.profileEdit = function(){
    this.each(function(){
        var profile = $(this);
        var form = $('form', profile);
//        var values = $('.value', profile);
        var edits = $('.edit', profile);
        var editLinks = $('a', edits);
//        var textFields = $('.i div.text', profile);
//        var buttons = $('.i button', profile);
        var uploadForms = $('.upload', profile);

        edits.each(function(){
            var edit = $(this);
            var editLink = $('a', edit);
//            var value = edit.siblings('.value');
//            var textField = edit.siblings('div.text');
//            var button = edit.siblings('button');
            var uploadForm = edit.siblings('.upload');
            var uploadFormClose = $('.close', uploadForm);

            editLink.click(function(){
                edits.css('visibility', 'visible');
                edit.css('visibility', 'hidden');
//                values.show();
//                value.hide();
//                textFields.hide();
//                textField.show().addClass('focus').find('input.text').focus();
//                buttons.hide();
//                button.show();
                uploadForms.hide();
                uploadForm.show();
                return false;
            });

            uploadFormClose.click(function(){
                uploadForm.hide();
                edits.css('visibility', 'visible');
            });
        });
    });
    return this;
};
})(jQuery);
