﻿var HKLCenterMap = 
{
	Bubble    : null,
	Image     : null,
	Areas     : [],
	i         : 0,
	stopdelay : false,
	
	load : function() 
	{
		var imgs = document.getElementsByTagName('img');
		
		for(var i = 0, len = imgs.length; i < len; i++) 
		{
			if (typeof imgs[i] == 'undefined' || 
				imgs[i].className != 'centerimagemap') {
				continue;
			};
			
			var mapname = 'map'+i;
			this.Image = imgs[i]; 
			
			imgs[i].setAttribute('usemap', '#'+mapname);
			imgs[i].useMap = '#'+mapname;
			
			var oMap = null;
			
			try
			{
				oMap = document.createElement( "<map name='"+ mapname +"'>" );
			} catch(e)
			{
				if( !oMap || oMap.name.toLowerCase() != mapname.toLowerCase() ) 
				{
					oMap = document.createElement("MAP");
					oMap.setAttribute("name", mapname);
				};
			};
			
			oMap.appendChild(
				this.getArea(
					'278,205,300,230', 
					'http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Kempten.html', 
					'Kempten', 
					
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Gebrauchtmaschinen Center Kempten</h2>'+
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Tel.: +49 (0)8 31 571 21-0</h2>'+
					'<i>Mehr Infos? Klick auf <a href="http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Kempten.html">HKL Center</a>.</i>'
				)
			);
			
			oMap.appendChild( 
				this.getArea('297,116,315,135', 
					'http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Falkenhagen.html', 
					'Falkenhagen', 
					
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Gebrauchtmaschinen Center Falkenhagen</h2>'+
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Tel.: +49 (0)3 39 86 637-0</h2>'+ 
					'<i>Mehr Infos? Klick auf <a href="http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Falkenhagen.html">HKL Center</a>.</i>'
				)
			);
			
			oMap.appendChild( 
				this.getArea(
					'160,298,174,321', 
					'http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Barcelona.html', 
					'Barcelona', 
					
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Gebrauchtmaschinen Center Barcelona</h2>'+
					'<h2 style="color:#2d4d76; margin-bottom: 0px; padding-bottom: 2px;">Tel.: +34 936 525 298</h2>'+
					'<i>Mehr Infos? Klick auf <a href="http://www.hkl-baumaschinen.de/Mieten/HKL_Center_Locator/HKL_Center_Barcelona.html">HKL Center</a>.</i>'
				)
			);
			
			document.body.appendChild(oMap);
			
			function HKLNextBubble(){
				HKLCenterMap.nextBubble();
			};
			
			HKLNextBubble();
			
		};
	},
	
	getArea : function(coords, href, alt, msg)
	{
		var oArea = document.createElement('area');
		oArea.coords = coords;
		oArea.shape  = 'rect';
		oArea.alt    = alt;
		oArea.href   = href;
		
		oArea.setAttribute("shape", "rect", 1);
		oArea.setAttribute("alt", alt, 1);
		oArea.setAttribute("href", href, 1);
		oArea.setAttribute("coords", coords, 1);

		//oArea.setAttribute('msg', msg);
		
		oArea.onmouseover = function() 
		{ 
			HKLCenterMap.showBubble(this, msg);
		};
		
		oArea.onmouseout = function() 
		{ 
		      //HKLCenterMap.hideBubble();
		};
		
		this.Areas.push(oArea);
		return oArea;
	},
	
	nextBubble : function() 
	{
		function HKLNextBubble(){
			HKLCenterMap.nextBubble();
		};
		
		HKLNextBubble.delay(5000);

		if (HKLCenterMap.stopdelay == true) {
		    return;
		};

		if(this.i > this.Areas.length-1) {
			this.i = 0;
		};
		
		_oi = this.i-1;
		if(_oi < 0) {
			_oi = this.Areas.length-1;
		};
		
		this.Areas[ _oi ].onmouseout()
		this.Areas[ this.i ].onmouseover();
		this.i++;
	},
	
	showBubble : function(obj, value, type)
	{
		if(this.Bubble != null) 
		{
			this.Bubble.obj.parentNode.removeChild( this.Bubble.obj );
			this.Bubble = null;
		};
		
		var pos = this.elmPos(this.Image);
		
		switch(obj.getAttribute('alt'))
		{
			case 'Kempten':
				pos.x = pos.x + 50;
				pos.y = pos.y + 90;
			break;
			
			case 'Falkenhagen':
				pos.x = pos.x + 70;
			break;
			
			case 'Barcelona':
				pos.x = pos.x -70;
				pos.y = pos.y + 180;
			break;
		};
			
		this.Bubble = new _ptools.Bubble({
			top: pos.y,
			left: pos.x
		});
		
		document.body.appendChild( this.Bubble.create() );

		this.Bubble.obj.onmouseover = function()
		{
		     HKLCenterMap.stopdelay = true;
		};

		this.Bubble.obj.onmouseout = function()
		{
		      HKLCenterMap.stopdelay = false;
		};
		
		this.Bubble.show();
		this.Bubble.setAttribute('content', value);
	},
	
	hideBubble : function()
	{
		if(!this.Bubble) {
			return;
		};
		
		this.Bubble.hide();
	},
	
	elmPos : function(element)
	{
		var elem=element, tagname="", x=0, y=0;

		while( (typeof elem == "object") && (typeof elem.tagName != "undefined") && elem.tagName != 'HTML' )
		{
			y = y+elem.offsetTop;
			x = x+elem.offsetLeft;
			tagname = elem.tagName.toUpperCase();
	
			if(tagname=="BODY") {
				elem = 0;
			};
			
			if(typeof(elem)=="object")
			{
	      		if(typeof(elem.offsetParent) == "object") {
	      			elem = elem.offsetParent;
	      		};
			};
		};
	
		return {x:x,y:y};
	}
};

