var IE = false;

function callMe(url, callback){
  ajaxObject = function() {
  try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e){
  try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e){
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){
  try { return new XMLHttpRequest() } catch(e){
  throw new Error( "This browser does not support XMLHttpRequest." );
  }}}}}}
  ajax = new ajaxObject();
  ajax.onreadystatechange = function(){
    if(ajax.readyState == 4){
      if(ajax.status == 200){
        callHandle(url,ajax.responseText,callback);
      }
    }
  };
  if(url.indexOf('time') == -1){
    url += '?time='+Number(new Date());
  }
  ajax.open('GET', 'ajax/'+url, true);
  ajax.send(null);
}
function callHandle(url,json, callback){
  location.href = "#"+url.replace(/,small_1/,'').split('?')[0];

  try{
    if(typeof(JSON) === "object" && typeof(JSON.parse) === "function")
      var obj = JSON.parse(json);
    else
      eval("var obj = "+json+";");
    if(obj.title) document.title = obj.title;
  }catch(e){
   var obj = json;
  }
  if(typeof(callback) === "function"){
    callback(obj);
  }
}

function AddLoad(func){
  var last = window.onload;
  if(typeof(last) !== 'function')
    window.onload = func;
  else
    window.onload = function(){last(); func();}
}

function addFile(){
  var el = document.getElementById("files");
  if(!el) return;
  var inp = document.createElement("input");
  inp.type = "file";
  inp.name = "file[]";
  inp.className = "file";
  el.appendChild(inp);
  inp = document.createElement("br");
  el.appendChild(inp);
}

var SlideIndex = 0;
var SlideTimeout = null;
var SlideTime = 5000;
function Slider(index){
  if(SlideTimeout) clearTimeout(SlideTimeout);
  if(index == '-'){
    if(!SlideIndex) index = 2;
    else index = SlideIndex-1;
  }else if(index == '+'){
    index = (SlideIndex+1)%3;
  }
  var el = document.getElementById('slider');
  if(index == SlideIndex || !el || typeof(el.effect) == 'object') return;
  RunEffect(el,'move',{to:-344*index,f:function(r){return .5-.5*Math.cos(r*Math.PI)},callback:function(){LightSlider(index)}});
}
function LightSlider(index){
  var ar = ['a','b','c'];
  document.getElementById('sld'+SlideIndex).className = 'tdpl '+ar[SlideIndex];
  document.getElementById('sld'+index).className = 'tdpl '+ar[index]+' act';
  SlideIndex = index;
  SlideTimeout = setTimeout(function(){Slider('+')},5000);
}
function RunSlide(){
  var el = document.getElementById('slider');
  if(el) SlideTimeout = setTimeout(function(){Slider('+')},5000);
}
AddLoad(RunSlide);
