// JavaScript Document
window.addEvent('load', function() {
	FLIR.init();
	FLIR.replace(['h1'], new FLIRStyle({ mode:'wrap', realFontHeight:true }));
	FLIR.replace(['#initiatiefnemers_button']);
	FLIR.replace(['p.subtitle'], new FLIRStyle({ mode:'wrap', realFontHeight:true }));
	FLIR.replace(['span.text']);
	FLIR.replace(['p.kijkvoormeer']);
	

	//if (!checkIE6()) loadSifr();
	initLeesMeer();
	//initShadowBoxInfo();
	initPopups();
});

function initLeesMeer() {
	if (document.getElementById('leesmeer')) {
		$('leesmeer').addEvent('click', function(e) {
			if (e) e.stop();
			var pElement = $(this).getPrevious('p');
			if (this.hasClass('opened')) {
				pElement.tween('height', 50);
				this.removeClass('opened');
				this.set('html', 'Lees meer over grenzeloos kiezen...');
			}
			else {
				if (checkIE6()) {
					var newHeight = 340;	
				}
				else {
					var newHeight = 315;	
				}
				pElement.tween('height', newHeight);
				this.addClass('opened');
				this.set('html', 'Sluiten');
			}
			return false;
		});
	}
}

/*
function initShadowBoxInfo() {
	$$('#stellingen tbody tr').each(function(value,key) {
		$(value.getProperty('class')).getElement('h1').setProperty('html', value.getElement('td.stelling').getProperty('html'));											
	});
}
*/

function initPopups() {
	$$('#stellingen tbody a').each(function(value,key) {
		/*
		var sMening = value.getProperty('class');
		var sPartij = value.getParent('td').getProperty('class');
		
		var azbuka = {
			src: '/swf/azbukapro.swf'
		};
	*/
		var spanEl = value.getElement('span');
		
		/*
		new Element('em', {
			'html': value.getParent('tr').getElement('td.stelling').getProperty('html')
		}).inject(spanEl,'top');
		*/
		
		var sStelling = value.getParent('tr').getProperty('class');
		
		/*
		new Element('strong', {
			'html': 'Lees meer',
			'events': {
				'click': function(e) {
					if (e) e.stop();
					var sStelling = $(this).getParent('tr').getProperty('class');
					var newContent = $(this).getParent('a').getElement('span').getProperty('text').replace("Lees meer","");
					$(sStelling).getElement('p.subtitle').setProperty('html', newContent);
					SqueezeBox.open($(sStelling), {handler: 'clone'});
					return false;
				}
			}
			
		}).inject(spanEl,'bottom');
		*/
		
		spanEl.setStyle('opacity', '0');
		value.addEvent('click', function(e) {
			if (e) e.stop();
			$$('#stellingen tbody a span').each(function(value,key) {
				if (value!=$(this)) value.fade('out');						
			});
			$(this).getElement('span').fade('toggle');					 
		});

	});
	
	$$('td.stelling').addEvent('click', function(e) {
		if (e) e.stop();
		var sStelling = $(this).getParent('tr').getProperty('class');
		if ($(sStelling)) {
			SqueezeBox.open($(sStelling), {handler: 'clone'});
		}
		else {
			this.setStyle('cursor', 'default');	
		}
		return false;
	});
	
	if ($('initiatiefnemers_button')) {
		$('initiatiefnemers_button').addEvent('click', function(e) {
			if (e) e.stop();
			SqueezeBox.open($('initiatiefnemers'), {handler: 'clone',  size: {x: 380, y: 260}});
			return false;
		});
	}
}

function loadSifr() {
	var azbuka = {
		src: '/swf/azbukapro.swf'
	};

	sIFR.replace(azbuka, {
		selector: '#content p.subtitle',
		wmode: 'transparent',
		css: [
			'.sIFR-root { text-transform:none; leading:-8 }'
		]
	});
	
	sIFR.replace(azbuka, {
		selector: '#content span.text',
		wmode: 'transparent',
		css: [
			'.sIFR-root { text-transform:uppercase; font-size:21px; }'
		]
	});

	sIFR.replace(azbuka, {
		selector: '#content p.kijkvoormeer',
		wmode: 'transparent',
		css: [
			'.sIFR-root { text-transform:uppercase; font-size:18px; text-decoration: none}',
			'a { color: #e10073; text-decoration: none}',
			'a:hover { color: #000000 }'
		]
	});
	
	sIFR.activate(azbuka);
	
}

function checkIE6() {
	return (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);  	
}

function checkIE() {
	return (navigator.userAgent.toLowerCase().indexOf('msie') != -1);  	
}