var HKLSlider = {
	
	content : null,
	fire : true,
	
	div : null,
	h : 870,
	
	load : function()
	{
		if(!$('hkl_slider')) {
			return;
		};
		
		var h = HKLSlider.h;
		var oHeader = document.createElement('strong');
		//oHeader.src = BIN_URL +'hkl/portal/images/hkl_center.png';
		//oHeader.style.paddingLeft = '2px';
		oHeader.innerHTML = 'HKL Center';
		
		var oContent = document.createElement('div');
		var style = oContent.style;
		//style.border = '1px solid red';
		style.height = h+'px';
		style.width = '230px';
		style.background = "url('"+ BIN_URL +"images/ajax-loader.gif') no-repeat center center";
		style.overflow = 'hidden';
		style.position = 'relative';
		
		this.content = oContent;
		
		$('hkl_slider').appendChild(oHeader);
		$('hkl_slider').appendChild(this.content);
		
		HKLSlider.next();
	},
	
	next : function()
	{
		_Ajax.asyncPost('ajax_hkl_centerticker', function(result) {
			var h = HKLSlider.h;
			HKLSlider.content.style.background = '';
			
			var div = document.createElement('div');
				div.style.position = 'absolute';
				div.style.top = h+'px';
				div.innerHTML = result;
				
			HKLSlider.content.appendChild(div);
				
			if(HKLSlider.div) 
			{
				new Fx.Morph( HKLSlider.div, {
					duration: 300,
					onComplete : function(me) {
						me.parentNode.removeChild(me);
					}
				} ).start({
					top : '-'+h+'px'
				});	
			};
			
			new Fx.Morph( div, {
				duration: 300,
				onComplete : function(me) {
					HKLSlider.div = me;
								
					function HKLSliderNext(){
						HKLSlider.next();
					};
					
					HKLSliderNext.delay(10000);
				}
			} ).start({
				top : '0px'
			});	

		}, {
			project : 'hkl',
			lang : _Project.lang
		});
	}
	/*
	prev : function()
	{
		_Ajax.async('ajax_hkl_centerticker', function(result) {
			
			HKLSlider.content.style.background = '';
			
			var div = document.createElement('div');
				div.style.position = 'absolute';
				div.style.top = '-400px';
				div.innerHTML = result;
				
			HKLSlider.content.appendChild(div);
				
			if(HKLSlider.div) 
			{
				new Fx.Morph( HKLSlider.div, {
					duration: 300,
					onComplete : function(me) {
						me.parentNode.removeChild(me);
					}
				} ).start({
					top : '400px'
				});	
			};
			
			new Fx.Morph( div, {
				duration: 300,
				onComplete : function(me) {
					HKLSlider.div = me;
								
					function HKLSliderNext(){
						HKLSlider.next();
					};
					
					HKLSliderNext.delay(5000);
				}
			} ).start({
				top : '0px'
			});	
				
		}, {
			project : 'hkl',
			type : 'prev'
		});
	}
	* */
};

