var isTablet = false;
var globalPageId = 0
var isMobile = 0;
var tmpBlock;
var arrBackgroundImageId, arrBackgroundWidth, arrBackgroundHeight, backgroundTimer, backgroundIndex;
var myResize = new Array();
var resizeCounter = 0;

function startPage(pageId, mobile) {
	globalPageId = pageId;
	
	isMobile = mobile;
	var bName = Browser.Platform.name.toLowerCase();
	var bVersion = '';
	if (bName == 'android' || bName == 'ios' || bName == 'webos' || bName == 'blackberry') isTablet = true;
	
	if (isTablet && isMobile == 0) {
		var winWidth = screen.width;
		var winHeight = screen.height;
		var uA = navigator.userAgent.toLowerCase();
		var x = uA.indexOf('android');
		if (x > -1) {
			var y = uA.indexOf(';', x);
			if (y > -1) {
				x += 7;
				var uV = uA.substr(x, y - x).trim().toInt(); 
				if (uV < 4) {
					winWidth = window.outerWidth;
					winHeight = window.outerHeight;
				} else {
					winWidth = screen.availWidth;
					winHeight = screen.availHeight;
				};
			};
		} else {
			winWidth = window.outerWidth;
			winHeight = window.outerHeight;
		};
		if (winWidth.toInt() < 980) {
			isMobile = 1;
			var req = new Request( {
				url: '/includes/ajax.asp?script=setMobile&isMobile=' + isMobile,
				onSuccess: function() {
					document.location.href = '/';
				}
			}).send();
		};
	};
	
	if (isMobile == 0) {
		window.addEvent('resize', function() {
			changeSize();
		});
		initBackground();
		initTopMenu();
		initBottomMenu();
	} else {
		initTopMenu();
	};
	initBlocks();
	initSearch();
	if (isMobile == 0) {
		orderContentBlocks();
		setContentHeight();
	};
}

function initBlocks() {
	tmpBlock = $('tmpBlock');
	var blocks = $$('div.contentBlock');
	blocks.each(function(block, i) {
		initIconPicker(block);
		initMonthPicker(block);
		initPlacePicker(block);
		initResizeBlock(block);
		initCalendar(block, true);
		initPeriodical(block, true);
		initTwitter(block);
		initBlockSize(block, true);
		initBlockScroller(block);
		if (globalPageId == 0 && isMobile == 0) {
			initLeftContentBlock();
			initDragDrop(block);
		};
	});
}

function initBlockSize(objBlock, firstInit) {
	if (!(objBlock.getElement('.blockContent'))) return;
	
	var objContent = objBlock.getElement('.blockContent');
	var contentHeight = objContent.getSize().y;
	var objScroller = objContent.getElement('.blockContentScroller');
	var scrollerHeight = objScroller.getSize().y;
	if (firstInit == true) {
		var doResize = true;
		if (objBlock.hasClass('Twitter')) doResize = false;
		if (objBlock.hasClass('Calendar') && objBlock.hasClass('Narrow')) doResize = false;
		if (doResize) objContent.setStyle('height', scrollerHeight);
	} else {
		if (objScroller.getStyle('opacity') == 0) {
			var Tween3 = new Fx.Tween(objScroller, {
				duration: 200,
				property: 'opacity'
			}).start(1);
		} else if (objContent.getStyle('opacity') == 0) {
			var Tween3 = new Fx.Tween(objContent, {
				duration: 200,
				property: 'opacity'
			}).start(1);
		};
		var Tween = new Fx.Tween(objContent, {
			duration: 400,
			property: 'height',
			onComplete: function() {
				initMonthPicker(objBlock);
				initBlockScroller(objBlock);
				blockRepair(objBlock, 1);
				objContent.removeClass('blockContentWhite');
			}
		}).start(scrollerHeight);
	};
}

function initSearch() {
	if (!($('search'))) return;
	$('search').getElement('div').addEvent('click', function() {
		var x = checkSearch(true);
	});
}

function checkSearch(doSubmit) {
	var searchText = $('searchText').value.trim();
	$('searchText').value = searchText;
	if (searchText == '') return false;
	if (doSubmit) {
		$('search').getElement('form').submit();
	} else {
		return true;
	}
}

function orderContentBlocks() {
	var position1, position2, size1, newPosition;
	
	var blocks = $$('div.contentBlock');
	blocks.each(function(block1, i) {
		blocks.each(function(block2, j) {
			if (j > i) {
				position1 = block1.getPosition($('content'));
				size1 = block1.getSize();
				position2 = block2.getPosition($('content'));
				if (position1.x == position2.x) {
					newPosition = position1.y + size1.y + 20;
					block2.setStyle('top', newPosition);
				};
			};
		});
	});
	
	if ($('mainContent').getStyle('visibility') == 'hidden') {
		$('mainContent').setStyles({
			'opacity': 0,
			'visibility': 'visible'
		});
		var newTween = new Fx.Tween($('mainContent'), {
			duration: 500,
			property: 'opacity'
		}).start(1);
	};
}

function sortNumber(a, b) {
	return a - b;
}

function blockRepair(objBlock, mode) {
	//mode = 2: dispose
	var checkPosition, checkSize;
	var arrBlocks = '', arrPos = '';
	var position = objBlock.getPosition($('content'));
	var positionX = position.x;
	var positionY = position.y;
	var size = objBlock.getSize();
	var sizeY = size.y;
	var objBlockId = objBlock.id;
	var blocks = $$('div.contentBlock');
	var Tweens = new Array();
	if (mode == 2) objBlock.dispose();
	
	blocks.each(function(block, i) {
		if (block.id != objBlockId) {
			checkPosition = block.getPosition($('content'));
			if (checkPosition.x == positionX && checkPosition.y > positionY) {
				if (mode == 1 || mode == 2) {
					if (arrBlocks != '') {
						arrBlocks += ',';
						arrPos += ',';
					};
					arrBlocks += block.id + '|' + checkPosition.y;
					arrPos += checkPosition.y;
				} else {
					Tweens[i] = new Fx.Tween(block, {
						duration: 400,
						property: 'opacity'
					}).start(mode);
				};
			};
		};
	});
	
	if (arrBlocks != '') {
		var arrTmp, blockId, blockY, block;
		var arrNew = '';
		var sequence = 0;
		arrBlocks = arrBlocks.split(',');
		arrPos = arrPos.split(',');
		arrPos = arrPos.sort(sortNumber);
		for (var x = 0; x < arrPos.length; x++) {
			for (var y = 0; y < arrBlocks.length; y++) {
				arrTmp = arrBlocks[y].split('|');
				blockId = arrTmp[0];
				blockY = arrTmp[1];
				if (blockY.toInt() == arrPos[x].toInt()) {
					if (arrNew != '') arrNew += ',';
					arrNew += blockId;
				};
			};
		};
		arrNew = arrNew.split(',');
		if (mode == 2) {
			blockY = positionY;	
		} else {
			blockY = positionY + sizeY + 20;
		};
		for (var x = 0; x < arrNew.length; x++) {
			block = $(arrNew[x]);
			block.setStyle('top', blockY);
			checkSize = block.getSize().y.toInt();
			blockY += checkSize + 20;
			if (mode == 1) {
				sequence += 1;
				Tweens[sequence] = new Fx.Tween(block, {
					duration: 400,
					property: 'opacity'
				}).start(mode);
			}
		};
	};
}

function correctPositions(objBlock, difHeight, duration) {
	var position = objBlock.getPosition($('content'));
	var blocks = $$('div.contentBlock');
	var checkPosition, checkSize;
	var Tweens = new Array();
	blocks.each(function(block, i) {
		if (block.id != objBlock.id) {
			checkPosition = block.getPosition($('content'));
			checkSize = block.getSize();
			if (checkPosition.x == position.x && checkPosition.y > position.y) {
				if (duration) {
					Tweens[i] = new Fx.Tween(block, {
						duration: duration,
						property: 'top',
						link: 'cancel'
					});
					Tweens[i].start(checkPosition.y + difHeight);
				} else {
					block.setStyle('top', checkPosition.y + difHeight);	
				};
			};
		};
	});
}

var leftContentTween;
function initLeftContentBlock() {
	$('leftContentBlock').setStyles({
		'opacity': 0,
		'visibility': 'visible'
	});
	leftContentTween = new Fx.Tween($('leftContentBlock'), {
		duration: 400,
		property: 'opacity',
		link: 'cancel'
	});
}

