
Event.observe(window, 'load', function() {
$$('dd.tags').each(function(element){
    createTagTips(element);
});



if($('more_featured_poems')) {
$('more_featured_poems').observe('click', function(event){

    var element = Event.element(event);


    // do an ajax call to get some random poems
    url = baseUrl + '/ajax/poem/get.featured.poems/format/html';
    params = {numPoems: 2};
    Object.toJSON(params);

    new Ajax.Updater('update_featured_poems',url, {
        parameters: params,
        evalScripts: true,
        onCreate: pleaseWait.bindAsEventListener(event, 'update_featured_poems'),
        onSuccess: function(transport) {
		res = transport.responseJSON;
        //alert(res.status);
		//relative.container.insert(res.status);
          },
          method: 'post'
    });
    
    
 });
 
}
// Comments Delete Button Hover
$$('#comment_block .hide').each(function(element) {
    element.hide();
});

$$('#comment_block dl').each(function(menuItem) {
  Event.mouseEnter(menuItem, function() {
    menuItem.down('dd.hide').show();
  });

  Event.mouseLeave(menuItem, function() {
    menuItem.down('dd.hide').hide();
  });
});

// IE6 Glbl Nav
// $$('.dropdown').each(function(element) {
//     element.hide();
// });
// 
// $$('#glbl-user-nav li').each(function(menuItem) {
//   Event.mouseEnter(menuItem, function() {
//     menuItem.down('ul.dropdown').show();
//   });
// 
//   Event.mouseLeave(menuItem, function() {
//     menuItem.down('ul.dropdown').hide();
//   });
// });






 
});

function createTagTips(element)
{
var id = element.id.gsub('poem_', '');

var tags = $('tags_' + id).innerHTML;

//alert(tags);


new Tip(element, tags, {
title: "Poem Tags",
	delay: 0.1,
	 target: $('tags_' + id).up('dd'),
	 style: 'creamy',
	border: 6,
	borderColor: '#EFE2C2',
	 //showOn: 'click',
	 stem: 'bottomLeft',
	 hook: { target: 'topLeft', tip: 'bottomLeft' },
	 width: 200,
	hideOn: false, // disable the normal hide event, because we only want to use the hideAfter option
	hideAfter: 1

});
}


function pleaseWait(event, element_id)
{
    $(element_id).update('Loading ...');
}

// please login message
function pleaseLogInMessage()
{

   var message = '<dd class="login-to-use">Please <a href="'+ baseUrl + '/login?r=true">login</a> to use the feature! :)</dd>';
   
   return message;
}

function facebook_onlogin()
{
  // show permissions
       // promt the user for the permissions
         FB.Connect.showPermissionDialog("publish_stream", function(perms) 
         {/*
             if (!perms) 
             {
                 //continue_without_permission();
                 alert('saved!');
             }
             else 
             {
                 //save_session();
                 alert('not saved!');
              }
              */
              
             // check to see if they have alreay registerd with facebook on our site
             // make an ajax call to find out
             new Ajax.Request(baseUrl+'/ajax/login/has.account/format/json', {
                 onSuccess: function(transport) {
                  var response  = transport.responseText.evalJSON();
                  
                      if(response['status'])
                      {
                         var redirect = gup('r');
                         var goRedirect = gup('go');
                         if(redirect == 'true')
                         {
                            // take them to the history
                            window.location = document.referrer;
       
                         }
                         else if(goRedirect)
                         {
                             window.location = baseUrl + '/' + goRedirect;
                         }
                         else
                         {
                             window.location.reload()
                         }
                      }
                      else
                      {
                          // they do not have a Facebook account yet so take them to a page to set it up
                          window.location = baseUrl + '/register/facebookconnect';
                      }
                  }
              });
             
              
         });     
}

function inputChange()
{
    // hide the old password field
    $('password-field').hide();
    
    // show the new one and set focus
    $('password-field2').show();   

    $('password-field2').focus();
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}









