//
//
// For fun / common functionality
//

//return  context name
function a_popup() {
  var a_element=null;
  var a_width=null;
  var a_height=null;
  var a_windowStyle=null;
  var a_customText=null;

  switch (a_popup.arguments.length) {
    case 5: a_customText = a_popup.arguments[4];
    case 4: a_windowStyle = a_popup.arguments[3];
    case 3: a_height = a_popup.arguments[2];
    case 2: a_width = a_popup.arguments[1];
    case 1: a_element = a_popup.arguments[0];
    default:
  }

  var aTarget = a_element.target;

  if (aTarget==null || aTarget=="") {
    aTarget = "pop";
  }

  if (a_windowStyle==null) {
    a_windowStyle = "titlebar,scrollbars=yes,resizable=yes";
  }

  if (a_width==null || a_width <=0) {
    a_width=400;
  }
  if (a_height==null || a_height <=0) {
    a_height=400;
  }

  a_windowStyle+= (",left="+((screen.availWidth - a_width) / 2));
  a_windowStyle+= (",width="+a_width);

  a_windowStyle+= (",top="+(((screen.availHeight - a_height) / 2 ) - 30));
  a_windowStyle+= (",height="+a_height);



  var w;
  if (a_customText!=null) {
    w = window.open('', aTarget, a_windowStyle);
    try {
      w.document.close();
      w.document.open();
      w.document.writeln(a_customText);
      try {
        w.document.close();
      } catch(e){}
    } catch(e){}
  } else {
    w = window.open(a_element.href, aTarget, a_windowStyle);
  }
  w.focus();

  return false;
}

function AWI_showChangeLanguage() {
  //popup a window
  var props = "dependent=yes";
  props+= ",directories=no";
  props+= ",height=275";
  props+= ",location=no";
  props+= ",menubar=no";
  props+= ",resizable=no";
  props+= ",scrollbars=yes";
  props+= ",status=no";
  props+= ",toolbar=no";
  props+= ",width=350";
  props+= ",screenX=150";
  props+= ",screenY=150";
  props+= ",left=150";
  props+= ",top=150";

  var w=window.open("POP", SITE.urlPrefix + "switch_language.content", "switch_language", props);
  w.focus();
  return  w;
}


$(document).observe("dom:loaded", function() {
    $(document.body).observe("click", function (event) {
      var link= event.element();
      if (link.tagName!='A') {
        link = link.up('a.quicklook');
      }
      if (link!=null&&link.hasClassName('quicklook')) {
         PACRIM.Popover.open(link.href);
         event.stop();

         s=s_gi(s_account);
         if(link.readAttribute('item-id'))s.products='item;i'+link.readAttribute('item-id');
         //s.linkTrackVars='events,eVar37,eVar9,eVar10,products';
         s.linkTrackVars='events,products';
         s.events=s.linkTrackEvents='event32';
         s.tl(true, 'o',"Quick Look")
      }
    });

});
PACRIM= {
  Popover : {
   open:function(url) {
     new Ajax.Request(url, {
       method:'get',
       'onSuccess': function(transport){
         $('popover-body').innerHTML = transport.responseText;
         var popover = $('popover');
         popover.removeClassName('hidden');
         if (!popover.hasClassName('initDraggable')){
           new Draggable(popover,{handle:'popover-name'});
           popover.addClassName('initDraggable');
         }
       }
     });
   },
   close:function(){
     $('popover').addClassName('hidden');
   }
 }
}

$(document).observe("dom:loaded", function() {
  if (canShowNavMenu) {
    menuDropdown();
  }
});

function AWI_switchLanguage(lid) {
  window.location='/commflrpac/' + SITE.market + '/' + lid + '/' + SITE.countryId + '/';
  return false;
}