function initDragDrop(objBlock) {
	var position, size, checkPosition, checkSize, tmpPosition, tmpSize, arrCoordinates;
	var arrBlock, startY, arrY, highY, blockX, blockY, blockInfo, blockMatch, tmpX, blockId;
	var opacityValue = 0.9;
	var checkMargin = 124;
	var gridSnap = new Array(0, 250, 500);
	var blocks = $$('div.contentBlock');
	var blockHeader = objBlock.getElement('.blockHeader')
	var i = -1;
	blocks.each(function(checkBlock, j) {
		if (objBlock.id == checkBlock.id) i = j;
	})
	var myDrag = new Drag(objBlock, {
		handle: blockHeader,
		limit: {x:[0,500],y:[0,10000]},
		onSnap: function(block) {
			leftContentTween.start(1);
			objBlock.addClass('dragging');
			objBlock.setStyle('opacity', opacityValue);
			position = objBlock.getPosition($('content'));
			tmpX = position.x;
			size = objBlock.getSize();
			tmpBlock.setStyles({
				'width': size.x - 4,
				'height': size.y - 4,
				'left': position.x,
				'top': position.y,
				'display': 'block'
			});
		},
		onComplete: function(block) {
			leftContentTween.start(0);
			blocks.removeClass('matchX');
			blocks.removeClass('matchY');
			objBlock.removeClass('dragging');
			position = tmpBlock.getPosition($('content'));
			objBlock.setStyles({
				'opacity': 1,
				'left': position.x,
				'top': position.y
			});
			tmpBlock.setStyle('display', 'none');
			setContentHeight();
			
			blockId = getCurrentValue(objBlock, 0);
			arrCoordinates = blockId + ',' + position.x + ',' + position.y;
			blocks.each(function(checkBlock, j) {
				if (objBlock.id != checkBlock.id) {
					checkPosition = checkBlock.getPosition($('content'));
					if (checkPosition.x == position.x) {
						arrCoordinates += '|' + getCurrentValue(checkBlock, 0) + ',' + checkPosition.x + ',' + checkPosition.y;
					}
				}
			})
			var req = new Request( {
				url: '/includes/ajax.asp?script=updateGrid&blockId=' + blockId + '&arrCoordinates=' + arrCoordinates
			}).send();
		},
		onDrag: function(block) {
			setContentHeight();
			position = objBlock.getPosition($('content'));
			size = objBlock.getSize();
			tmpPosition = tmpBlock.getPosition($('content'));
			tmpSize = tmpBlock.getSize();
			blocks.each(function(checkBlock, j) {
				if (objBlock.id != checkBlock.id) {
					checkPosition = checkBlock.getPosition($('content'));
					if (position.x >= (checkPosition.x - checkMargin) && position.x <= (checkPosition.x + checkMargin)) {
						checkSize = checkBlock.getSize();
						checkBlock.addClass('matchX');
						if (position.x >= (tmpPosition.x - checkMargin) && position.x <= (tmpPosition.x + checkMargin)) {
							if (position.y > tmpPosition.y) {
								if (position.y > (checkPosition.y + (checkSize.y / 2)) && position.y < (checkPosition.y + checkSize.y)) {
									checkBlock.addClass('matchY');	
								} else {
									if (position.y > checkPosition.y + checkSize.y && tmpPosition.y < checkPosition.y) {
										checkBlock.addClass('matchY');
									} else {
										checkBlock.removeClass('matchY');
									}
								}
							} else {
								if (position.y < (checkPosition.y + (checkSize.y / 2)) && position.y < (checkPosition.y + checkSize.y)) {
									if (position.y < checkPosition.y + checkSize.y && tmpPosition.y > checkPosition.y) {
										checkBlock.addClass('matchY');
									} else {
										checkBlock.removeClass('matchY');
									}
								} else {
									checkBlock.removeClass('matchY');
								}
							}
						} else {
							if (position.y < checkPosition.y || position.y < (checkPosition.y + (checkSize.y / 2))) {
								checkBlock.addClass('matchY');	
							} else {
								checkBlock.removeClass('matchY');
							}
						}
					} else {
						checkBlock.removeClass('matchX');
						checkBlock.removeClass('matchY');
					}
				}
			});
			
			if (!(position.x >= (tmpPosition.x - checkMargin) && position.x <= (tmpPosition.x + checkMargin))) {
				blocks.each(function(checkBlock, j) {
					if (objBlock.id != checkBlock.id) {
						checkPosition = checkBlock.getPosition($('content'));
						if (checkPosition.x >= (tmpPosition.x - checkMargin) && checkPosition.x <= (tmpPosition.x + checkMargin)) {
							if (checkPosition.y > tmpPosition.y) {
								checkBlock.addClass('matchY');
							}
						}
					}
				});
			}
			
			blockInfo = '';
			blockX = -1;
			blocks.each(function(checkBlock, j) {
				if (objBlock.id != checkBlock.id) {
					checkPosition = checkBlock.getPosition($('content'));
					if (position.x >= (checkPosition.x - checkMargin) && position.x <= (checkPosition.x + checkMargin)) {
						blockX = checkPosition.x;
						if (checkBlock.hasClass('matchY')) {
							if (blockInfo != '') blockInfo += '|';
							blockInfo += checkPosition.y + ',' + j;
						}
					}
				}
			});
			
			if (blockX == -1) {
				for (j = 0; j < gridSnap.length; j++) {
					if (position.x >= (gridSnap[j] - checkMargin) && position.x <= (gridSnap[j] + checkMargin)) {
						blockX = gridSnap[j];
					}	
				}	
			}
			
			if (blockInfo == '' && (!(position.x >= (tmpPosition.x - checkMargin) && position.x <= (tmpPosition.x + checkMargin)))) {
				blockInfo = 'x';	
			}
			if (blockInfo != '') {
				if (blockInfo == 'x') {
					blockInfo = tmpPosition.y + ',' + i;	
				} else {
					blockInfo = tmpPosition.y + ',' + i + '|' + blockInfo;
				}
				arrBlock = blockInfo.split('|');
				
				startY = -1;
				highY = -1;
				
				if (position.x >= (tmpPosition.x - checkMargin) && position.x <= (tmpPosition.x + checkMargin)) {
					for (j = 0; j < arrBlock.length; j++) {
						arrY = arrBlock[j].split(',');
						if (arrY[0].toInt() < startY || startY == -1) startY = arrY[0].toInt();
						if (arrY[0].toInt() > highY) highY = arrY[0].toInt();
					}
					arrY = arrBlock[0].split(',');
					if (arrY[0].toInt() <= startY) {
						blockY = highY + 1;
					} else {
						blockY = startY - 1;
					}
					
					arrBlock[0] = blockY + ',' + i;
					arrBlock = arrBlock.sort();
					
					for (j = 0; j < arrBlock.length; j++) {
						arrY = arrBlock[j].split(',');
						blocks.each(function(checkBlock, k) {
							if (arrY[1].toInt() == k) {
								checkSize = checkBlock.getSize();
								tmpBlock.setStyle('left', blockX);
								objBlock.setStyle('left', blockX);
								if (i == k) {
									tmpBlock.setStyle('top', startY);
									objBlock.setStyle('top', startY);
								} else {
									checkBlock.setStyle('top', startY);	
								}
								startY += checkSize.y + 20;
							}
						});
					}
				
				} else {
					
					arrBlock = '';
					blocks.each(function(checkBlock, j) {
						if (objBlock.id != checkBlock.id) {
							checkPosition = checkBlock.getPosition($('content'));
							if (position.x >= (checkPosition.x - checkMargin) && position.x <= (checkPosition.x + checkMargin)) {
								blockX = checkPosition.x;
								if (arrBlock != '') arrBlock += '|';
								arrBlock += checkPosition.y + ',' + j + ',' + checkBlock.hasClass('matchY');
							}
						}
					});
					arrBlock = arrBlock.split('|').sort();
					blockMatch = false;
					blockY = 0;
					for (j = 0; j < arrBlock.length; j++) {
						arrY = arrBlock[j].split(',');
						if (arrY[2] == 'true' && blockMatch == false) {
							blockMatch = true;
							tmpBlock.setStyles({
								'left': blockX,
								'top': blockY
							});
							objBlock.setStyles({
								'left': blockX,
								'top': blockY
							});
							blockY += tmpSize.y + 20;
						}
						blocks.each(function(checkBlock, k) {
							if (arrY[1]) {
								if (arrY[1].toInt() == k) {
									checkSize = checkBlock.getSize();
									checkBlock.setStyle('top', blockY);	
									blockY += checkSize.y + 20;
								}
							}
						});
					}
					if (blockMatch == false) {
						tmpBlock.setStyles({
							'left': blockX,
							'top': blockY
						});
						objBlock.setStyles({
							'left': blockX,
							'top': blockY
						});
					}
					
					arrBlock = '';
					blocks.each(function(checkBlock, j) {
						checkPosition = checkBlock.getPosition($('content'));
						if (tmpX == checkPosition.x) {
							if (arrBlock != '') arrBlock += '|';
							arrBlock += checkPosition.y + ',' + j;
						}
					});
					
					tmpX = blockX;
					arrBlock = arrBlock.split('|').sort();
					blockY = 0;
					for (j = 0; j < arrBlock.length; j++) {
						arrY = arrBlock[j].split(',');
						blocks.each(function(checkBlock, k) {
							if (arrY[1]) {
								if (arrY[1].toInt() == k) {
									checkSize = checkBlock.getSize();
									checkBlock.setStyle('top', blockY);	
									blockY += checkSize.y + 20;
								};
							};
						});
					};
				}
			}
		}
	});
}

function initBottomMenu() {
	var shareTrigger = $('shareTrigger');
	var shareBlock = $('shareBlock');
	shareTrigger.addEvent('click', function(){
		var newState = (shareBlock.getStyle('display') == 'block') ? 'none' : 'block';
		shareBlock.setStyle('display', newState);
	});
}

