/*
 *       Gekko - Open Source Web Development Framework
 *       ------------------------------------------------------------------------
 *       Copyright (C) 2004-2006, J. Carlos Nieto <xiam@users.sourceforge.net>
 *       This program is Free Software.
 *
 *       package        GekkoShot
 *       license        http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
 *       author         David Valdez gnuget@lidsol.org
 *       link           http://www.gekkoware.org
 */

//declaring the class
var GekkoShot = Class.create();

//defining the rest of the class implementation
GekkoShot.prototype = {
    //the constructor
    initialize: function() {        
        this.david = document.getElementsByTagName('a');             

        for(i = 0;i < this.david.length ; i ++)
        {            
            validate = this.david[i].toString();
            //if the url is not a  relative
            if(validate.search("http://"+document.domain) == -1) 
                {   //if the url is  a webpage                 
                    if(validate.match(/(zip|exe|mp3|jpg|png|gif|avi|mov|mpg|mpeg|rar)$/) == null)
                        {
                            Event.observe(this.david[i],'mouseover',this.showImage.bindAsEventListener(this,i),false); 
                            Event.observe(this.david[i],'mouseout',this.disappearImage.bindAsEventListener(this,i),false);
                        }                   
                }
        }                
    },    
    showImage: function(tipo,numero) 
    {    
        //create the div
        this.div=document.createElement('div');
        this.div.className='thumbnail';
        this.div.style.width='243px';
        this.div.style.height='195px';
        this.div.style.position='absolute';
        //   this.div.style.top= this.david[numero].offsetTop  +  17 + 'px';
        //this.div.style.left= this.david[numero].offsetLeft + 5 + 'px';            
        this.div.style.top = this.findPos(this.david[numero])[1]+17 + 'px';
        this.div.style.left = this.findPos(this.david[numero])[0]+17 + 'px';
        this.div.style.background= 'url("bg.png")';          

        //create the image 
        this.img=document.createElement("img");
        this.img.setAttribute("src", "http://mozshot.nemui.org/shot/shot?"+this.david[numero]);
        this.img.position='absolute';
        this.img.style.marginTop="40px";
        this.img.style.marginLeft="60px";        
        this.img.setAttribute("alt","mozshot.nemui.org");

        //creating childs :-p
        this.div.appendChild(this.img);                                             
        document.getElementsByTagName('body')[0].appendChild(this.div)
    },   

    disappearImage: function(tipo,numero)
    {     
        //killing childs
        document.getElementsByTagName('body')[0].removeChild(this.div);
    },
    
    findPos: function(obj) {
        this.derecha = 0; 
        this.arriba  = 0;
        this.posicion = new Array();
        
        if(obj.offsetParent)
        {
            this.derecha =obj.offsetLeft;
            this.arriba =obj.offsetTop;
            
            while(obj = obj.offsetParent) 
                {
                    this.derecha += obj.offsetLeft;
                    this.arriba +=obj.offsetTop;
                }
            this.posicion[0] = this.derecha;
            this.posicion[1] = this.arriba;
        }
        return this.posicion;
    }

};

Event.observe(window, 'load', initGekkoShot, false);

function initGekkoShot()
{
    var watcher = new GekkoShot();
}