var SiteClass = new Class({

	initialize: function(){
	
		hs.lang.cssDirection = lang.cssDirection;
		hs.lang.loadingText = lang.loadingText;
		hs.lang.loadingTitle = lang.loadingTitle;
		hs.lang.focusTitle = lang.focusTitle;
		hs.lang.fullExpandTitle = lang.fullExpandTitle;
		hs.lang.previousText = lang.previousText;
		hs.lang.nextText = lang.nextText; 
		hs.lang.moveText = lang.moveText;
		hs.lang.closeText = lang.closeText; 
		hs.lang.closeTitle = lang.closeTitle; 
		hs.lang.resizeTitle = lang.resizeTitle;
		hs.lang.playText = lang.playText;
		hs.lang.playTitle = lang.playTitle;
		hs.lang.pauseText = lang.pauseText;
		hs.lang.pauseTitle = lang.pauseTitle;
		hs.lang.previousTitle = lang.previousTitle;
		hs.lang.nextTitle = lang.nextTitle;
		hs.lang.moveTitle = lang.moveTitle;
		hs.lang.fullExpandText = lang.fullExpandText;
		hs.lang.number = lang.number;
		hs.lang.restoreTitle = lang.restoreTitle;			
		hs.graphicsDir = 'public/gfx/highslide/';
		hs.align = 'center';
		hs.transitions = ['expand', 'crossfade'];
		hs.outlineType = 'rounded-white';
		hs.fadeInOut = true;
		hs.dimmingOpacity = 0.50;
		hs.showCredits = false;
	
		hs.addSlideshow({
			//slideshowGroup: 'group1',
			interval: 5000,
			repeat: false,
			useControls: true,
			fixedControls: 'fit',
			overlayOptions: {
				opacity: .75,
				position: 'bottom center',
				hideOnMouseOut: true
			}
		});
				
	}, // initialize

	domReady: function() {

		$$('ul#menu > li > h2 > a').each(function(a){ a.addClass('cufon').addClass('cufonNormal'); });
		
		Cufon.replace('.cufonNormal', { hover: true, fontFamily: 'MyriadPro' });
		Cufon.replace('.cufonBox', { hover: true, fontFamily: 'MyriadPro', textShadow: '1px 1px #BF722C' });
		Cufon.now();
		
		if($('other-industries')) {
			var height = (Math.max($('other-industries').getFirst().getFirst().getHeight().toInt(),$('other-industries').getFirst().getFirst().getNext().getHeight().toInt()));
			$('other-industries').getFirst().setStyle('height', height);
		}
		
		this.activateCustomers();
		this.pngFix('div#msdynamics');

		if($('gotop')) {
			$('gotop').addEvent('click', function() {
				var scrollFx = new Fx.Scroll(window, {
					transition: Fx.Transitions.Quad.easeInOut
				});
				scrollFx.toTop();
			});
		}
		
		$$('ul#menu li').each(function(li){
			if (Browser.Engine.trident4) {
					li.addEvent('mouseenter', function(){ this.addClass(this.getFirst('ul')?'submenu_hover':'hover');});
					li.addEvent('mouseleave', function(){ this.removeClass(this.getFirst('ul')?'submenu_hover':'hover');});
					
			}	
		});		
		
		if($('gmap')) this.loadMap();
		if($('hidden-filename')) window.location.href = $('hidden-filename').innerHTML;
		if($('YTbanner')) {
			new Swiff('http://www.youtube.com/v/'+$('YTbanner').innerHTML+'&hl='+lang.lang+'&fs=1', {
				id: 'yt',
				container: $('YTbanner'),
				width: '100%',
				height: '100%',
				params: {
					wmode: 'tranaparent',
					allowFullScreen: 'true',
					allowscriptaccess: 'always'
				}
			});
		}
		if($('header-flash')) {
			new Swiff('/public/flash/xplus.swf', {
				id: 'panorama',
				container: $('header-flash'),
				width: '100%',
				height: '100%',
				params: {
					wmode: 'transparent',
					allowFullScreen: 'true',
					allowscriptaccess: 'always'
				},
				vars: {
					xmlURL: '/public/flash/xplus-'+lang.lang+'.xml'
				}
			});
		}
	}, // domReady

	fadeDuration: 1000,
	delayDuration: 8000,

	activateCustomers: function() {

		if($('customers')) {
			$$('ul#customers li').each(function(li, i) { li.setStyle('opacity', 0); if(i == 0) li.addClass('active'); });
			new Fx.Tween($('customers').getFirst(), {duration: Site.fadeDuration}).start('opacity', 0, 1);
			
			if($$('ul#customers li').length > 1) {
				var nextQuote = function() {
					var lis = $$('ul#customers li.active');
					new Fx.Tween(lis[0], {
						duration: Site.fadeDuration, 
						onComplete: function(li){
							li.removeClass('active');
							var next = (li.getNext()) ? li.getNext() : li.getParent().getFirst();
							next.addClass('active');
							new Fx.Tween(next, {
								duration: Site.fadeDuration
							}).start('opacity', 0, 1);
						}
					}).start('opacity', 1, 0);
				}
				var periodical = nextQuote.periodical(2 * Site.fadeDuration + Site.delayDuration);
			}
		}

	}, //activateCustomers

	map: null,
	loadMap: function() {
		
		var myLatlng = new google.maps.LatLng(52.15008070192658, 21.028218269348145);
		var myOptions = {
		zoom: 15,
		center: myLatlng,
		navigationControlOptions: {
			style: google.maps.NavigationControlStyle.ZOOM_PAN
		},
		mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		
		this.map = new google.maps.Map($('gmap'), myOptions);
		
		var marker = new google.maps.Marker({
			position: myLatlng, 
			map: this.map
		});
		
	}, // loadMap
	
	pngFix: function(pattern) {
		if(Browser.Engine.trident4) {
			$$(pattern).each(function(el){
				var background = el.getStyle('background-image');
				if(background != 'none') {
					var regex = /\/public(.+)\.png/;
					var result = regex.exec(background);
					if(result[0]) {
						el.setStyle('background', 'none');
						el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + result[0] + '\', sizingMethod=\'scale\')';
					}
				}
			});
		}

	}, //pngFix

	showMail: function(user, domain, contry, attr) {
		var start = "<a href=\"mailto:" + user + "@" + domain + "." + contry + "\"" + attr + ">";
		var end = "</a>";
		document.write(start + user + "@" + domain + "." + contry + end);
		return false;
	} // showMail
	
});

var Site = new SiteClass();
window.addEvent('domready', function(){ Site.domReady(); });
