$(document).ready(function(){
	$(".button").each(function(){
		$(this).css({
			'padding': '0px 0px 0px 0px',
			'margin': '0px 0px 0px'		
		});
		var linkW = $(this).width();
		$(this).height("25px").css({'line-height':'25px','height':'25px','display':'block','width':linkW+'px','background':'url(/bC.png) repeat-x','color':'#fff','position':'relative','float':'left'});
		var curParent = $('<span class="button-wrapper" style="height:25px; display:inline-block; position:relative;"></span>');
		$(this).css('margin','0px 0px 0px 0px');
		$(this).wrap(curParent);
		$(this).before('<span class="butL" style="background:url(/bL.png) no-repeat;"></span>').after('<span class="butR"  style="background:url(/bR.png) no-repeat;"></span>');
	});
	
	var bck;
	var bok;
	$(".hoverable").each(function(){
		bck =$(this).css("background-color");
		$(this).children("*[name=bc]").remove();
		$(this).css("cursor","pointer").append("<input type='hidden' name='bc' value='"+bck+"'>");
		if($(this).children("a").size()){
			$(this).click(function(){
				document.location.href=$(this).children("a").attr("href");
			});
		}
		$(this).hover(function(){
			$(this).css({"outline":"1px solid #c00", "background-color":"#ffeeee"});
		},function(){
			bok = $(this).children("input[name=bc]").val();
			$(this).css({"outline":"none", "background-color":bok});
		});
	});
	
	$(".mainTableCont").width("975px");
	
	$("td.colorize div:even").css({"background-color":"#eee"});
	
	$('.bubbleInfo').each(function () {
    // options
    var distance = 0;
    var time = 250;
    var hideDelay = 250;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: -120,
          left: -10,
		  padding:10,
		  border: '1px dotted #212121',
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
 // showFacebox();
});

function showFacebox(){
    //$('body').click(function() {
    var wReg='<ul><li>Неограниченное количество обьявлений</li><li>Возможность редактирования своих обьявлений</li><li>Возможность добавления большего количества фотографий</li><li>Возможность отправки личных сообщений другим зарегистрированным пользователям</li></ul>';
    var woReg='<ul><li>Ограниченное количество обьявлений</li><li>Невозможность редактирования своих обьявлений</li><li>Ограниченое колличество фотографий</li><li>Нельзя отправлять личные сообщения</li></ul>';
    
    var question = "<table width='100%' cellpadding='0' cellspacing='0' border='0'><tr><th>Уважаемый пользователь.Регистрация даст Вам следующие преимущества</th></tr><tr><td>"+wReg+"</td></tr></table>";
    var caption = "Извините, но вы не зарегистрированы";
    
    Boxy.ask(question, ["Перейти к регистрации", "Перейти к размещению обьявления"], function(val) { 
      if(val=='Перейти к регистрации'){
          window.location.href="/signup.php";
      } else {
          window.location.href="/addsaleform.html";
      }
            
    }, {title: caption});
  //  return false;
  //});
  
  /*
  $('#alert-actuator').click(function() {
    Boxy.alert("File not found", null, {title: 'Message'});
    return false;
  });
  $('#confirm-actuator').click(function() {
    Boxy.confirm("Please confirm:", function() { alert('Confirmed!'); }, {title: 'Message'});
    return false;
  });
  */
}