function mietanfrage( o )
{
	var Parent = o.parentNode;

	while(Parent.nodeName != 'FORM')
	{
		if(Parent.nodeName == 'BODY') {
			break;
		};

		Parent = Parent.parentNode;
	};

	if(Parent.nodeName == 'FORM') {
		Parent.submit();
		return false;
	};

	return true;
};



// Bilder im Content Zoomen
function zoom_image_loader(){
	var ZImgs = document.getElementById('content').getElementsByTagName('img');
	var Zext;
	var Zsource;
	if(ZImgs.length <= 0)
	{
		return;
	};

	for(var i = 0, len = ZImgs.length; i < len; i++)
	{
		if(ZImgs[i].className.match('zoom'))
		{

			var _Zoomimage = ZImgs[i].src;
			Zext = _Zoomimage.substr(_Zoomimage.length-4, 4);
			Zsource = _Zoomimage.split("__");
			if(Zsource[0] != _Zoomimage){
				_Zoomimage = Zsource[0]+Zext;
			}


			ZImgs[i].setAttribute('pcsg_zoomimage',_Zoomimage);
			ZImgs[i].onclick = function()
			{
				var slideshowgroup = '';
				if(this.getAttribute('slideshowgroup') != null){
					slideshowgroup = this.getAttribute('slideshowgroup');
				}

				return hs.expand(this, { src: this.getAttribute('pcsg_zoomimage'), slideshowGroup: slideshowgroup } );
			};

		};
	};
}

var oActiveSize = null;
function fontsize( type )
{
	var oContent = document.getElementById('content');
	var oMiddle = document.getElementById('middle');

	switch( type )
	{
		case "medium":
			oContent.style.fontSize   = '13px';
			oMiddle.style.fontSize    = '13px';
			oContent.style.lineHeight = '1.4em';
			oMiddle.style.lineHeight  = '1.4em';

			if(oActiveSize)
			{
				oActiveSize.className = oActiveSize.className.replace('active','');
			};

			var oLink = document.getElementById('fontmedium');
			oActiveSize = oLink;
			oActiveSize.className = 'mediumactive';

			// Cookie setzen
			_ptools.Cookie.set('hkl_size', 'medium');

		break;

		case "large":
			oContent.style.fontSize   = '15px';
			oMiddle.style.fontSize    = '15px';
			oContent.style.lineHeight = '1.2em';
			oMiddle.style.lineHeight  = '1.2em';

			if(oActiveSize)
			{
				oActiveSize.className = oActiveSize.className.replace('active','');
			};

			var oLink = document.getElementById('fontlarge');
			oActiveSize = oLink;
			oActiveSize.className = 'largeactive';

			// Cookie setzen
			_ptools.Cookie.set('hkl_size', 'large');

		break;

		default:
			oContent.style.fontSize   = '';
			oMiddle.style.fontSize    = '';
			oContent.style.lineHeight = '';
			oMiddle.style.lineHeight  = '';

			if(oActiveSize)
			{
				oActiveSize.className = oActiveSize.className.replace('active','');
			};

			var oLink = document.getElementById('fontsmall');
			oActiveSize = oLink;
			oActiveSize.className = 'smallactive';

			// Cookie setzen
			_ptools.Cookie.set('hkl_size', 'small');

		break;
	};
};

function FieldFocus (InputField, FValue, SValue )
{
	InputField = document.getElementById ( InputField );
	var _value = InputField.value

	if(_value != ''){
		SValue =_value;
	}
	if(InputField.value ==''){
		InputField.value = SValue;
	}


	if(InputField)
	{
		InputField.onfocus = function ()
		{
			if(InputField.value == SValue)
			{
				InputField.value = FValue;
			}
			else
			{
				InputField.select ();
			}

		}
		InputField.onblur = function ()
		{
			if(InputField.value == FValue)
			{
				InputField.value = SValue;
			}
		}
	}
}

function trackConversion(ConversionID, ConversionLabel, ConversionValue)
{	
	var element = document.createElement('img');
	element.setAttribute('src', 'http://www.googleadservices.com/pagead/conversion/' + ConversionID + '/?value=' + ConversionValue + '&label=' + ConversionLabel + '&guid=ON&script=0');
	document.body.appendChild(element);
}