var isInIFrame = (window.location != window.parent.location) ? true : false;

function xaction(commands) {
   try {
     eval(commands);
   } catch (e) {
   }
}
function getLadiesByPage(p, sid) {
  if (isInIFrame) {
    return true;
  }
  new Ajax.Request('/services/accounts.ajax.php', {
    method: 'post',
    parameters: {is_lady: '1', p: p, sid: sid},
    onSuccess: function(transport) {
       xaction(transport.responseText)
    }
  });
  return false;  
}
function getMenByPage(p, sid) {
  if (isInIFrame) {
    return true;
  }
  new Ajax.Request('/services/accounts.ajax.php', {
    method: 'post',
    parameters: {is_lady: '0', p: p, sid: sid},
    onSuccess: function(transport) {
       xaction(transport.responseText)
    }
  });
  return false;  
}
function setAccounts(l1,l2,l3, t1, t2, t3,p) {
  $('data_photo_1').update(l1);
  $('data_photo_2').update(l2);
  $('data_photo_3').update(l3);
  $('data_text_1').update(t1);
  $('data_text_2').update(t2);
  $('data_text_3').update(t3);
  $('data_pages').update(p);
}
var current_p=1;
function getNextList(is_lady, is_next, sid) {
  var p;
  if (is_next) {
    p = current_p+1;
  }else{
    p = current_p-1;
  }
  new Ajax.Request('/services/accounts_small.ajax.php', {
    method: 'post',
    parameters: {is_lady: is_lady, p: p, sid: sid},
    onSuccess: function(transport) {
       xaction(transport.responseText)
    }
  });
}
function setSmallAccounts(l1,l2,l3,l4,l5,p) {
  if ($('list_1').hasClassName('selectedlist')) {
    $('list_1').removeClassName('selectedlist');
    $('list_1').addClassName('list');
  }
  $('list_1').update(l1);
  if ($('list_2').hasClassName('selectedlist')) {
    $('list_2').removeClassName('selectedlist');
    $('list_2').addClassName('list');
  }
  $('list_2').update(l2);
  if ($('list_3').hasClassName('selectedlist')) {
    $('list_3').removeClassName('selectedlist');
    $('list_3').addClassName('list');
  }
  $('list_3').update(l3);
  if ($('list_4').hasClassName('selectedlist')) {
    $('list_4').removeClassName('selectedlist');
    $('list_4').addClassName('list');
  }
  $('list_4').update(l4);
  if ($('list_5').hasClassName('selectedlist')) {
    $('list_5').removeClassName('selectedlist');
    $('list_5').addClassName('list');
  }
  $('list_5').update(l5);
  current_p = p;
}

function createUL(is_first) {
   var newI = new Element('ul');
   var html = '';
   cur_element = topimgs_last_id;
   for (var p = 0; p<6; p++) {
     cur_element++;
     if (cur_element>=topimgs.length) {
        cur_element=0;
     }
     html = html+'<li>'+topimgs[cur_element]+'</li>';
   }
   topimgs_last_id = cur_element;
   newI.update(html);
   if (is_first) {
     newI.setStyle({left: '0px'});
   }else{
     newI.setStyle({left: '1002px'});
   }
   $('rotator').insert({'bottom':newI});
   return newI;
}
function moveChilds(element) {
   var childs = $(element).childElements();
   if (childs.length==0) {
      createUL(true);
   }
   for (var index = 0, len = childs.length; index < len; ++index) {
       if (parseInt(childs[index].getStyle('left')) <-1010) {
         childs[index].remove();
       } else if (parseInt(childs[index].getStyle('left')) == 0 )  {
         createUL(false);
         childs[index].setStyle({
            left: (parseFloat(childs[index].getStyle('left') || '0')-1).round() + 'px'
         });
       } else {
          childs[index].setStyle({
            left: (parseFloat(childs[index].getStyle('left') || '0')-1).round() + 'px'
          });
       }
   }     
   setTimeout('moveChilds(\''+element+'\')',50);
}

function in_array(str,arr) {
 res = -1;
 for (var i=0;i<arr.length;i++) {
   if (arr[i]==str) {
     res = i;
     i=arr.length;
   }
 }
 return res;
}

function del_from_array(str,arr) {
 res = -1;
 newarr = Array();
 for (var i=0;i<arr.length;i++) {
   if (arr[i]!=str) newarr.push(arr[i]);
 }
 return newarr;
}

function add_to_array(str,arr) {
  lastid=arr.length;
  arr[lastid]=str;
  return lastid;
}

function add_unique_to_array(str,arr) {
  if (in_array(str,arr)==-1) {
     lastid=arr.length;
     arr[lastid]=str;
     return lastid;
  }else{
     return -1;
  }
}

function add_to_top_array(str,arr) {
  lastid=arr.length;
  for (i=lastid; i>0;i--) {
    arr[i]=arr[i-1];
  }
  arr[0]=str;
  return lastid;
}


function add_unique_to_top_array(str,arr) {
  var m;
  if (in_array(str,arr)==-1) {
     m = add_to_top_array(str,arr);
     return m;
  }else{
     return -1;
  }
} 