function initTopMenu() {
	$('menuTop').getElement('h1').addEvent('click', function() {
		document.location = '/';
	});
	if (!($('menuPlace')) || isMobile == 1) return;
	var timeoutId;
	var collapsible = new Fx.Slide($('menuPlace').getElement('ul'), {
		link: 'cancel',
		duration: 400, 
		transition: Fx.Transitions.quadIn
	});
	collapsible.hide();
	$('menuTop').getElement('h1').addEvent('mouseenter', function() {
		timeoutId = (function(){ 
			collapsible.slideIn();
		}).delay(5000);
	});
	$('menuTop').getElement('h1').addEvent('mouseleave', function() {
		clearTimeout(timeoutId);
	});
	$('menuPlace').addEvent('mouseleave', function() {
		clearTimeout(timeoutId);
		collapsible.slideOut();
	});
}

function initBackground() {
	if ($('arrBackgroundImageId')) {
		arrBackgroundImageId = $('arrBackgroundImageId').value.split(',');
		arrBackgroundWidth = $('arrBackgroundWidth').value.split(',');
		arrBackgroundHeight = $('arrBackgroundHeight').value.split(',');
		backgroundIndex = -1;
		setBackgroundImage();
	}
}

function setBackgroundImage() {
	backgroundIndex += 1;
	if (backgroundIndex >= arrBackgroundImageId.length) backgroundIndex = 0;
	var currentLayer = ((backgroundIndex / 2) == (backgroundIndex / 2).toInt()) ? 1 : 2;
	var previousLayer = (currentLayer == 1) ? 2 : 1;
	var imgObj = $('bg' + currentLayer);
	imgObj.setStyles({
		'opacity': 0,
		'z-index': 2
	});
	var imageId = arrBackgroundImageId[backgroundIndex].toInt();
	imgObj.src = '/files/media_base/original/' + imageId + '.jpg';
	$('bg' + previousLayer).setStyle('z-index', 1);
	var myImage = new Asset.image('/files/media_base/original/' + imageId + '.jpg', {
		onLoad: function() {
			var size = imgObj.getSize();
			if (size.x == 1) {
				setBackgroundImage();
				return;
			}
			changeSize();
			var newTween = new Fx.Tween(imgObj, {
				duration: 500,
				property: 'opacity',
				onComplete: function() {
					if (arrBackgroundImageId.length > 1) {
						backgroundTimer = setTimeout(function() {
							setBackgroundImage();
						}, 5000);
					}
				}
			}).start(1);
		}
	});
}

function changeSize() {
	if (isMobile == 1) return;
	var currentLayer = ((backgroundIndex / 2) == (backgroundIndex / 2).toInt()) ? 1 : 2;
	var imgObj = $('bg' + currentLayer);
	var imgWidth = arrBackgroundWidth[backgroundIndex].toInt();
	var imgHeight = arrBackgroundHeight[backgroundIndex].toInt();
	var imgRatio = imgWidth / imgHeight;
	var size = window.getSize();
	var winWidth = size.x;
	var winHeight = size.y;
	var winRatio = winWidth / winHeight;
	var imgWidth = winWidth;
	var imgHeight = winHeight;
	if (winRatio > imgRatio) {
		imgHeight = (imgRatio > 1) ? (imgWidth / imgRatio).toInt() : (imgWidth * imgRatio).toInt();
	} else {
		imgWidth = (imgRatio < 1) ? (imgHeight / imgRatio).toInt() : (imgHeight * imgRatio).toInt();
	};
	var imgX = (imgWidth > winWidth) ? 0 - ((imgWidth - winWidth) / 2).toInt() : 0;
	var imgY = (imgHeight > winHeight) ? 0 - ((imgHeight - winHeight) / 2).toInt() : 0;
	imgObj.setStyles({
		'left': imgX,
		'top': imgY,
		'width': imgWidth,
		'height': imgHeight
	});
	if ($('slideShowContainer')) slideShowCloseButton.fireEvent('click');
}

function setContentHeight() {
	if (!($('content'))) return;
	
	var blocks = $$('div.contentBlock');
	var mHeight = 0;
	var checkPosition, checkSize, tmpHeight
	var totalHeight = $('content').getPosition().y;
	blocks.each(function(checkBlock, i) {
		tmpHeight = checkBlock.getPosition($('content')).y + checkBlock.getSize().y + 20;
		if (tmpHeight > mHeight) mHeight = tmpHeight;
	});
	totalHeight += mHeight;
	$('mainContent').setStyle('height', totalHeight + 20);
}

function initPeriodical(objBlock, firstInit) {
	//Also for mediablocks
	if ((objBlock.hasClass('Narrow'))) {
		if (objBlock.getElement('.periodicalItem')) {
			var periodicalItem = objBlock.getElement('.periodicalItem');
			var hoverArea = periodicalItem.getElement('.hoverArea');
			var periodicalMessage = periodicalItem.getElement('.periodicalMessage');
			periodicalMessage.setStyle('opacity', 0);
			var Tween1 = new Fx.Tween(hoverArea, {
				duration: 250,
				property: 'opacity',
				link: 'cancel',
				onComplete: function() {
					if (hoverArea.getStyle('opacity') == 0) {
						hoverArea.setStyle('z-index', 1);
						periodicalMessage.setStyle('z-index', 2);
					} else {
						periodicalMessage.setStyle('z-index', 'inherit');
						hoverArea.setStyle('z-index', 'inherit');
					}
				}
			});
			var Tween2 = new Fx.Tween(periodicalMessage, {
				duration: 250,
				property: 'opacity',
				link: 'cancel'
			});
			hoverArea.addEvent('mouseenter', function() {
				Tween1.start(0);
				Tween2.start(1);
			});
			periodicalItem.addEvent('mouseleave', function() {
				Tween1.start(1);
				Tween2.start(0);
			});
			periodicalMessage.addEvent('mouseleave', function() {
				Tween1.start(1);
				Tween2.start(0);
			});
		};
	};
	if (firstInit == false) initBlockSize(objBlock, firstInit);
}

function initTwitter(objBlock) {
	if (!(objBlock.hasClass('Twitter'))) return;
	
	var updateCounter = 0;
	var firstInit = 1;
	var blockId = getCurrentValue(objBlock, 0);
	var wideBlock = getCurrentValue(objBlock, 1);
	var currentItem;
	var objContent = objBlock.getElement('.blockContent');
	var defaultHeight = objContent.getSize().y;
	var objScroller = objContent.getElement('.blockContentScroller');
	var twitterTimer, twitterUpdateTimer;
	var Tween = new Fx.Tween(objScroller, {
		duration: 1000,
		property: 'top',
		onComplete: function() {
			var currentY = objScroller.getPosition(objContent).y;
			if (objContent.getElement($('t-' + objBlock.id + '-spacer'))) {
				var scrollerHeight = objScroller.getSize().y - objContent.getElement($('t-' + objBlock.id + '-spacer')).getSize().y;
				var contentHeight = objContent.getSize().y;
				var difHeight = scrollerHeight - Math.abs(currentY);
				if (difHeight >= contentHeight) {
					objContent.getElement($('t-' + objBlock.id + '-spacer')).dispose();
				};
			};
			if (currentY == 0) {
				var lastItem = objScroller.getElements('.twitterItem').getLast();
				if (lastItem.getPosition(objScroller).y > objContent.getSize().y) {
					var newItem = lastItem.clone();
					lastItemId = lastItem.id;
					lastItem.dispose();
					newItem.id = lastItemId;
					newItem.inject(objScroller, 'top');
					objScroller.setStyle('top', 0 - newItem.getSize().y);
					setTwitterEvents(newItem.id);
				};
			};
		}
	});
	
	objScroller.addEvent('mouseleave', function() {
		slideTwitter();
		clearInterval(twitterTimer);
		twitterTimer = slideTwitter.periodical(6000);
		objBlock.getElements('.twitterItem').each(function(tmpTwitterItem, i) {
			if (tmpTwitterItem.getElement('.twitterContainer')) {
				tmpTwitterItem.getElement('.twitterContainer').removeClass('selected');		
			};
		});
	});
	
	twitterUpdate()
	
	function setTwitterContentHeight() {
		var scrollerHeight = objScroller.getSize().y;	
		var currentHeight = objContent.getSize().y;
		if (scrollerHeight < defaultHeight && currentHeight != scrollerHeight) {
			objContent.setStyle('height', scrollerHeight);
			setContentHeight();
		} else if (currentHeight != defaultHeight) {
			objContent.setStyle('height', defaultHeight);
			setContentHeight;
		};
	}
	
	function slideTwitter() {
		if (currentItem) {
			var arrTweets = objScroller.getElements('.twitterItem');
			var previousTweet = -1;
			arrTweets.each(function(Tweet, i) {
				if (Tweet.id == currentItem.id) previousTweet = i - 1;
			});
			if (previousTweet >= 0) {
				currentItem = arrTweets[previousTweet];	
				var tweetHeight = currentItem.getSize().y;
				Tween.start(objScroller.getPosition(objContent).y + tweetHeight);
			};
		};
	}
	
	function twitterUpdate() {
		var req = new Request({
			url: '/includes/ajax.asp?script=twitterUpdate&blockId=' + blockId + '&wideBlock=' + wideBlock + '&firstInit=' + firstInit,
			onSuccess: function(txt) {
				if (txt != '') {
					clearInterval(twitterUpdateTimer);
					updateCounter += 1;
					if (firstInit == 1) objContent.removeClass('waitAnim');
					var arrTweets = txt.split('##||##');
					for (var x = 0; x < arrTweets.length; x++) {
						var newItem = new Element('div');
						newItem.addClass('twitterItem');
						newItem.set('id', 't-' + objBlock.id + '-' + updateCounter + '-' + x);
						newItem.set('html', arrTweets[x]);
						newItem.inject(objScroller, 'bottom');
						if (firstInit == 1 && x == (arrTweets.length - 1)) currentItem = newItem;
					};
					setTwitterContentHeight();
					var scrollerHeight = objScroller.getSize().y;
					var contentHeight = objContent.getSize().y;
					var currentHeight = currentItem.getSize().y;
					if (firstInit == 1) {
						var currentY = currentHeight - scrollerHeight;
						objScroller.setStyle('top', currentY);
						twitterTimer = slideTwitter.periodical(6000);
						firstInit = 0;
					};
					setTwitterEvents();
					var currentY = Math.abs($(objScroller).getPosition(objContent).y);
					var difHeight = scrollerHeight - currentY;
					if (difHeight < contentHeight) {
						difHeight = contentHeight - difHeight;
						var newItem = new Element('div');
						newItem.addClass('twitterItem');
						newItem.set('id', 't-' + objBlock.id + '-spacer');
						var newDiv = new Element('div');
						newDiv.addClass('twitterContainer');
						newDiv.setStyle('height', difHeight);
						newDiv.inject(newItem);
						newItem.inject(objScroller, 'bottom');
					};
					twitterUpdateTimer = twitterUpdate.periodical(60000);	
				};
			}
		}).send();
	}
	
	function setTwitterEvents(tweetId) {
		if (tweetId) {
			var twitterItems = objBlock.getElements($(tweetId));	
		} else {
			var twitterItems = objBlock.getElements('.twitterItem');	
		};
		twitterItems.each(function(twitterItem, i) {
			if (tweetId) {
				twitterItem.removeClass('hasEvents');
				twitterItem.removeEvents();
			};
			if (!(twitterItem.hasClass('hasEvents'))) {
				twitterItem.addClass('hasEvents');
				twitterItem.addEvent('mouseenter', function(){
					clearInterval(twitterTimer);
					twitterItem.getElement('.twitterContainer').addClass('selected');
				});
				twitterItem.addEvent('mouseleave', function(){
					twitterItem.getElement('.twitterContainer').removeClass('selected');
					if (twitterItem.getElement('.twitterBigImage')) {
						var twitterBigImage = twitterItem.getElement('.twitterBigImage')
						twitterBigImage.setStyles({
							'display': 'block',
							'opacity': 0
						});
						twitterBigImage.set('tween', {duration: 200});
						twitterBigImage.tween('opacity', 1);
					};
				});
				if (twitterItem.getElement('.twitterBigImage')) {
					twitterItem.getElement('.twitterBigImage').addEvent('mouseenter', function() {
						var TweenOut = new Fx.Tween(twitterItem.getElement('.twitterBigImage'), {
							duration: 200,
							property: 'opacity',
							link: 'cancel',
							onComplete: function() {
								twitterItem.getElement('.twitterBigImage').setStyle('display', 'none');
							}
						});
						TweenOut.start(0);
					});
				};
			};
		});
	}
}

