
// ONLOAD/ONRESIZE: GET ACTUAL WINDOW HEIGHT FOR ADJUSTED POSITION OF CONTENT
// INITIALIZE N FOR ADJUSTMENTS
function getWindowHeight(){
	if(window.innerHeight != null) {
		return window.innerHeight;
	}
	if (document.body.offsetHeight != null) {
		return document.body.offsetHeight;
	}
	return (null);
}

function getWindowWidth(){
	if(window.innerWidth != null) {
		return window.innerWidth;
	}
	if (document.body.offsetWidth != null) {
		return document.body.offsetWidth;
	}
	return (null);
}

function adjustPos() {
	var topPos = getWindowHeight();
	var leftPos = getWindowWidth();
	
	//document.getElementById('maintable').style.height = (topPos-125) + 'px';
		
}

function mshow(element){
           element.addClass('hover');
           }
function mhide(element){
           element.removeClass('hover');
     }
//-->

// MOOTOOLS EFFECTS

window.addEvent('domready', function() {
	
	//var plusURL = 'http://www.trax.com.my';
	var plusURL = 'http://112.137.167.41';
									 
	var subnavID = $('subnavigation');
	var beforeID = $('beforeToTop');
	var tlclink = $('tollFareNavi');
	var totopID = $('toTop');
	var headerImage = $('main').getFirst();
	
	beforeID.setStyles({'opacity':0});
	//totopID.setStyles({'opacity':0});
	//tlclink.setStyles({'opacity':0});
	
	var listPosition = headerImage.getCoordinates();
	var navHeight = $('subnavigation').getHeight();
	$$('.mainSubMenu').setStyles({top: 126, width: listPosition.width-30, right: listPosition.right-15, left: listPosition.left+15 });
	$('contentspalte').setStyles({'min-height': navHeight });
	$$('.hideImage').setStyles({top: listPosition.top+20, width: listPosition.width-30, right: listPosition.right-15, left: listPosition.left+15 });
	
		
		navFade = new Fx.Tween(subnavID, {property:'opacity', duration:1500, link: 'cancel'});
		
		var dlg = new Dialog({});
		
		$('tollFareLaunch').addEvent('click',function(e){
				$$('.maske').destroy();
				$$('.poplayer').destroy();
				var e = new Event(e);
				e.stop();
				var myIFrame = new IFrame({
					src: plusURL + '/calculator/index.asp',
					scrolling: 'no',
					allowTransparency: 'true', 
					frameborder: '0',
					styles: {
						width: 282,
						height: 442,
						border: '0px none #fff'
					},
					events: {
						
						load: function(data){
							//alert('The iframe has finished loading.');
							el.set('html',this);
						}
					}
				});
				//var el = new Element('div',{'class':'calcLayer', 'html': '<img src="fileadmin/templates/img/calculator.png" onclick="calculatorFadeOut();" />', 'events': {'click': this.hide.bind(this)}, 'styles':{'padding-left':15,'background':'transparent','width':300}})
				navFade.start(0);
				dlg.show(myIFrame);
		});
		
		$$('.tfcLaunchLink').addEvent('click',function(e){
				$$('.maske').destroy();
				$$('.poplayer').destroy();
				var e = new Event(e);
				e.stop();
				var myIFrame = new IFrame({
					src: plusURL + '/calculator/index.asp',
					scrolling: 'no',
					frameborder: '0',
					allowTransparency: 'true', 
					styles: {
						width: 282,
						height: 442,
						border: '0px none #fff'
					},
					events: {
						
						load: function(data){
							alert('The iframe has finished loading.');
							el.set('html',this);
						}
					}
				});
				//var el = new Element('div',{'class':'calcLayer', 'html': '<img src="fileadmin/templates/img/calculator.png" onclick="calculatorFadeOut();" />', 'events': {'click': this.hide.bind(this)}, 'styles':{'padding-left':15,'background':'transparent','width':300}})
				navFade.start(0);
				dlg.show(myIFrame);
		});
		
		/* link management */
			//$('gototop').set('opacity','0').setStyle('display','block');
		
		
		
		naviMove = new Fx.Tween(subnavID, {property:'top', duration:500, link: 'cancel'});
		beforefade = new Fx.Tween($('beforeToTop'), {property:'opacity', duration:1500, link: 'cancel'});
		//totopfade = new Fx.Tween($('toTop'), {property:'opacity', duration:1500, link: 'cancel'});
		//tlclinkfade = new Fx.Tween($('toTop'), {property:'opacity', duration:1500, link: 'cancel'});
		var navPosi = subnavID.getCoordinates().top;
		//var pageHeight = $('subnavigation');
		
			/* scrollspy instance */
			var ss = new ScrollSpy({
				min: navPosi-20,
				onEnter: function(position,enters) {
					subnavID.getParent().setStyles({'width':272});
					subnavID.setStyles({'position':'absolute'});
					beforefade.start(1);
					//totopfade.start(1);
					//tlclinkfade.start(1);
					naviMove.start(window.getScrollTop()+40);					
				},
				onLeave: function(position,leaves) {
					beforefade.start(0);
					//totopfade.start(0);
					//tlclinkfade.start(0);
					//$('subnavigation').setStyles({'position':'relative'});
					naviMove.start(navPosi);
				},
				onTick: function(position,state,enters,leaves) {
					//$('toTop').getElements('a').set('text',window.getScrollTop());
					//$('toTop').getElements('a').set('text',$('subnavigation').getCoordinates().bottom);
					if ((subnavID.getCoordinates().bottom + 40) < ($('footer').getCoordinates().top)){
					naviMove.start(window.getScrollTop()+40);
					}
				},
				container: window
			});

			
});

function calculatorFadeOut() {	
			navFade.start(1);
			var calcfade = new Fx.Tween($('poplayer'), {
					property:'opacity', 
					duration:1500, 
					link: 'cancel',
					onComplete: function(){
						//and here we apply the highlight effect on complete
						$('maske').destroy();
						$('poplayer').destroy();
					}
					});
			calcfade.start(0);
};
		
window.addEvent('resize', function() {
									 
	var headerImage = $('main').getFirst();
	
	var listPosition = headerImage.getCoordinates();
	var navHeight = $('subnavigation').getHeight();
	//$$('.mainSubMenu').setStyles({top: listPosition.top-2, width: listPosition.width-30, right: listPosition.right-15, left: listPosition.left+15, 'min-height': listPosition.height-30 });
	$$('.mainSubMenu').setStyles({top: listPosition.top-2, width: listPosition.width-30, right: listPosition.right-15, left: listPosition.left+15 });
	//$$('.mainSubMenu').setStyles({top: listPosition.top-2, width: listPosition.width-95, right: listPosition.right-15, left: listPosition.left+80 });
	$('contentspalte').setStyles({'min-height': navHeight });
	$$('.hideImage').setStyles({top: listPosition.top+20, width: listPosition.width-30, right: listPosition.right-15, left: listPosition.left+15 });
	
	  	/*
		var thisSlider = new Fx.Slide( $( 'headerIMG' ), { duration: 1000, transition: Fx.Transitions.Sine.easeOut } );
	  	thisSlider.show();
	  	$$('.hideImage').addEvent( 'click', function(){ 
			thisSlider.hide();
			this.set('text', 'Show Image');
			this.removeClass('hideImage');
			this.addClass('showImage');
			$$('.toggleImage').addEvent( 'click', function(){ 
				thisSlider.show();
				this.set('text', 'Hide Image');
				this.removeClass('showImage');
				this.addClass('hideImage');
			});
		});
		*/
});

