
$(window).load(function() {
  var pos = $('#see_you').position();
  $('#see_you').css({'position':'absolute','left':pos.left,'top':pos.top});
});

$(function() {
  

  $('#theaters div').click(function() {
    $('#see_you').fadeOut('slow');
    $('#theaters div').removeClass('active');
    $(this).addClass('active');
    $('#movie_times').load('/movies/findByTheater/'+$(this).attr('id')+'/html');
  });

  // Alert Button hovering
  $('#btn_move_alerts').hover(
   function(){$(this).attr('src', '/img/button-movie-alerts-on.jpg')},
   function(){$(this).attr('src', '/img/button-movie-alerts-off.jpg')}
  );

  // Alert Box dialog
  var $signup_box = $('#signup-dialog');
  $signup_box.dialog({
    bgiframe: true,
    resizable: false,
    modal: true,
    dialogClass: 'no-title alerts-dialog',
    autoOpen: false,
    overlay: {
        backgroundColor: '#000',
        opacity: 0.5
    },
    buttons: {
        'No Thanks': function() {
            $(this).dialog('close');
        },
        'Sign Up!': function() {
             data = {};
             $signup_box.find('input').each(function() {data[$(this).attr('name')] = $(this).val()});
             console.log(data);
             $.ajax({
              'url': '/contacts/save',
              'data': data,
              'type':'POST',
              'success': function(d){
                feedback.notice_box.show('Thank You.');
                $signup_box.dialog('close');
              },
              'error' : function(req) {
                $signup_box.find('.message').html(req.responseText);
              } 
            })
        }
        }
  });

  $('#btn_move_alerts').click(function() {$signup_box.dialog('open')});

  $('.imdb').live('click', function() {
    var link = escape($(this).parent().text().replace(/:/,''));
    window.open('/imdb/go/'+link);
  })
    .livequery(function() {
    $(this).toolTip('Find on IMDB<br/><i><small>(in new window)</small></i>',{'nudgeHorizontal':-20,'nudgeVertical':-2});
  });


});
