
// 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_R = 14+457;
var randRechts = 28;
var spaltenAbstand = 5;
var spalten = 5;
var spaltenBreite = 79;
var rasterNum = spalten - 1;
var auswahl;
var auswahlBreite;
var abstandLinks_R = 200 + randLinks_R;

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



function targetR(e) {
	with($('ende')) {
		x = parseInt(Event.pointerX(e));
		y = parseInt(Event.pointerY(e));
		
		x = getFixpointR(x);
		
		style.left = x + 'px';
		style.top = y-5 + '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 getFixpointR(x) {
	for(i = 0; i < a.length; i++) {
		if(x >= b[i] && x < b[i+1] - spaltenBreite/2)
			x = b[i];
		else if(x >= b[i+1] - spaltenBreite/2 && x < b[i+1])
			x = b[i+1];
		else if(x < b[0])
			x = b[0];
		else if(x > b[a.length-1])
			x = [a.length-1];
	}

	return x;
}
function getStartR(e) {
	with($('start')) {
		x = parseInt(Event.pointerX(e));
		y = parseInt(Event.pointerY(e));
	
		x = getFixpointR(x);

		style.left = x + 'px';
		style.top = y + 'px';
	}
}
function initAuswahlR(e) {
	getStartR(e);
  
	Event.observe(document, 'mousemove', drawAuswahlR);
	Event.observe(document, 'mouseup', stopR);
}
function drawAuswahlR(e) {

  
	x = parseInt(Event.pointerX(e)); 
	y = parseInt(Event.pointerY(e));
  //$('inf').innerHTML = x;

	sx = parseInt($('start').style.left)-abstandLinks_R;
	breite = x - sx;
	breite = getFixpointR(breite+14) - abstandLinks_R + 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) ? b[a.length-1] - sx : breite;

//  $('inf').innerHTML = sx + ' ' +  breite + '<br>' +
//		                   sy + ' ' +  hoehe;

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

  // aus loadPopup
	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)-200-457;
  wet = parseInt($('ende').style.top)+40;
  wel = parseInt($('start').style.left)+parseInt($('auswahlRahmen').style.width);

	wb = parseInt($('start').style.left)+parseInt($('auswahlRahmen').style.width) - parseInt($('start').style.left);
  wh = (parseInt($('ende').style.top) - parseInt($('start').style.top))+16;



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

	wurl = "/epapertest/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";

	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);

}

function loadPopupR() {

  st = parseInt($('start').style.top)-40;
  sl = parseInt($('start').style.left)-200;
  et = parseInt($('ende').style.top);
  el = parseInt($('ende').style.left)+24;
  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;

	with($('popup')) {
		style.width = parseInt($('auswahlRahmen').style.width)*2 + 80 + 'px';
		style.height = parseInt($('auswahlRahmen').style.height)*2 + 80 + 'px';
		style.top = '100px';
		innerHTML = 'url(http://bremer-anzeiger.gz.emsn.int/epapertest/picture.php?c='+sl+'|'+st+'|'+(el-sl)+'|'+(et-st)+'|'+akt_page+'|'+browse.ausgabe+')';
		style.background = '#767676 url(http://bremer-anzeiger.gz.emsn.int/epapertest/picture.php?c='+sl+'|'+st+'|'+(el-sl)+'|'+(et-st)+'|'+akt_page+'|'+browse.ausgabe+') 50% 50% no-repeat';
	}
  /*browse.akt_page*/
	left = $('epaper').offsetWidth / 2 - parseInt($('popup').style.width) / 2;
	$('popup').style.left = left +'px';

	new Effect.Parallel([
		new Effect.Appear('popup'),
	]);
}
function hidePopup() {
	$('popup').hide();
}

window.onload = init;

function zoomR(bool) {
	return false;
	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)
		zoomR(true);
	else
		zoomR(false);
}