function initCalendar(objBlock, firstInit) {
	if (!(objBlock.hasClass('Calendar')) && !(objBlock.hasClass('Media'))) return;
	
	var initialHeight = 88;
	var arrHeight = '0';
	var calendarItems = objBlock.getElements('.calendarItem');
	calendarItems.each(function(calendarItem, i) {
		if (objBlock.hasClass('Wide') || isMobile == 1) {
			var calendarMore = calendarItem.getElement('.calendarMore');
			var calendarContentMore = calendarItem.getElement('.calendarContentMore');
			var calendarMessage = calendarItem.getElement('.calendarMessage');
			var calendarMessageContent = calendarMessage.getElement('.calendarMessageContent');
			var sizeText = calendarMessageContent.getSize().y;
			if (calendarContentMore) {
				var maxHeight = 0;
				var calendarInfo = calendarItem.getElement('.calendarInfo');
				var hoverArea = calendarItem.getElement('.hoverArea');
				var sizeInfo = calendarInfo.getSize().y + (initialHeight + 4);
				maxHeight = (sizeInfo > sizeText) ? sizeInfo : sizeText;
				calendarInfo.setStyle('height', maxHeight - (initialHeight + 4));
				calendarMessageContent.setStyle('height', maxHeight);
				sizeText = calendarMessageContent.getSize().y;
				var sizeMore = calendarContentMore.getSize().y + initialHeight;
				maxHeight = (sizeMore > sizeText) ? sizeMore : sizeText;
				var parentTween = new Fx.Tween(calendarItem.getParent('.blockContent'), {
					duration: 400,
					property: 'height',
					link: 'cancel'
				});
				var Tween1 = new Fx.Tween(calendarContentMore, {
					duration: 400,
					property: 'height',
					link: 'cancel'
				});
				var Tween2 = new Fx.Tween(calendarMessage, {
					duration: 400,
					property: 'height',
					link: 'cancel'
				});
				var Tween3 = new Fx.Tween(calendarItem, {
					duration: 400,
					property: 'height',
					link: 'cancel',
					onComplete: function() {
						calendarContentMore.setStyle('visibility', (calendarItem.getStyle('height').toInt() == (initialHeight + 10)) ? 'hidden' : 'visible');
						initResizeBlock(objBlock);
						var timeoutId = (function(){ 
							setContentHeight();
						}).delay(1000);
					}
				});
				calendarMore.addEvent('click', function() {
					if (calendarMore.hasClass('calendarMoreActive')) {
						var dif = calendarItem.getSize().y - (initialHeight + 10);
						parentTween.start(calendarItem.getParent('.blockContent').getSize().y - dif);
						calendarMore.removeClass('calendarMoreActive');
						Tween1.start(0);
						Tween2.start(initialHeight);
						Tween3.start(initialHeight + 10);
						correctPositions(objBlock, 0 - dif, 400)
					} else {
						var dif = (maxHeight + 10) - calendarItem.getSize().y;
						parentTween.start(calendarItem.getParent('.blockContent').getSize().y + dif);
						calendarMore.addClass('calendarMoreActive');
						calendarContentMore.setStyle('visibility', 'visible');
						Tween1.start(maxHeight - initialHeight);
						Tween2.start(maxHeight);
						Tween3.start(maxHeight + 10);
						correctPositions(objBlock, dif, 400)
					}
				});
				hoverArea.addEvent('click', function() {
					calendarMore.fireEvent('click');
				});
				calendarMessageContent.addEvent('click', function() {
					calendarMore.fireEvent('click');
				});
				if (isMobile == 1) {
					calendarMessage.setStyle('opacity', 0);
					hoverArea.setStyle('opacity', 1);
					calendarMessageContent.addEvent('mouseenter', function() {
						calendarMessage.setStyle('opacity', 1);
						hoverArea.setStyle('opacity', 0);
					});
					calendarMessageContent.addEvent('mouseleave', function() {
						calendarMessage.setStyle('opacity', 0);
						hoverArea.setStyle('opacity', 1);
					});
				};
				if (calendarMore.hasClass('isOpen')) {
					calendarMore.removeClass('isOpen');
					calendarMore.fireEvent('click');
				};
			} else {
				if (objBlock.hasClass('Media')) {
					var calendarPreview = calendarItem.getElement('.calendarPreview');
					calendarPreview.removeEvents();
					calendarMore.removeEvents();
					calendarMore.addEvent('click', function() {
						var folderId = calendarItem.getElement('.folderId').value;
						changeBlockContent(objBlock, '6|' + folderId);
					});
					calendarPreview.addEvent('click', function() {
						calendarMore.fireEvent('click');
					});
				};
			};
		} else {
			var hoverArea = calendarItem.getElement('.hoverArea');
			var calendarMessage = calendarItem.getElement('.calendarMessage');
			var calendarMore = calendarItem.getElement('.calendarMore');
			var calendarPreview = calendarItem.getElement('.calendarPreview');
			var Tween1 = new Fx.Tween(hoverArea, {
				duration: 250,
				property: 'opacity',
				link: 'cancel'
			});
			var Tween2 = new Fx.Tween(calendarMessage, {
				duration: 250,
				property: 'opacity',
				link: 'cancel'
			});
			calendarMore.addEvent('mouseenter', function(){
				Tween1.start(0);
				Tween2.start(1);	
			});
			hoverArea.addEvent('mouseenter', function() {
				Tween1.start(0);
				Tween2.start(1);
			});
			calendarItem.addEvent('mouseleave', function() {
				Tween1.start(1);
				Tween2.start(0);
			});
			calendarMessage.addEvent('mouseleave', function() {
				Tween1.start(1);
				Tween2.start(0);
			});
			calendarMore.addEvent('click', function() {
				var pageId = calendarItem.getElement('input').value;
				var req = new Request({
					url: '/includes/ajax.asp?script=rewriteURL&pageId=' + pageId + '&placeId=0', 
					onSuccess: function(txt) {
						document.location.href = txt;
					}
				}).send();
			});
			calendarPreview.addEvent('click', function() {
				calendarMore.fireEvent('click');
			});
		};
		arrHeight += ',' + calendarItem.getSize().y;
	});
	arrHeight = arrHeight.split(',');
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	var scrollerHeight = objScroller.getSize().y;
	var mHeight = 0;
	if (arrHeight.length > 1) {
		for (var x = 1; x < arrHeight.length; x++) {
			if (objBlock.hasClass('Narrow') && x > 4 && isMobile == 0) break;
			mHeight += arrHeight[x].toInt();
		};	
	} else {
		mHeight = scrollerHeight;	
	};
	var newHeight = (scrollerHeight < mHeight) ? scrollerHeight : mHeight;
	if (firstInit == true) {
		objContent.setStyle('height', newHeight);
	} else {
		var Tween = new Fx.Tween(objContent, {
			duration: 400,
			property: 'height',
			onComplete: function() {
				setContentHeight();
				initBlockScroller(objBlock);
				blockRepair(objBlock, 1);
			}
		}).start(newHeight);
	};
}

