function initServiceNavi() {
	var naviItems = $$('div.serviceNavi ul li a');
	naviItems.each(function(item) {
		if($(item).hasClass('language')) {
			return;
		}
		item.addEvent('click', function() {
			if (loading) {
				return false;
			}
			loading = true;
			fadeContent(this.getProperty('href'));
			return false;
		});
	});
}

function initCloseButton() {
	var closeButtons = $$('div.window p.closeButton a');
	closeButtons.each(function(item) {
		item.addEvent('click', function() {
			if (loading) {
				return false;
			}
			loading = true;
			fadeContent(this.getProperty('href'));
			return false;
		});
	});
}

function initTabLinks() {
	var tabButtons = $$('div.window div.windowHeader a');
	tabButtons.each(function(item) {
		item.addEvent('click', function() {
			if (loading) {
				return false;
			}
			loading = true;
			fadeWindowContent(this.getProperty('href'));
			var tabButtons = $$('div.window div.windowHeader a');
			tabButtons.each(function(item) {
				item.removeClass('active');
			});
			this.addClass('active');
			return false;
		});
	});
}

function showLightBox(imgPath) {
	var overlayNode = $('overlay');
	var lightBoxContainerNode = $('lightbox-container');
	var lightBoxNode = $('lightbox');
	if (overlayNode && lightBoxContainerNode && lightBoxNode) {
		lightBoxNode.innerHTML = '<img src="' + imgPath + '" alt="" />';
		overlayNode.setStyles({'opacity':0.9, 'background':'#000', 'top':'0px','left':'0px','width':'100%','height':'100%'});
		overlayNode.addClass('show');
		lightBoxContainerNode.setStyles({'opacity':0});
		lightBoxContainerNode.addClass('show');
		var fadeFx = new Fx.Tween(lightBoxContainerNode, {
			duration: 300, 
			transition: new Fx.Transition(Fx.Transitions.Sine).easeOut,
			onComplete: function(){
				$('lightbox-container').setStyles({'opacity':1});	
			}
		});
		//$('lightbox-container').setStyles({'opacity':1}).delay(350,$('lightbox-container'));
		fadeFx.start('opacity', 1);			
	}	
}

function initVideoLinks() {
	var links = $$('a.video');
	links.each(function(item) {
		item.addEvent('click', function() {
			var flv = this.getProperty('href');
			var overlayNode = $('overlay');
			var videoContainerNode = $('video-container');
			var videoNode = $('video');
			if (overlayNode && videoContainerNode && videoNode) {
				videoNode.innerHTML = '';
				videoContainerNode.addClass('show');
				overlayNode.setStyles({'opacity':0.9, 'background':'#fff'});
				overlayNode.addClass('show');
				var obj = new Swiff('/media/flash/player_flv.swf', {
					id: 'videoFlash',
					container: videoNode,
					width: 500,
					height: 500,
					params: {
					    wmode: 'transparent'
					},
					vars: {
						flv: flv,
						width: 500,
						height: 500,
						autoplay: 1,
						margin: 0,
						phpstream: 0
				    }
				});
			}
			return false;
		});
	});
}

function initVideoCloseButton() {
	var link = $$('#video-container p.closeButton');
	if (link.length > 0) {
		link[0].addEvent('click', function() {
			var overlayNode = $('overlay');
			var videoContainerNode = $('video-container');
			var videoNode = $('video');
			if (overlayNode && videoContainerNode && videoNode) {
				videoNode.innerHTML = '';
				videoContainerNode.removeClass('show');
				overlayNode.removeClass('show');
			}
		});
	} 
	link = $$('#lightbox-container p.closeButton');
	if (link.length > 0) {
		link[0].addEvent('click', function() {
			var overlayNode = $('overlay');
			var lightBoxContainerNode = $('lightbox-container');
			var lightBoxNode = $('lightbox');
			if (overlayNode && lightBoxContainerNode && lightBoxNode) {
				lightBoxNode.innerHTML = '';
				lightBoxContainerNode.removeClass('show');
				overlayNode.removeClass('show');
			}
		});
	} 
	
}

function initLinks() {
	initCloseButton();
	initTabLinks();
	initServiceNavi();
	initVideoCloseButton();
	initVideoLinks();
}

window.addEvent('domready', function() {
	initLinks();
});