/**
 * @author azzamallow
 */
function overlay(element)
{
  if (typeof(window["AUTH_TOKEN"]) == "undefined")
  {
    AUTH_TOKEN = '';
  }

  params = (AUTH_TOKEN) ? 'authenticity_token=' + encodeURIComponent(AUTH_TOKEN) : '';

  var myAjax = new Ajax.Request(
    element.href, {
    method: 'get',
    parameters: params,
    onComplete: callBack.bindAsEventListener(this)
  }
    );

  return false;
}

function callBack(response)
{
  new Element.insert($('overlay-content'), response.responseText);
  openModal();
  // the code to detect the code height
  jQuery('#overlay-back').css({height: jQuery(body).height()});
}

function openModal()
{
  height = scrollingDetector();
  jQuery('#overlay-back').css({height: jQuery('.page').height()+20});
  jQuery('#overlay-back').css({width: jQuery(body).width()});
  jQuery('#overlay-back-container').css({height: jQuery(body).height()+20});
  jQuery('#overlay-back-container').css({width: jQuery(body).width()});
  objHeight = 100;
  jQuery('#overlay-content').css({top: (height+objHeight)});
  jQuery('#overlay-back').show();
  jQuery('#overlay-back-container').show();
  $('overlay-content').style.display = "block";
  $('overlay-back-container').style.display = "block";
  $('overlay-back').style.display = "block";
}

function closeModal()
{
  // Close drop down if it i open
  items = $$('.style-select-items');
  for (var i = 0; i < items.length; i++)
  {
    items[i].style.display = 'none';
  }

  $('overlay-back').style.display = "none";
  $(('overlay-back-container')).style.display = "none";
  $('overlay-content').innerHTML = "";
  $('overlay-content').style.display = "none";
}

function scrollingDetector()
{
  var currHeight = 0;

  if (navigator.appName == "Microsoft Internet Explorer")
  {

    currHeight = document.documentElement.scrollTop;
  }

  else
  {
    currHeight = window.pageYOffset;
  }
  return currHeight;

}