function initMediaFolder(objBlock, folderId) {
	var Tweens = new Array();
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	var scrollerHeight = objScroller.getSize().y;
	var Tween = new Fx.Tween(objContent, {
		duration: 400,
		property: 'height',
		onComplete: function() {
			setContentHeight();
			initBlockScroller(objBlock);
			blockRepair(objBlock, 1);
			if (objBlock.hasClass('Narrow')) {
				if (folderId > 0) {
					var placeId = getCurrentValue(objBlock, 4).toInt();
					clearClass(objBlock.getElement('.iconInfo'), 'place');
					objBlock.getElement('.iconInfo').addClass('place' + placeId);
				}
				initPeriodical(objBlock, false);
			}
		}
	}).start(scrollerHeight);
}

function initIconPicker(objBlock) {
	var clickCount = 0;
	
	if (!(objBlock.getElement('.allIcons'))) return;
	
	if (objBlock.hasClass('Minimized')) {
		var children = objBlock.getChildren();
		children.each(function(child, i) {
			if (!(child.hasClass('blockHeader'))) child.setStyle('display', 'none');
		});
	};
	
	var blockHeader = objBlock.getElement('.blockHeader');
	if (blockHeader.getElement('.iconPlus')) {
		if (globalPageId == 0) {
			var iconPlus = blockHeader.getElement('.iconPlus');
			var iconPlusParent = iconPlus.getParent('div');
			iconPlusParent.dispose();
		};
	};
	
	var allIcons = blockHeader.getElement('.allIcons');
	var blockWidth = objBlock.getSize().x;
	allIcons.setStyle('width', blockWidth);
	
	var originalHeight = allIcons.getSize().y;
	var blockContent = objBlock.getElement('.blockContent');
	var contentHeight = blockContent.getSize().y;
	allIcons.setStyle('height', 0);
	allIcons.setStyle('visibility', 'hidden');
	var allElements = allIcons.getElements('div');
	allElements.each(function(element, i) {
		element.removeEvents();
	});
	
	var iconTween = new Fx.Tween(allIcons, {
		duration: 200,
		property: 'height',
		link: 'cancel',
		onComplete: function() {
			if (allIcons.getSize().y < 10) {
				allIcons.setStyle('visibility', 'hidden');
			};
		}
	});
	
	objBlock.getElement('.iconRight').addEvent('click', function() {
		if (objBlock.hasClass('Minimized')) {
			objBlock.removeClass('Minimized');
			var children = objBlock.getChildren();
			children.each(function(child, i) {
				if (!(child.hasClass('blockHeader'))) {
					child.setStyle('display', 'block');
				};
			});
			var blockId = getCurrentValue(objBlock, 0).toInt();
			var req = new Request({
				url: '/includes/ajax.asp?script=minimizeBlock&blockId=' + blockId
			}).send();
			initBlockSize(objBlock, true);
			initBlockScroller(objBlock);
			initResizeBlock(objBlock);
			blockRepair(objBlock, 1);
			setContentHeight();
		} else {
			if (objBlock.hasClass('Expanded')) {
				objBlock.removeClass('Expanded');
				iconTween.start(0);
			} else {
				objBlock.addClass('Expanded');
				allIcons.setStyle('visibility', 'visible');
				iconTween.start(originalHeight);
			};
		};
	});
	
	allIcons.addEvent('mouseleave', function() {
		if (objBlock.hasClass('Expanded')) {
			objBlock.removeClass('Expanded');
			iconTween.start(0);
		};
	});
	
	var iconBlocks = allIcons.getChildren('div');
	iconBlocks.each(function(iconBlock, i) {
		if (iconBlock.getElement('.iconMinus')) {
			iconBlock.addEvent('click', function() {
				iconTween.start(0);
				objBlock.addClass('Minimized');
				var children = objBlock.getChildren();
				children.each(function(child, i) {
					if (!(child.hasClass('blockHeader'))) {
						child.setStyle('display', 'none');
					}
				});
				var blockId = getCurrentValue(objBlock, 0).toInt();
				var req = new Request( {
					url: '/includes/ajax.asp?script=minimizeBlock&blockId=' + blockId
				}).send();
				blockRepair(objBlock, 1);
			});
		} else if (iconBlock.getElement('.iconPlus')) {
			var iconPlus = iconBlock.getElement('.iconPlus');
			iconBlock.addEvent('click', function() {
				iconTween.start(0);
				var blockId = getCurrentValue(objBlock, 0).toInt();
				var req = new Request( {
					url: '/includes/ajax.asp?script=updateGrid&blockId=' + blockId,
					onSuccess: function(txt) {
						if (txt.trim() != '') {
							startPopup(1);
						};
					}
				}).send();
				originalHeight -= iconPlus.getParent('div').getSize().y;
				iconPlus.getParent('div').dispose();
				(function() {
					blockRepair(objBlock, 1);
				}).delay(500);
			});
		} else if (iconBlock.getElement('.iconCross')) {
			iconBlock.addEvent('click', function() {
				var blockId = getCurrentValue(objBlock, 0).toInt();
				var req = new Request( {
					url: '/includes/ajax.asp?script=deleteBlock&blockId=' + blockId,
					onSuccess: function(txt) {
						blockRepair(objBlock, 2);
					}
				}).send();
			});
		};
	});
}

function initMonthPicker(objBlock) {
	if (!(objBlock.getElement('.monthPicker'))) return;
	
	var wideBlock = (objBlock.hasClass('Wide')) ? 1 : 0;
	var monthPicker = objBlock.getElement('.monthPicker');
	
	monthPicker.getElements('div').each(function(el) {
		el.removeEvents();
		
		if (objBlock.hasClass('Periodical')) {
			var arrPageId = getCurrentValue(objBlock, 9).split(',');
			if (arrPageId.length < 2) monthPicker.setStyle('display', 'none');
		};
		if (objBlock.hasClass('Media')) {
			var arrFolderId = getCurrentValue(objBlock, 7).split(',');
			if (arrFolderId.length < 2) monthPicker.setStyle('display', 'none');
		};
		if (monthPicker.getStyle('display') == 'none') {
			if (objBlock.getElement('.specialLink')) objBlock.getElement('.specialLink').addClass('noMargin');	
		};
		
		el.addEvent('click', function(event) {
			var direction = (el.hasClass('navRight')) ? 1 : -1;
			if (objBlock.hasClass('Periodical')) {
				var pageId = getCurrentValue(objBlock, 8).toInt();
				var arrPageId = getCurrentValue(objBlock, 9).split(',');
				for (var x = 0; x < arrPageId.length; x++) {
					if (arrPageId[x].toInt() == pageId.toInt()) {
						var newPageIndex = x + direction;
						if (newPageIndex >= arrPageId.length) newPageIndex = 0;
						if (newPageIndex < 0) newPageIndex = arrPageId.length - 1;
						pageId = arrPageId[newPageIndex];	
						break;
					};
				};
				changeBlockContent(objBlock, '8|' + pageId);
			} else if (objBlock.hasClass('Media')){
				var folderId = getCurrentValue(objBlock, 6);
				var arrFolderId = getCurrentValue(objBlock, 7).split(',');
				var arrPlaceId = getCurrentValue(objBlock, 5).split(',');
				for (var x = 0; x < arrFolderId.length; x++) {
					if (arrFolderId[x].toInt() == folderId.toInt()) {
						var newFolderIndex = x + direction;
						if (newFolderIndex >= arrFolderId.length) newFolderIndex = 0;
						if (newFolderIndex < 0) newFolderIndex = arrFolderId.length - 1;
						folderId = arrFolderId[newFolderIndex];	
						var placeId = arrPlaceId[newFolderIndex];
						break;
					}
				}
				changeBlockContent(objBlock, '4|' + placeId + '#6|' + folderId);
			} else if (objBlock.hasClass('Calendar')) {
				var intMonth = getCurrentValue(objBlock, 2).toInt();
				var intYear = getCurrentValue(objBlock, 3).toInt();
				intMonth += direction;
				if (intMonth == 13) {
					intMonth = 1;
					intYear += 1;
				}
				if (intMonth == 0) {
					intMonth = 12;
					intYear -= 1;
				}
				var req = new Request({
					url: '/includes/ajax.asp?script=putMonthYear&intMonth=' + intMonth + '&intYear=' + intYear,
					onSuccess: function(txt) {
						monthPicker.getElement('p').set('html', txt);
						changeBlockContent(objBlock, '2|' + intMonth + '#3|' + intYear);
					}
				}).send();
			}
		});
	});
}

