var timer;

$(document).ready(function() {

    prepareExpandableBoxes();

    // lightbox initialisation
    $('a[@rel*=lightbox]').lightBox();

    // SLIDESHOW
    if ($('div#slideshow').length) {
        $('div#slideshow').slideshow();

        skipToNextSlide('firstcall');
    }

    if ($('div.divNeedToLogin').length) {
        $('div.divNeedToLogin').hide();

        $('dl#articleRating dd strong').bind(
      'mouseover', function() {
          $('div.divNeedToLogin').show();
      }
    ).bind(
      'mouseout', function() {
          $('div.divNeedToLogin').hide();
      }
    );

        $('div.divNeedToLogin').bind(
      'mouseover', function() {
          $('div.divNeedToLogin').show();
      }
    ).bind(
      'mouseout', function() {
          $('div.divNeedToLogin').hide();
      }
    );
    }
});

function enhanceHeadings()
{
  $('div.column h2').each(function(){
    $(this).replaceWith('<div class="headerContainer"><h2>'+$(this).html()+'</h2><img class="glyph" src="./media/img/heading_glyph.gif" alt="glyph" /></div> <!-- .headerContainer -->');
  });
}


 


function restoreMouseOvers()
{
  $('div#cameraFinder div.panel:not(.open) a').each(function()
  {
    $(this).bind(
      'mouseover',function(){
        $(this).css('background-color','#D6D6D6');
      }
    ).bind(
      'mouseout',function(){
        $(this).css('background-color','#E9E9E9');
      }
    );
  });
}




function prepareExpandableBoxes()
{
  $('div#emailBestDealsForm').hide();
  
  $('a#emailBestDeals').click(function()
  {
    $('div#emailBestDealsForm').slideToggle();
    return false;
  });
  
  $('div#commentsBox').hide();
  $('div#friendsBox').hide();
  
  $('a#toggleComments').click(function()
  {
    if ( $('a#toggleFriend').hasClass('active') )
    {
      $('a#toggleFriend').removeClass('active');
      $('div#friendsBox').slideUp();
    }
    
    if ( $(this).hasClass('active') )
    {
      $(this).removeClass('active');
      $('div#commentsBox').slideUp();
    }
    else
    {
      $(this).addClass('active');
      $('div#commentsBox').slideDown();
    }
    return false;
  });
  
  $('a#toggleFriend').click(function()
  {
    if ( $('a#toggleComments').hasClass('active') )
    {
      $('a#toggleComments').removeClass('active');
      $('div#commentsBox').slideUp();
    }
    
    if ( $(this).hasClass('active') )
    {
      $(this).removeClass('active');
      $('div#friendsBox').slideUp();
    }
    else
    {
      $(this).addClass('active');
      $('div#friendsBox').slideDown();
    }
    return false;
  });

  $('div#postCommentForm').hide();
  $('div#friendsBox').hide();
  
}


function BlockAlert(aMessage)
{
  $.blockUI({
    message:'<h1>' + aMessage + '</h1>',
    css:
    {
      border: 'none',
      padding: '15px',
      backgroundColor: '#000',
      '-webkit-border-radius': '10px',
      '-moz-border-radius': '10px',
      opacity: '.5',
      color: '#fff'
    }
  });
  
  setTimeout($.unblockUI,2000);
}


String.prototype.trim = function()
{
  return this.replace(/^\s+|\s+$/g,"");
}


