var G_dragobj = null;
var G_dragx   = 0;
var G_dragy   = 0;
var G_posx    = 0;
var G_posy    = 0;

var G_isW3C   = false;
var G_isIE    = false;

function draginit()
{   // Bestimmung, welcher Browser gerade läuft.
    if ( document.addEventListener )
    {   G_isW3C = true;
    }
    else
    if ( window.event )
    {   G_isIE = true;
    }

    // Initialisierung der Überwachung der Events
    document.onmousemove = drag;
    document.onmouseup  = dragstop;
}

function dragstart( element )
{   // Wird aufgerufen, wenn ein Objekt bewegt werden soll.
    G_dragobj = document.images["smallpics"];
    //alert( "element " + element.id );
    //alert( "offsetLeft " + G_dragobj.offsetLeft );
    G_dragx   = G_posx;
}

function dragstop()
{   // Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
    G_dragobj = null;
}

function drag( ereignis )
{   var deltax;
    // Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.

    if ( G_isIE )
    {   ereignis = window.event;
    }

    G_posx = ereignis.clientX;
    //G_posx = document.all ? window.event.clientX : ereignis.pageX;
    //alert( "G_posx " + G_posx );
    //G_posy = document.all ? window.event.clientY : ereignis.pageY;

    if ( G_dragobj != null )
    {   deltax = G_posx - G_dragx;
        G_act_links = (G_act_links + deltax);
        G_act_clip_links  = G_act_clip_links - deltax;
        G_act_clip_rechts = G_act_clip_rechts - deltax;
        
        // Nicht über den linken Rand hinaus verschieben
        if ( G_act_links > G_first_links )
	{   G_act_links       = G_first_links;
            G_act_clip_links  = 0;
            G_act_clip_rechts = G_vis_img_width;
	}
        // Nicht über den rechten Rand hinaus verschieben
        if ( G_act_links < (G_vis_img_width - G_all_img_width + G_first_links) )
	{   G_act_links       = G_vis_img_width - G_all_img_width + G_first_links;
            G_act_clip_rechts = G_all_img_width;
            G_act_clip_links  = G_all_img_width - G_vis_img_width;
	}
        document.images["smallpics"].style.left = G_act_links + "px";
        var clip_string = "rect(0px "+G_act_clip_rechts+"px 65px "+G_act_clip_links+"px)";
        document.images["smallpics"].style.clip = clip_string;

        G_dragx = G_posx;
    }
}