function initPlacePicker(objBlock) {
	if (!(objBlock.getElement('.placePicker'))) return;
	
	var isActive = false;
	var placePicker = objBlock.getElement('.placePicker');
	if (!(placePicker.getElement('.allPlaces'))) return;
	var placeContainer = placePicker.getElement('.allPlaces');
	var originalHeight = placeContainer.getSize().y;
	placeContainer.setStyle('height', 0);
	placeContainer.setStyle('visibility', 'visible');
	var objContent = objBlock.getElement('.blockContent');
	var originalContentHeight = objContent.getSize().y;
	var placeLists = placePicker.getElements('.allPlaces div')
	
	placeLists.each(function(listItem, i) {
		listItem.addEvent('mouseover', function() {
			var placeId = getClass(listItem, 'place').toInt();
			objBlock.getElement('.textRight').set('html', listItem.get('html'));
			clearClass(placePicker, 'place');
			placePicker.addClass('place' + placeId);
		});
		listItem.addEvent('click', function() {
			var placeId = getClass(listItem, 'place').toInt();
			clearClass(objBlock.getElement('.iconInfo'), 'place');
			clearClass(placePicker, 'place');
			objBlock.getElement('.iconInfo').addClass('place' + placeId);
			placePicker.addClass('place' + placeId);
			placePicker.getElement('input').value = placeId;
			objBlock.getElement('.textRight').set('title', listItem.get('html'));
			objBlock.getElement('.textRight').set('html', listItem.get('html'));
			placeTween.start(0);
			changeBlockContent(objBlock, '4|' + placeId + '#5|' + placeId + '#6|0#7|');
		});
	});
	
	placeContainer.addEvent('mouseleave', function() {
		var placeId = placePicker.getElement('input').value;
		clearClass(placePicker, 'place');
		placePicker.addClass('place' + placeId);
		objBlock.getElement('.textRight').set('html', objBlock.getElement('.textRight').get('title'));
	});
	var placeTween = new Fx.Tween(placeContainer, {
		duration: 400,
		property: 'height',
		onComplete: function() {
			isActive = (isActive == true) ? false : true;
		}
	});
	objBlock.getElement('.textRight').addEvent('click', function() {
		if (isActive == false) {
			placeTween.start(originalHeight);
			correctPositions(objBlock, originalHeight, 400);
		} else {
			placeTween.start(0);
			correctPositions(objBlock, 0 - originalHeight, 400);	
		}
	});
	placePicker.addEvent('mouseleave', function() {
		if (isActive == true) {
			placeTween.start(0);
			correctPositions(objBlock, 0 - originalHeight, 400);
		}
	});
}

function changeBlockContent(objBlock, arrVars) {
	arrVars = arrVars.split('#');
	for (var x = 0; x < arrVars.length; x++) {
		var arrSet = arrVars[x].split('|');	
		var index = arrSet[0];
		var strValue = arrSet[1];
		setCurrentValue(objBlock, index, strValue);
	}
	
	var blockId = getCurrentValue(objBlock, 0).toInt();
	var wideBlock = getCurrentValue(objBlock, 1).toInt();
	var intMonth = getCurrentValue(objBlock, 2).toInt();
	var intYear = getCurrentValue(objBlock, 3).toInt();
	var placeId = getCurrentValue(objBlock, 4).toInt();
	var arrPlaceId = getCurrentValue(objBlock, 5);
	var folderId = getCurrentValue(objBlock, 6).toInt();
	var arrFolderId = getCurrentValue(objBlock, 7);
	var pageId = getCurrentValue(objBlock, 8).toInt();
	var arrPageId = getCurrentValue(objBlock, 9);
	
	var objHeader = objBlock.getElement('.blockHeader');
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	
	if (objBlock.getElement('.blockScroller')) {
		var blockScroller = objBlock.getElement('.blockScroller');
		blockScroller.getElements('div').each(function(el) {
			el.removeEvents();
		});
	}
	
	var urlScript = '';
	var isMediaBlock = objBlock.hasClass('Media');
	var isPeriodicalBlock = objBlock.hasClass('Periodical');
	var isCalendarBlock = objBlock.hasClass('Calendar');
	
	var tweenProperty = 'height';
	var tweenDuration = 400;
	var tweenValue = 0;
	
	if (isMediaBlock) {
		if (folderId > 0 && wideBlock == 1) {
			urlScript = 'mediaFolder';
		} else {
			urlScript = 'mediaItems';
		}
		blockRepair(objBlock, 0);
		var objTween = objBlock.getElement('.blockContent');
	} else if (isPeriodicalBlock) {
		urlScript = 'periodicalItem';
		tweenProperty = 'opacity';
		tweenDuration = 200;
		var objTween = objBlock.getElement('.blockContentScroller');
		objContent.addClass('blockContentWhite');
	} else {
		urlScript = 'calendarItems';
		blockRepair(objBlock, 0);
		var objTween = objBlock.getElement('.blockContent');
	}
	var Tween = new Fx.Tween(objTween, {
		duration: tweenDuration,
		property: tweenProperty,
		onComplete: function() {
			var req = new Request( {
				url: '/includes/ajax.asp?script=' + urlScript +
					'&blockId=' + blockId +
					'&wideBlock=' + wideBlock +
					'&intMonth=' + intMonth +
					'&intYear=' + intYear +
					'&placeId=' + placeId +
					'&arrPlaceId=' + arrPlaceId +
					'&folderId=' + folderId +
					'&arrFolderId=' + arrFolderId +
					'&pageId=' + pageId +
					'&arrPageId=' + arrPageId,
				onSuccess: function(txt) {
					var result = txt.split('##||##');
					if (result.length == 2) {
						txt = result[1];
						arrVars = result[0].split('#');
						for (var x = 0; x < arrVars.length; x++) {
							var arrSet = arrVars[x].split('|');	
							var index = arrSet[0];
							var strValue = arrSet[1];
							setCurrentValue(objBlock, index, strValue);
						}
					} else {
						txt = result[0];
					}
					objScroller.setStyle('top', 0);
					objScroller.set('html', txt);
					
					if (isMediaBlock) {
						if (folderId > 0) {	
							initMediaFolder(objBlock, folderId);
							if (objBlock.getElement('.blockInfo') && wideBlock == 1) {
								var blockInfo = objBlock.getElement('.blockInfo');
								blockInfo.set('html', 'terug');
								blockInfo.addEvent('click', function(event) {
									blockInfo.set('html', '');
									blockInfo.removeEvents();
									changeBlockContent(objBlock, '6|0#4|-1');
									return;
								});
							}
						} else {
							initCalendar(objBlock, false);
						}
					} else if (isPeriodicalBlock) {
						setPageClass(objBlock, pageId);
						initPeriodical(objBlock, false);
					} else if (isCalendarBlock) {
					 	if (objBlock.getElement('.blockInfo')) {
							var blockInfo = objBlock.getElement('.blockInfo');
							blockInfo.set('html', '');
						}
						initCalendar(objBlock, false);
					}
					initResizeBlock(objBlock);
				}
			}).send();
		}
	}).start(tweenValue);
}

function checkBlockScroller(objBlock) {
	//Check visibility of scroll arrows
	if (!(objBlock.getElement('.blockScroller'))) return;
	
	var blockScroller = objBlock.getElement('.blockScroller');
	var navLeft = blockScroller.getElement('.navLeft');
	var navRight = blockScroller.getElement('.navRight');
	var pText = blockScroller.getElement('p');
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	
	var containerHeight = objContent.getSize().y;
	var divHeight = objScroller.getSize().y;
	var minY = containerHeight - divHeight;
	var currentY = objScroller.getPosition(objContent).y;
	navLeft.setStyle('visibility', (currentY == 0) ? 'hidden' : 'visible');
	navRight.setStyle('visibility', (currentY == minY) ? 'hidden' : 'visible');
	pText.setStyle('visibility', (navLeft.getStyle('visibility') == 'visible' || navRight.getStyle('visibility') == 'visible') ? 'visible' : 'hidden');
}

function initBlockScroller(objBlock) {
	if (!(objBlock.getElement('.blockScroller'))) return;
	
	var direction, containerHeight, divHeight, scrollStep, minY, currentY, diffY, isBusy, newTween, newY;
	var blockScroller = objBlock.getElement('.blockScroller');
	var navLeft = blockScroller.getElement('.navLeft');
	var navRight = blockScroller.getElement('.navRight');
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	
	checkBlockScroller(objBlock);
	
	blockScroller.getElements('div').each(function(el) {
		
		if (isTablet) {
		
			el.addEvent('click', function(event) {
				direction = (el.hasClass('navLeft')) ? 1 : -1;
				containerHeight = objContent.getSize().y.toInt();
				divHeight = objScroller.getSize().y.toInt();
				scrollStep = (containerHeight / 1.5).toInt();
				minY = containerHeight - divHeight
				currentY = objScroller.getPosition(objContent).y;
				objScroller.setStyle('top', currentY);
				currentY += scrollStep * direction;
				if (currentY < minY) currentY = minY;
				if (currentY > 0) currentY = 0;
				newTween = new Fx.Tween(objScroller, {
					duration: 600,
					property: 'top',
					transition: Fx.Transitions.Quad.easeOut,
					onComplete: function() {
						isBusy = false;
						checkBlockScroller(objBlock);
					}
				});
				newTween.start(currentY);
			})
		
		}
		
		if (isTablet == false) {
			
			el.addEvent('mouseenter', function(event) {
				containerHeight = objContent.getSize().y;
				divHeight = objScroller.getSize().y;
				minY = containerHeight - divHeight;
				currentY = objScroller.getPosition(objContent).y;
				objScroller.setStyle('top', currentY);
				newY = (el.hasClass('navLeft')) ? 0 : minY;
				diffY = Math.abs(newY - currentY) * 5;
				if (diffY == 0) return;
				newTween = new Fx.Tween(objScroller, {
					duration: diffY,
					property: 'top',
					transition: Fx.Transitions.Quad.easeOut,
					onComplete: function() {
						isBusy = false;
						checkBlockScroller(objBlock);
					}
				});
				isBusy = true;
				newTween.start(newY);
			})
			
			el.addEvent('mouseleave', function(event) {
				if (isBusy == true) {
					newTween.stop();
					isBusy = false;
					checkBlockScroller(objBlock);
				}
			})
		}
	});
}

