(function($) {
   $.fn.attach = function(to, align) {
     group=this;
	 //alert($(group).outerWidth(true));
	 if (!align) align='left';
     $(window).bind('resize', function(){
        width=$(group).outerWidth(true);
		//alert($(group).outerWidth(true));
	    $(to).css(align, width-10+'px');
     }).trigger('resize');
   }
})(jQuery);

(function($) {
   $.fn.equalHeight = function() {
      var group = this;
      $(window).bind('resize', function(){
         var tallest = 0;
         $(group).height('auto').each(function() {
            tallest = Math.max(tallest, $(this).height());
         }).height(tallest);
      }).trigger('resize');
   }
})(jQuery);

(function($) {
   $.form = function(html) {
	 if (html) {
		 
	   function verticalAlignMiddle() {
		  $('#cleanblue').css('height', 'auto');
		 // alert($('#cleanblue').height());
	      var top=($(window).height()-$('#cleanblue').height())/2;
		  //alert(top+" "+$(window).height()+" "+$('#cleanblue').height());
		  var w=$('#cleanblue').css('width');
		  w=parseInt(w);
		  if (w>700) w=820; else w=600;
	      if (top>0) {
			  $('#cleanblue').css('top', top+'px') .css('overflow', 'hidden') .css('width', w+'px');
		  }
	      else {
		    $('#cleanblue').css('top', '0px') .css('overflow', 'auto') .css('width', w+20+'px') .css('height', $(window).height());
			
	      }
	   }
	   if ($('#cleanblue').html()) {
		   $('.cleanbluemessage').html(html); 
		   $('#cleanblue').css('width', '600px');
		  /* $('#cleanblue').prompt({
				buttons:{'x':true},
				prefix:'cleanblue',
				top:'0'
	         });*/
		   $('#cleanblue').trigger('change');
	   }
	   else {
       $.prompt(html ,{
				buttons:{'x':true},
				prefix:'cleanblue',
				top:'0'
	   });
	  $('#cleanblue').bind('change', verticalAlignMiddle);
	  $(window).bind('resize', verticalAlignMiddle) .trigger('resize');
	   }
	if ($('input#url').attr('value')=='') {
       $('input#name').keyup( function(event){
          $('input#url').attr('value', Rus2Lat($(this).attr('value')));
       });
	}
	  
    $('input#url').keyup( function(event){
	if ($('input#url').attr('value')=='') {
       $('input#name').keyup( function(event){
          $('input#url').attr('value', Rus2Lat($(this).attr('value')));
       });
	}
    });
	$('select.select option').quicksearch({
		position: 'before',
		attached: 'select.select',
		labelText: 'Поиск'
	});
	
	} else {
	   $.prompt.close();	   
	 }
   }
})(jQuery);
