
// Seitebreite				breite
// Seitenrand (links)		randLinks
// Seitenrand (rechts)	randRechts
// Spaltenabstand			spaltenAbstand
// Spaltenbreite			spaltenBreite
// Spaltenzahl				spalten
// Anzehl Raster			rasterNum
// Auswahlrahmen		auswahl
// Rahmenbreite			auswahlBreite

var gbreite = 457;
var ghoehe = 643;
var randLinks = 14;
var randRechts = 28;
var spaltenAbstand = 5;
var spalten = 5;
var spaltenBreite = 79;
var rasterNum = spalten - 1;
var auswahl;
var auswahlBreite;
var abstandLinks = 210 + randLinks;

// Ankerpunkte
var a = new Array();
for(i = 0; i < spalten + 1; i++) {
	a[i] = i * spaltenAbstand + i * spaltenBreite + parseInt(abstandLinks - spaltenAbstand / 2);
}



function init() {
  browse.load(0);

	Event.observe(document, 'mousedown', function() { $('auswahlRahmen').hide(); });
	Event.observe('seiteL', 'mousedown', initAuswahl);
	Event.observe('seiteL', 'mousemove', target);

  Event.observe('seiteR', 'mousedown', initAuswahlR);
  Event.observe('seiteR', 'mousemove', targetR);

	//new Draggable('popup', { starteffect : false, endeffect: false, handle : 'drag' });
}
function target(e) {
	with($('ende')) {
		x = parseInt(Event.pointerX(e));
		y = parseInt(Event.pointerY(e));
		
		x = getFixpoint(x);
		
		style.left = x + 'px';
		//style.top = y-5 + 'px';
		style.top = y+2 + 'px';
		style.width = '19px';
		style.height = '19px';
		style.background = 'url(images/cursor_red.gif) no-repeat';
	}
	
}
function getFixpoint(x) {
	for(i = 0; i < a.length; i++) {
		if(x >= a[i] && x < a[i+1] - spaltenBreite/2)
			x = a[i];
		else if(x >= a[i+1] - spaltenBreite/2 && x < a[i+1])
			x = a[i+1];
		else if(x < a[0])
			x = a[0];
		else if(x > a[a.length-1])
			x = [a.length-1];
	}

	return x;
}
function getStart(e) {
	//if(browse.akt_page == 0) { return false;}
	with($('start')) {
		x = parseInt(Event.pointerX(e));
		y = parseInt(Event.pointerY(e));

		x = getFixpoint(x);

		style.left = x + 'px';
		style.top = y + 'px';
	}
}
function initAuswahl(e) {

	getStart(e);
  
	Event.observe(document, 'mousemove', drawAuswahl);
	Event.observe(document, 'mouseup', stop);
}
function drawAuswahl(e) {

  
	x = parseInt(Event.pointerX(e)); 
	y = parseInt(Event.pointerY(e));
  if(x > 630) { x = 630;}


	sx = parseInt($('start').style.left)-abstandLinks;
	breite = x - sx;
	breite = getFixpoint(breite+14) - abstandLinks + spaltenAbstand / 2;
	
	sy = parseInt($('start').style.top);
	hoehe = (y - sy < 50) ? 50 : y - sy;
	
	hoehe = (sy + hoehe >= ghoehe) ? ghoehe - sy : hoehe;
	breite = ((sx + breite)-214 >= gbreite) ? a[a.length-1] - sx : breite;

	with($('auswahlRahmen')) {
		show();
		style.left = (sx+abstandLinks) + 'px';
		style.top = sy + 'px';
		style.width = breite + 'px';
		style.height = hoehe + 'px';
	}	
}
function stop(e) {
	Event.stopObserving(document, 'mousemove', drawAuswahl);
	Event.stopObserving(document, 'mouseup', stop);
	$('auswahlRahmen').hide();	
	//loadPopup(x,y);	

  // aus loadPopup
  //  Parameter für Popup-Aufruf ändern
  st = parseInt($('start').style.top)-60;
  sl = parseInt($('start').style.left)-200;
  et = parseInt($('ende').style.top)-40;
  el = parseInt($('start').style.left)+parseInt($('auswahlRahmen').style.width);

  wst = parseInt($('start').style.top)-40;
  wsl = parseInt($('start').style.left)-210;
  wet = parseInt($('ende').style.top)+40;
  wel = parseInt($('start').style.left)+parseInt($('auswahlRahmen').style.width);


//  if(parseInt($('ende').style.left) > (gbreite + abstandLinks)) {
//    wb = (gbreite + abstandLinks) - parseInt($('start').style.left);
//	} else {
    wb = parseInt($('start').style.left)+parseInt($('auswahlRahmen').style.width) - parseInt($('start').style.left);
//  }
  wh = (parseInt($('ende').style.top) - parseInt($('start').style.top))+16;

  if(browse.akt_page < 10) akt_page = '00' + browse.akt_page;
  if(browse.akt_page > 9 && browse.akt_page < 100) akt_page = '0' + browse.akt_page;

	wurl = "/epaperneu/frame.php?c=95|82|476|210|002|20071014";
	wurl = './frame.php?c='+wsl+'|'+wst+'|'+wb+'|'+wh+'|'+akt_page+'|'+browse.ausgabe;


  wtop = 50;
  wleft = 100;
  wwidth = (wb*2.25)+25;
	//if(wwidth < 85) wwidth = 92;
  wheight = (wh*2.25)+48;

	wtitle = "ePaper Detail"+
		"<a href=\"#\" onclick=\"Application.evalCode('open_new_bookmark', true);\" return false;>bookmark</a>";
	wtitle = "ePaper Detail";
  //wtitle = wurl;

	var win = new Window({className: "spread", title: wtitle,
			top:wtop, left:wleft, width:wwidth, height:wheight,
			url: wurl, showEffectOptions: {duration:0.5}})
  win.show();
	Application.evalCode('open_window2', true);

}

// muss das? Sebastian?
window.onload = init;

function zoom(bool) {
	wAmount = (bool) ? 20 : -20;
	zAmount = (bool) ? -10: 10;
	with($('popup')) {
		style.width = parseInt($('popup').style.width)+wAmount + 'px';
		style.height = parseInt($('popup').style.height)+wAmount + 'px';
		style.left = parseInt($('popup').style.left)+zAmount + 'px';
		style.top = parseInt($('popup').style.top)+zAmount + 'px';
	}
}


function handle(delta) {
	return false;
	if (delta < 0)
		zoom(true);
	else
		zoom(false);
}

function wheel(event){
	return false;
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		handle(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

/* Initialization code. */
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;