function initResizeBlock(objBlock) {
	var contentSize, difHeight, contentHeight;
	
	if (!(objBlock.getElement('.blockContent')) || !(objBlock.getElement('.blockResize'))) return;
	var objContent = objBlock.getElement('.blockContent');
	var objScroller = objContent.getElement('.blockContentScroller');
	var objHandle = objBlock.getElement('.blockResize');
	var scrollerSize = objScroller.getSize();
	if (objContent.hasClass('isResizable')) {
		var counter = 0;
		var blocks = $$('div.contentBlock');
		blocks.each(function(block, i) {
			if (block.getElement('.blockContent')) {
				if (block.getElement('.blockContent').hasClass('isResizable')) {
					counter += 1;
					if (objBlock.id == block.id) {
						myResize[counter].detach();
						resizeCounter = counter;
					};
				};
			};
		})
	} else {
		resizeCounter += 1;
		objContent.addClass('isResizable');
	};
	
	if (myResize[resizeCounter]) {
		myResize[resizeCounter].removeEvents();
	};
	
	myResize[resizeCounter] = objContent.makeResizable({
		handle: objHandle,
		limit: {x:[scrollerSize.x,scrollerSize.x],y:[0,scrollerSize.y]},
		onSnap: function(cblock) {
			cblock.addClass('dragging');
			cblock.setStyle('opacity', 0.5);
			contentHeight = cblock.getSize().y;
		},
		onComplete: function(cblock) {
			cblock.removeClass('dragging');
			cblock.setStyle('opacity', 1);
			setContentHeight();
		},
		onDrag: function(cblock) {
			setContentHeight();
			var containerHeight = objContent.getSize().y;
			var divHeight = objScroller.getSize().y;
			var currentY = objScroller.getPosition(objContent).y;
			if (currentY < 0 && (Math.abs(currentY) + containerHeight) > divHeight) {
				currentY = containerHeight - divHeight;
				objScroller.setStyle('top', currentY);
			}
			contentSize = cblock.getSize();
			difHeight = contentSize.y - contentHeight;
			contentHeight = contentSize.y;
			correctPositions(objBlock, difHeight);
			checkBlockScroller(objBlock);
		}
	});
}

function getCurrentValue(objBlock, index) {
	var currentValues = objBlock.getElement('.currentValues').value.split('|');
	return currentValues[index];
}

function setCurrentValue(objBlock, index, strValue) {
	var currentValues = objBlock.getElement('.currentValues').value.split('|');
	var newValues = '';
	for (var x = 0; x < currentValues.length; x++) {
		if (newValues != '') newValues += '|';
		newValues += (x == index) ? strValue : currentValues[x];
	};
	objBlock.getElement('.currentValues').value = newValues;
}

function clearClass(objElement, className) {
	var arrAllId = $('all_' + className).value.split(',');
	for (var x = 0; x < arrAllId.length; x++) {
		if (objElement.hasClass(className + arrAllId[x])) objElement.removeClass(className + arrAllId[x]);
	};
}

function getClass(objElement, className) {
	var arrAllId = $('all_' + className).value.split(',');
	for (var x = 0; x < arrAllId.length; x++) {
		if (objElement.hasClass(className + arrAllId[x])) {
			return arrAllId[x];
		};
	};
	return 0;
}

function setPageClass(objBlock, pageId) {
	var iconInfo = objBlock.getElement('.iconInfo');
	var req = new Request({
		url: '/includes/ajax.asp?script=setPageClass&pageId=' + pageId, 
		onSuccess: function(txt) {
			var result = txt.split('##||##');
			clearClass(iconInfo, 'place');
			iconInfo.addClass(result[1]);
			if (objBlock.getElement('.monthPicker p')) {
				objBlock.getElement('.monthPicker p').set('html', result[0]);
			}
		}
	}).send();
}

var slideShowOverlay, slideShowContainer, slideShowLeftButton, slideShowRightButton, slideShowCloseButton, slideShowPlayButton;
var slideShowInfoText, slideShowImages, slideShowNavInfo, slideShowCurrentImage, slideShowLoader, slideShowTimer, slideShowSetTimer;
var slideShowImageLeft, slideShowImageRight
function startSlideShow(baseId) {
	var arrTmp, title, text, arrBase, arrSize;
	var lastId = 0
	var arrImageId = new Array();
	var arrImageName = new Array();
	var arrWidth = new Array();
	var arrHeight = new Array();
	var arrTitle = new Array();
	
	if (!($('slideShowContainer'))) {
		slideShowContainer = new Element('div', { 
			'id': 'slideShowContainer'
		}).inject($(document.body));
		slideShowOverlay = new Element('div#slideShowOverlay').inject(slideShowContainer);
		slideShowLeftButton = new Element('div.leftButton').inject(slideShowContainer);
		slideShowRightButton = new Element('div.rightButton').inject(slideShowContainer);
		slideShowCloseButton = new Element('div.closeButton').inject(slideShowContainer);
		slideShowPlayButton = new Element('div.playButton').inject(slideShowContainer);
		slideShowInfoText = new Element('div.infoText').inject(slideShowContainer);
		slideShowImages = new Element('div.imageContainer').inject(slideShowContainer);
		slideShowImageLeft = new Element('div.imageLeft').inject(slideShowContainer);
		slideShowImageRight = new Element('div.imageRight').inject(slideShowContainer);
		slideShowNavInfo = new Element('div.navInfo').inject(slideShowContainer);
		slideShowLoader = new Element('div.waitAnim').inject(slideShowContainer);
		slideShowCloseButton.addEvent('click', function() {
			clearInterval(slideShowTimer);
			clearInterval(slideShowSetTimer);
			slideShowOverlay.setStyles({
				'height': 0,
				'display': 'none',
				'opacity': 0
			});
			slideShowContainer.setStyles({
				'height': 0,
				'display': 'none'
			});
		});
		slideShowPlayButton.addEvent('click', function() {
			if (slideShowPlayButton.hasClass('pauseButton')) {
				slideShowPlayButton.removeClass('pauseButton');
				clearInterval(slideShowTimer);
			} else {
				slideShowPlayButton.addClass('pauseButton');
				slideShowTimer = executeSlideShow.periodical(6000);
			};
		});
		slideShowOverlay.addEvent('click', function() {
			slideShowCloseButton.fireEvent('click');
		});
		
		slideShowImageLeft.addEvent('click', function() {
			slideShowLeftButton.fireEvent('click');
		});
		slideShowImageRight.addEvent('click', function() {
			slideShowRightButton.fireEvent('click');
		});
	};
	
	slideShowPlayButton.removeClass('pauseButton');
	slideShowImages.set('html', '');
	slideShowNavInfo.set('html', '');
	slideShowContainer.setStyles({
		'top': 0,
		'height': window.getSize().y,
		'display': 'block',
	});
	slideShowOverlay.setStyles({
		'top': 0,
		'height': slideShowContainer.getSize().y,
		'display': 'block',
		'opacity': 0.9
	});
	
	var buttonTop = ((window.getSize().y - slideShowLeftButton.getSize().y) / 2).toInt();
	slideShowLeftButton.setStyle('top', buttonTop);
	slideShowRightButton.setStyle('top', buttonTop);
	slideShowLoader.setStyle('visibility', 'hidden');
	setSlideShow();
	
	function setSlideShow() {
		clearInterval(slideShowSetTimer);
		var tmpLastId = lastId;
		var req = new Request({
			url: '/includes/ajax.asp?script=getSlideShow&baseId=' + baseId + '&lastId=' + lastId + '&windowWidth=' + (window.getSize().x - 100) + '&windowHeight=' + (window.getSize().y - 160),
			onSuccess: function(txt) {
				arrTmp = txt.split('####||||####');
				title = arrTmp[0];
				text = arrTmp[1];
				arrSize = arrTmp[3].split(',');
				if (arrTmp[4].toInt() > 0) lastId = arrTmp[4].toInt();
				if (tmpLastId > 0) {
					var tmpArrBase = arrBase.join('###|||###');
					arrBase = arrTmp[2];
					if (tmpArrBase != '' && arrBase != '') tmpArrBase += '###|||###';
					arrBase = tmpArrBase + arrBase;
					arrBase = arrBase.split('###|||###');
				} else {
					arrBase = arrTmp[2].split('###|||###');
				};
				slideShowInfoText.set('html', '<h2>' + title + '</h2>' + text);
				slideShowImages.setStyles({
					'width': arrSize[0].toInt(),
					'height': arrSize[1].toInt(),
					'left': ((window.getSize().x - arrSize[0]) / 2).toInt(),
					'top': ((window.getSize().y - arrSize[1]) / 2).toInt()
				});
				slideShowLoader.setStyles({
					'left': slideShowImages.getStyle('left'),
					'top': slideShowImages.getStyle('top'),
					'margin-left': ((arrSize[0] - slideShowLoader.getSize().x) / 2).toInt(),
					'margin-top': ((arrSize[1] - slideShowLoader.getSize().y) / 2).toInt()
				});
				slideShowNavInfo.setStyles({
					'width': arrSize[0].toInt(),
					'left': ((window.getSize().x - arrSize[0]) / 2).toInt(),
					'top': ((window.getSize().y - arrSize[1]) / 2).toInt() + arrSize[1].toInt() + 10
				});
				if (tmpLastId == 0) slideShowCurrentImage = 0;
				for (var x = 0; x < arrBase.length; x++) {
					var arrTmp = arrBase[x].split('##||##');
					arrImageId[x] = arrTmp[0].toInt();
					if (arrImageId[x].toInt() == baseId.toInt() && tmpLastId == 0) slideShowCurrentImage = x;
					arrImageName[x] = arrTmp[1];
					arrWidth[x] = arrTmp[2].toInt();
					arrHeight[x] = arrTmp[3].toInt();
					arrTitle[x] = arrTmp[4];
				};
				if (tmpLastId == 0) {
					showSlideShowImage();
					slideShowLeftButton.removeEvents();
					slideShowRightButton.removeEvents();
					slideShowLeftButton.addEvent('click', function() {
						slideShowCurrentImage -= 1;
						if (slideShowCurrentImage < 0) slideShowCurrentImage = arrBase.length - 1;
						showSlideShowImage();
					});
					slideShowRightButton.addEvent('click', function() {
						slideShowCurrentImage += 1;
						if (slideShowCurrentImage >= arrBase.length) slideShowCurrentImage = 0;
						showSlideShowImage();
					});
				};
				slideShowSetTimer = setSlideShow.periodical(60000);
			}
		}).send();
	}
	
	function executeSlideShow() {
		slideShowRightButton.fireEvent('click');
	}
	
	function showSlideShowImage() {
		slideShowLoader.setStyle('visibility', 'visible');
		var html = '';
		var imageHeight = arrHeight[slideShowCurrentImage].toInt();
		var divHeight = slideShowImages.getSize().y.toInt();
		var paddingTop = ((divHeight - imageHeight) / 2).toInt();
		var myImage = new Asset.image('/files/media_base/work/' + arrImageName[slideShowCurrentImage], {
			onLoad: function() {
				slideShowImages.set('html', '<img style="padding-top:' + paddingTop + 'px;" src="/files/media_base/work/' + arrImageName[slideShowCurrentImage] + '" width="' + arrWidth[slideShowCurrentImage] + '" height="' + arrHeight[slideShowCurrentImage] + '" alt="" />');
				var width = arrWidth[slideShowCurrentImage].toInt();
				var height = arrHeight[slideShowCurrentImage].toInt();
				slideShowImageLeft.setStyles({
					'width': (width / 2).toInt(),
					'left': ((window.getSize().x - width) / 2).toInt(),
					'top': ((window.getSize().y - height) / 2).toInt(),
					'height': height
				});
				slideShowImageRight.setStyles({
					'width': (width / 2).toInt(),
					'left': ((window.getSize().x - width) / 2).toInt() + (width / 2).toInt(),
					'top': ((window.getSize().y - height) / 2).toInt(),
					'height': height
				});
				html = (slideShowCurrentImage + 1) + ' van ' + arrBase.length;
				if (arrTitle[slideShowCurrentImage] != '') {
					html += ' - ' + arrTitle[slideShowCurrentImage];
				}
				slideShowNavInfo.set('html', html);
				slideShowImages.setStyle('display', 'block');
				slideShowLoader.setStyle('visibility', 'hidden');
			}
		});
	}
	return false;
}

