var logo;

function sameh(id1,id2)
{               
    try {
    obj1 = document.getElementById(id1);
    obj2 = document.getElementById(id2);
    maxh = Math.max(parseInt(obj1.clientHeight),parseInt(obj2.clientHeight));
    obj1.style.height = maxh+"px";
    obj2.style.height = maxh+"px";
    }catch (e){}
}


function addListener(element, type, expression, bubbling)
{
    bubbling = bubbling || false;
    if(window.addEventListener) 
    {
    	element.addEventListener(type, expression, bubbling);
	return true;
    }
    else 
    if(window.attachEvent)
    { // IE
	element.attachEvent('on' + type, expression);
	return true;
    }
    else return false;
}







function absPosition(obj) 
{
      var x = y = 0;
      while(obj) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
            obj = obj.offsetParent;
      }
      return {x:x, y:y};
}


function getElementsByClassName(className, tag, elm){
    var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length;
    for(var i=0; i<length; i++){
	current = elements[i];
	if(testClass.test(current.className)){
	    returnElements.push(current);
	}
    }
    return returnElements;
}

function makeShoot(x,y)
{
    var bullet = "<img class=bulletimg src='/xtpl/i/bul/1.gif' width=25 height=25 alt='' style='position:absolute;top:"+(y+(Math.random()*10)-3)+"px;left:"+(x)+"px;'>";
    document.getElementById('debug').innerHTML=(document.getElementById('debug').innerHTML+bullet);
}

var crc =0;
var igif = '1x.gif';

function makeShootSpecial(x,y)
{
    if (!igif) return ;
    logo = absPosition(document.getElementById('logo'));


    //do not shoot logo
    if (logo.x+76 < x && logo.x+160+76 > x && logo.y +32 < y && logo.y+130+32>y)    return;

    //if shoot shooting-range 


    crc ++;
    var bullet = "<img class=specbul src='/xtpl/i/bul/"+igif+"' alt='' style='position:absolute;top:"+(y+(Math.random()*10)-3)+"px;left:"+(x)+"px;' id=bul"+crc+" style='z-index:99999' >";
    document.getElementById('debug').innerHTML=(bullet+document.getElementById('debug').innerHTML);

    // get cursor back after DOM  remake
    try{
    xx1 = document.getElementById('x1'); 
    xx2 = document.getElementById('x2'); 
    xx3 = document.getElementById('x3'); 
    xx4 = document.getElementById('x4'); 
    }catch(e){}

    setTimeout("clear_bullet('bul"+crc+"')",1300);
}




function reshoot()
{
    try{
    var imgs = getElementsByClassName('bulletimg','img');
    var j=0;

    var a = getElementsByClassName('h2gr pl', 'h2');
    for (i in a)
    {
	var r=absPosition(a[i]);
	imgs[j].style.top = (y+(Math.random()*10)-3)+'px';
	imgs[j].style.left = r.x-30+'px';
	j++;
    }

    a = getElementsByClassName('h2gr', 'h2');
    for (i in a)
    {
	var r=absPosition(a[i]);
	imgs[j].style.top = (y+(Math.random()*10)-3)+'px';
	imgs[j].style.left = r.x-30+'px';
	j++;
    }}catch(o){}

}



function makeShoots()
{
    var a = getElementsByClassName('h2gr pl', 'h2');
    for (i in a)
    {	
	var r=absPosition(a[i]);
	makeShoot(r.x-25,r.y);
    }

    a = getElementsByClassName('h2gr', 'h2');
    for (i in a)
    {
	var r=absPosition(a[i]);
	makeShoot(r.x-25,r.y);
    }
}

function clear_screen()
{
    p = document.getElementById('debug');
    a = getElementsByClassName("specbul", 'img', p );
    for(i in a){try{p.removeChild(a[i]);} catch (obj){}}
    clrscr = false;
}


function clear_bullet(id)
{
    p = document.getElementById('debug');
    img = document.getElementById(id);
    try{p.removeChild(img);} catch (obj){}
}



