/*-----------------------------------------------------------------------
core JavaScript File

version: 	4.1
author:		sebastian kupke
email:		sebastian.kupke@baral-geohaus.de
website:	http://www.baral.de
-----------------------------------------------------------------------*/

/* =namespace core
 * 
 * @constructor
 * @param {number} r The desired radius of the circle.
 * @author 	Developer's name.
 * @constructor 	Marks a function as a constructor.
 * @deprecated 	Marks a method as deprecated.
 * @exception 	Documents an exception thrown by a method, synonym for @throws.
 * @param 	Documents a method parameter.
 * @return 	Documents a return value.
 * @see 	Documents an association to another object.
 * @throws 	Documents an exception thrown by a method.
 * @version 	Provides the version number of a library.
 * 
-----------------------------------------------------------------------*/

ws.c = {
	
	// parameter von stadtfix
	stadtfix:'',
	
	// url rewriting
	ur: '',
	
	// current window width (for resize)
	width: 0,
	height: 0,
	
	// Pixel per cm (only with 96dpi)
	ppcm: 37.795276,
	
	firstLoading: true,
	
	// conf
	conf: '',
	
	// style folder
	style: '',
	
	// use border?
	border: true,
	borderSize: 0,
	
	// use header?
	header: true,
	
	// use toolbar?
	toolbar: false,
	
	// use modules?
	modules: false,
	
	/* =init
	-----------------------------------------------------------------------*/
	init: function() {
		
		// Set window width and hight for possible resize
		ws.c.width = $(window).width();
		ws.c.height = $(window).height();
		
		// initialize the border
		if (ws.c.border) {
			ws.c.borderSize = 40;
			cbb.init();
		}
		
		// Set browser height (-40 because of border)
		$('#wrapper').height(ws.c.height - ws.c.borderSize);
		$('#maps').height(ws.c.height - ws.c.borderSize);
	
		// initialize mousewheel
		$('#maps').mousewheel(function(e, delta) {
			ws.c.mousewheel.handle(e, delta);
		});

		// ie6
		if ($.browser.msie && parseInt($.browser.version) == 6) {
			$('#toolbar').css({
				backgroundColor: 'white'
				/*
				background: '',
				top: '7px'
				*/
			});
		}
		
		// header
		if (ws.c.header) {
			$('#header').show();
			$('#header_version').show();
		}
	
		//------------------------------
		// if scale was not set with url interface set it
		//------------------------------
		if (ws.map.scaleNumber) {
		    ws.map.scale = ws.map.setScaleFactor(ws.map.scaleNumber);
		} else {
			var tmpScaleX = (ws.map.startExtent.maxx - ws.map.startExtent.minx) / $('#map_div').width();
			var tmpScaleY = (ws.map.startExtent.maxy - ws.map.startExtent.miny) / $('#map_div').height();
			
			ws.map.scale = tmpScaleX > tmpScaleY ? tmpScaleX : tmpScaleY;
		}
		
		// extParams.level
		if (extParams.level) {
			var service = ws.map.getService();
			if (service.getLevel(extParams.level)) {
				var level = service.setCurLevel(extParams.level);
				
				var scaleNumber = ws.map.getScaleNumber();
				if (level.maxScale > scaleNumber || level.minScale < scaleNumber) {
					service.setCurLevel(level.id);
					ws.map.setScaleFactor((level.minScale - level.maxScale) / 2 + level.maxScale);
				}
			}
		}
		
		// extParams.layer
		if (extParams.layer) {
			var level = ws.map.getService().getLevel();
			if (level.getLayer(extParams.layer)) {
				level.setCurLayer(extParams.layer);
			}
		}
		
		// modules
		if ($.browser.msie) {
			$('#m_navigator img').attr('src', 'style/' + ws.c.style + '/img/modules/navigator.gif');
		}
	
		// Now get the first map
		ws.map.load();
	
		// Re-initialize the fisheye toolbar
		if (ws.c.toolbar) {
			
			ws.t.init();
			
			if (ws.t.t.defaultTool) {
				$('#button_' + ws.t.t.defaultTool).parent().trigger('click');
			}
		}
		
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//stadtfix anfang

                if(ws.c.stadtfix){			
			// Pin einsetzen		
			var wapper = document.createElement("div");				
			document.getElementById("wrapper").style.zIndex=0;					   
			var img = document.createElement("img");
			document.body.appendChild(img);
			img.setAttribute("id","pin_select");
			img.src ="http://geodaten.karlsruhe.de/stadtplan/style/karlsruhe/img/modules/stadtfix/stadtfix.png";				
			// Pixel diff from left upper
			width = $('#map_div').width();
			height = $('#map_div').height();		
			img.style.position = "absolute";				
			img.style.left =width/2+ "px";
			img.style.top =height/2 + "px";
			wapper.appendChild(img);
			document.body.appendChild(wapper);
			var elem = document.getElementById('pin_select');
	    ws.pin.startDrag(elem);
	    
	    var mousePos = {x:width/2, y:height/2};
	
	    Imgs_coords = ws.map.px2Coords(mousePos);             
      top.parent.document.getElementById('geox').value = Imgs_coords.x;
		  top.parent.document.getElementById('geoy').value = Imgs_coords.y; 
		}
//stadtfix end		
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////					
		ws.usr.c.onload();	
	},

	/* =browser resize
	-----------------------------------------------------------------------*/
	countResize: 0,
	
	
	resize: function() {
		ws.c.countResize++;
		setTimeout('ws.c.resizeGo(' + ws.c.countResize + ')', 500);	        
		},
	
	resizeGo: function(currentCount) {
		
		// anfangsPosition von Element rechnen
                var Elem_px_start= ws.map.getElemPx();
		var Elem_coords=ws.map.px2Coords(Elem_px_start);
		
	        var width = $(window).width();
	        var height = $(window).height();
	    

		if (currentCount == ws.c.countResize && (ws.c.width != width || ws.c.height != height)) {
	        
			$('#wrapper').height(height - ws.c.borderSize);
			$('#maps').height(height - ws.c.borderSize);
			
			// endesPosition von Element rechnen
			var Elem_px_end=ws.map.coords2Px(Elem_coords);
			$('#pin_select').css({					
			top: Elem_px_end.y + 'px',
			left: Elem_px_end.x + 'px'
			});
			
			ws.map.load();
			if (ws.c.toolbar) {
				ws.t.init();
			}

			ws.c.width = width;
			ws.c.height = height;
		}
	}
};

// document ready
$(document).ready(ws.c.init);

// window resize
$(window).resize(ws.c.resize);









