var OP = (window.opera) ? 1 : 0;
var IE = (!OP && (document.all || window.navigator.userAgent.toLowerCase().indexOf('msie') != -1)) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0; 
var DOM = (document.getElementById && !IE) ? 1 : 0;

function startUp() {
	
   in_frame_Y = parent.document.getElementById("if1");
   mousePushed = 0;
   dragActive = 0;
   attached = 0;
   closer = 0;
   x_offset = x_moved = x_drag =
   y_offset = y_moved = y_drag = 0;

   attachedElements = Array(Array(""),
                            Array("drag02", "drag01", "drag"),
                            Array("drag03", "drag01", "drag"),
                            Array("butt01", "drag01", "hide"));
   document.onmouseup = eventHandler;
   document.onmousedown = eventHandler;
   document.onmousemove = eventHandler;

//   parent.window.scrollTo(0,0);
   
   if (in_frame_Y) {
       in_frame_Y.height = 6000;
       window.setTimeout("iframeSize()", 500);
       window.setTimeout("makePI()", 500);
   }
}


function iframeSize()  {
    if (NS4) {
        diff = in_frame_Y.height - document.getElementsByTagName('body')[0].offsetHeight - 15;
    } else {
        diff = in_frame_Y.height - document.getElementsByTagName('body')[0].scrollHeight - 15;
    }
    if (Math.abs(diff) > 10 ) {
        diff = Math.round(diff / 10);
        in_frame_Y.height -= diff;
        window.setTimeout("iframeSize()", 20);
    } else if (Math.abs(diff) > 0) {
        diff = (diff / diff);
        in_frame_Y.height -= diff;
        window.setTimeout("iframeSize()", 20);
    }
}

function makePI() {
   if (parent.document && parent.PICount > 0) {
       var new_count = parent.PICount + 1;

       var toplist = parent.document.getElementsByName("tl")[0];
       var new_toplist = toplist.src.replace(/&a=\d+/, "") + "&a=" + new_count;
       toplist.src = new_toplist;

       var ads_banner = parent.document.getElementById("ads_banner");
       var new_banner = ads_banner.src.replace(/&a=\d+/, "") + "&a=" + new_count;
       ads_banner.src = new_banner;

       var ads_skyscraper = parent.document.getElementById("ads_skyscraper");
       var new_skyscraper = ads_skyscraper.src.replace(/&a=\d+/, "") + "&a=" + new_count;
       ads_skyscraper.src = new_skyscraper;

       var ads_contentbox = parent.document.getElementById("ads_contentbox");
       var new_contentbox = ads_contentbox.src.replace(/&a=\d+/, "") + "&a=" + new_count;
       ads_contentbox.src = new_contentbox;

   }
   parent.PICount ++;
}

function openWindow(Content,X,Y,L,T) {
   Title = "/index.php?content=" + Content;
   if (closer == 1)  {
      Window1.close();
   }
   Window1=window.open(Title,"Window1","width="+X+", height="+Y+", resizable=no, left="+L+", top="+T );
   closer = 1;
}

function eventHandler(E) {
    if (IE) {
       E = event;
       element = E.srcElement;
    } else {
       element = E.target;
    }
    if (E.type == "mousedown") {
        mousePushed = 1;
        x_offset = (IE) ? E.clientX : E.pageX;
        y_offset = (IE) ? E.clientY : E.pageY;
        checkElement = searchElement(element.id);
        if (checkElement) {
            attached = checkElement;
        }
    } else if (E.type == "mouseup") {
        mousePushed = 0;
        dragActive = 0;
        attached = 0;
        x_moved = y_moved = x_drag = y_drag = 0;
    } else if (E.type == "mousemove" && mousePushed) {
        var x_local = (IE) ? E.clientX : E.pageX;
        var y_local = (IE) ? E.clientY : E.pageY;
        x_moved = x_local - x_offset;
        y_moved = y_local - y_offset;
    }
    if (attached && !dragActive) {
        target = document.getElementById(attachedElements[attached][1]);
        if (attachedElements[attached][2] == "hide") {
            target.style.display = "none";
        } else if (attachedElements[attached][2] == "drag") {
            dragActive = 1;
            x_drag = Math.floor(target.style.left.replace(/px/, ""));
            y_drag = Math.floor(target.style.top.replace(/px/, ""));
        }
    }
    if (E.type == "mousemove" && dragActive) {
        new_x = Math.floor(x_drag + x_moved);
        new_y = Math.floor(y_drag + y_moved);
        target.style.left = new_x + "px";
        target.style.top = new_y + "px";
    }
}

function searchElement(this_id) {
    for (elem in attachedElements) {
        if (attachedElements[elem][0] == this_id) {
            return Math.round(elem);
        }
    }
    return 0;
}