


var oWindowSizes = window.getCoordinates();

if(oWindowSizes['width'] <= '1024') {
	var sSize = 'm';
} else {
	if(oWindowSizes['width'] <= '1280') {
		var sSize = 'l';
	} else {
		var sSize = 'xl';
	}
}


var iCurrentItem = 1;
var periodical;
var iChange;

var change = function() {
	if(iCurrentItem > iTotalItems) {
		iChange = 1;
	} else {
		iChange = iCurrentItem++;
	}
	$('intro_item_'+ iChange).fireEvent('mouseenter');
	//console.log(iCurrentItem);
	
};




window.addEvent('domready', function(){
	
	$('introContainer').setStyle('display', 'none');
	
	if($('splashContainer')) {
		
		$('splashContainer').setStyle('display', 'block');
		
		setTimeout(function(){
			
			
			var myTween = new Fx.Morph($('svo'), {duration: 1000, transition: Fx.Transitions.Sine.easeOut});
			myTween.start({
				'opacity': 0,
				'filter': 'alpha(opacity=0)'
			});
			
			
			
			setTimeout(function(){
				
				var myTween = new Fx.Morph($('ktd'), {duration: 500, transition: Fx.Transitions.Sine.easeOut});
				myTween.start({
					'margin': '52px 0 0 -140px'
				});
				
				
				setTimeout(function(){
					
					$('splashLogo').setStyle('display', 'none');
					$('ktd').setStyle('display', 'none');
					$('splashLogo2').setStyle('display', 'block');
					
					//$('introContainer').setStyle('display', 'block');
					
					oCoos = $('splashLogo2').getCoordinates();
					iLeft = oCoos['left'] + 86;
					iTop = oCoos['top'] + 62;
				
					var myTween = new Fx.Morph($('splashLogo2'), {duration: 500, transition: Fx.Transitions.Sine.easeOut});
					myTween.start({
					    'left': [iLeft, 130],
					    'top': [iTop, 19],
					    'margin': 0,
					    'width': 323,
					    'height': 124
					});
					
					setTimeout(function(){
						
						$('introContainer').setStyle('display', 'block');
						$('splashContainer').destroy();
						
						setThumbs();
						makeAccordion();
						initItems();
						
						change();
						periodical = change.periodical(4000);
					

					}, 1000);
					
					
					
				}, 2000);
				
				
				
			}, 750);

			
		}, 2000);
		
	
	} else {
		
		$('introContainer').setStyle('display', 'block');
		
		setThumbs();
		makeAccordion();
		initItems();
		
		change();
		periodical = change.periodical(4000);
		
	}
	
	

	
});


function initItems(){
	
	$('introItems').addEvents({
		'mouseenter': function(){
			
			$clear(periodical);
			
		},
		'mouseleave': function(){
			
			change();
			periodical = change.periodical(4000);
			
		}
	});
	
	$('introThumbs').addEvents({
		'mouseenter': function(){
			
			$clear(periodical);
			
		},
		'mouseleave': function(){
			
			change();
			periodical = change.periodical(4000);
			
		}
	});
	
}

function makeAccordion() {
	
	//create our Accordion instance
	var myAccordion = new Accordion($('introItems'), 'div.introItem', 'p', {
		
		opacity: false,
		
		// this is hardcoded set in this version of mootools
		trigger: 'mouseenter',
		
		onActive: function(toggler, element){
			toggler.addClass('active');
			sItem = toggler.getElement('h3').className;
			
			iCurrentItem = sItem.replace('item_', '');
			
			sHref = toggler.getElement('a').href;
			sBg = oItems[sItem]['bg'];
			sIcon = oItems[sItem]['icon'];
			$('introBg').src = 'introimages/'+ sBg;
			
			$('intro_icon_'+ sItem +'_'+ sSize).setStyle('visibility', 'visible');

			/*
			el = $('thumb_'+ sItem);
			el.setStyles({
				opacity: 0.6,
				filter: 'alpha(opacity=60)'
			});
			*/
			
			toggler.addEvent('click', function(){
				window.location.href = sHref;
			});
			
		},
		
		onBackground: function(toggler, element){
			toggler.removeClass('active');
			sItem = toggler.getElement('h3').className;
			
			/*
			el = $('thumb_'+ sItem);
			el.setStyles({
				opacity: 1,
				filter: 'alpha(opacity=100)'
			});
			*/
			
			$$('.intro_icon_'+ sItem).setStyle('visibility', 'hidden');
			
		}
		
	});
	
	/*
	$$('div.introItem').addEvent('mouseenter', function() { 
		this.fireEvent('click');
	});
	*/

}

/*
// Gemeentelinks
window.addEvent('domready', function(){
	$('gemeenteNav').addEvents({
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.set('tween', {
				duration: 200
			}).tween('height', '280px');
		},
		'mouseleave': function(){
			// Resets the tween and changes the element back to its original size
			this.set('tween', {}).tween('height', '99px');
		}
	});
});
*/


// Thumbs
function setThumbs(){
	
	var oItems = $$('img.introThumbItem');

	for (i = 0; i<oItems.length; i++) {
		
		oItems[i].addEvents({
			
			'mouseenter': function() { 
				
				sItem = this.id.replace('thumb_', '');
				$('intro_'+ sItem).fireEvent('mouseenter');
				this.style.visibility = 'visible';
				this.style.cursor = 'pointer';
				
			},
			
			'click': function() {
				
				sItem = this.id.replace('thumb_', '');
				sHref = $('intro_'+ sItem).getElement('a').href;
				window.location.href = sHref;
				
			}
		});
		
	}
	
}



