
( function( $ ) {
 
    // plugin definition
    $.fn.overlabel = function( options ) {
 
        // build main options before element iteration
        var opts = $.extend( {}, $.fn.overlabel.defaults, options );
 
        var selection = this.filter( 'label[for]' ).map( function() {
 
            var label = $( this );
            var id = label.attr( 'for' );
            var field = document.getElementById( id );
 
            if ( !field ) return;
 
            // build element specific options
            var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
 
            label.addClass( o.label_class );
 
            var hide_label = function() { label.css( o.hide_css ) };
            var show_label = function() { this.value || label.css( o.show_css ) };
 
            $( field )
                 .parent().addClass( o.wrapper_class ).end()
                 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
 
            return this;
 
        } );
 
        return opts.filter ? selection : selection.end();
    };
 
    // publicly accessible defaults
    $.fn.overlabel.defaults = {
 
        label_class:   'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css:      { 'text-indent': '-10000px' },
        show_css:      { 'text-indent': '0px', 'cursor': 'text' },
        filter:        false
 
    };
 
} )( jQuery );

function showHelp() {
	$(".tags .help").click(
		function() { $("#tags").hide(); $("#help").show();}
	);
	$(".tags .close").click(
		function() { $("#tags").show(); $("#help").hide();}
	);
}


function autoFill(id){
	var title=$(id).attr('title'); 
	$(id).addClass("readonly").attr({ value: title }).focus(function(){
		if($(id).val()==title){
			$(id).val("").removeClass("readonly");
		}
	}).blur(function(){
		if($(id).val()==""){
			$(id).addClass("readonly").val(title);
		}
	});
}



function photoOverlay() {
	$(".flickr .tumbnails a").click(
		function() { $("html").css("overflow","hidden");$(".overlay").show(); $(".window").show();}
	);
	$(".window .close").click(
		function() {  $("html").css("overflow",""); $(".overlay").hide(); $(".window").hide();}
	);
}

function loginForm()
{
	$("#login").click(
		function() {
			$("html").css("overflow","hidden");
			$(".overlay").show();
			$(".window").show();
			return false;
		}
	);

	$(".window .close").click(
		function() {
			$("html").css("overflow","");
			$(".overlay").hide();
			$(".window").hide();
			return false;
		}
	);
}


function editAddress()
{
	alert($(".place #cityID").value);

	//$(".place #edit_metro")
}


$ (
	function () {
		loginForm();
		showHelp();
		autoFill("#code");	
		autoFill("#reg-code");	
		autoFill("#rem-email");	
		autoFill(".mail #email");	
		autoFill("#name");	
		autoFill("#theme");	
		//photoOverlay();
		$("label.overlabel").overlabel();
	    
	}
);