var popupOverlay, popupContainer, popupMother, popupCloseButton
function startPopup(popupId) {
	if (!($('popupContainer'))) {
		popupContainer = new Element('div', { 
			'id': 'popupContainer'
		}).inject($(document.body));
		popupOverlay = new Element('div#popupOverlay').inject(popupContainer);
		popupMother = new Element('div#popupMother').inject(popupContainer);
		popupOverlay.addEvent('click', function() {
			popupOverlay.setStyles({
				'height': 0,
				'display': 'none',
				'opacity': 0
			});
			popupContainer.setStyles({
				'height': 0,
				'display': 'none'
			});
		});
	};
	popupContainer.setStyles({
		'top': 0,
		'height': window.getSize().y,
		'display': 'block',
	});
	popupOverlay.setStyles({
		'top': 0,
		'height': popupContainer.getSize().y,
		'display': 'block',
		'opacity': 0.9
	});
	
	var req = new Request.HTML({
		url: '/files/popup/' + popupId + '.htm',
		onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
			var arrTmp = responseHTML.split('###|||###');
			var arrWH = arrTmp[0].split(',');
			var html = arrTmp[1];
			var popupWidth = arrWH[0].toInt();
			var popupHeight = arrWH[1].toInt();
			popupMother.setStyles({
				'width': popupWidth,
				'height': popupHeight,
				'left': ((popupContainer.getSize().x - popupWidth) / 2).toInt(),
				'top': ((popupContainer.getSize().y - popupHeight) / 2).toInt()
			});
			popupMother.set('html', html);
		}
	}).get();
	
	return false;
}

function popupClose() {
	popupOverlay.fireEvent('click');	
	return false;
}





























function keyStroke(e, validate) {
	var key = window.event ? e.keyCode : e.which;
	if (key == 8 || key == 0) return true;
	if (key == 124 ) return false;
	if (validate == 1 && key == 32) return false;
	if (validate == 3 || validate == 2) {
		if (key < 48 || key > 57) {
			if (key != 44 && key != 45) {
				return false;
			} else {
				if (validate == 2 && key == 44) {
					return false;
				}
			}
		}
	}
}

function checkForm(formIdentifier) {
	var formitem = $('checkfields' + formIdentifier).value.split('#**#');
	for (var x = 0; x < formitem.length; x++) {
		var formproperties = formitem[x].split('#|#');
		var formfield = formproperties[0];
		var fieldname = formproperties[1];
		var validate = parseInt(formproperties[2]);
		var compulsary = parseInt(formproperties[3]);
		var unique = parseInt(formproperties[4]);
		if (validate != 2) {
			if ($(formfield)) {
				var a = $(formfield).value.trim();
				$(formfield).value = a;
			}
		}
		if (compulsary == 1) {
			if ($(formfield).value == '') {
				if ($(formfield).getStyle('visibility') != 'hidden') {
					translate(3, '', ': ' + fieldname);
					$(formfield).focus();
					return false;
				}
			}
		}
		if (validate == 1) {
			if (emailCheck(formfield, compulsary) == false) {
				translate(4, '', '');
				$(formfield).focus();
				return false;
			}
		}
		if (unique == 1) {
			var result = $(formfield + '_unique').value.toInt();
			if (result == 0) {
				translate(5, '', ': ' + fieldname);
				$(formfield).focus();
				return false;
			}
		}
	}
	return;
}

function emailCheck(formfield, compulsary) {
	var emailStr = $(formfield).value
	if (compulsary == 0 && emailStr == '') return true;
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) return false;
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i = 0; i < user.length; i++) {
		if (user.charCodeAt(i) > 127) return false;
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i) > 127) return false;
	}
	if (user.match(userPat)==null) return false;
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i = 1;i <= 4; i++) {
			if (IPArray[i] > 255) return false;
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i = 0; i < len; i++) {
		if (domArr[i].search(atomPat) == -1) return false;
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) return false;
	if (len < 2) return false;
	return true;
}

function translate(id, before, after) {
	var req = new Request({
		url: '/includes/ajax.asp?script=translate&id=' + id,
		onSuccess: function(txt) {
			var response = before + txt + after;
			alert(response);
		}
	}).send();
}

function checkUnique(dbtable, dbfield, id, formfield) {
	var req = new Request({
		url: '/includes/ajax.asp?script=checkunique&dbtable=' + dbtable + '&dbfield=' + dbfield + '&dbvalue=' + escape(document.getElementById(formfield).value) + '&id=' + id,
		onSuccess: function(txt) {
			$(formfield + '_unique').value = txt;
		}
	}).send();
}

var infoWindow;

function downloadUrl(url, callback) {
	var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = function() {}; 
			callback(request, request.status);
			}
	};
	request.open('GET', url, true);
	request.send(null);
}

function bindInfoWindow(marker, map, infoWindow, html) {
	google.maps.event.addListener(marker, 'click', function() {
		infoWindow.setContent(html);
		infoWindow.open(map, marker);
	});
}

function gmInitialize(mapId, latitude, longitude) {
	infoWindow = new google.maps.InfoWindow;
	var myNavControlOptions = { style: google.maps.NavigationControlStyle.SMALL	};
	var myMapControlOptions = { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU };
	var bounds = new google.maps.LatLngBounds();
	var myLatLng = new google.maps.LatLng(latitude, longitude);
	bounds.extend(myLatLng);
	var myOptions = {
		zoom: 15,
		center: myLatLng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		navigationControl: true,
		navigationControlOptions: myNavControlOptions,
		mapTypeControl: true,
		mapTypeControlOptions: myMapControlOptions
	};
	var map = new google.maps.Map(document.getElementById('map' + mapId), myOptions);
	var marker = new google.maps.Marker({
		position: myLatLng, 
		map: map,
		draggable: false,
		clickable: false
	});
}

