// bij page load
window.addEvent('domready', function() {
	ReplaceHeadsWithFlashFont();
	if ($('carousselcontainer')) init_caroussel();
	if ($('navigatie')) init_navigatie();
	if($('vraagstellen')) {
		var vraag_gewijzigd = false;
		$E('input.text', 'vraagstellen').addEvent('click', function() {
			if(vraag_gewijzigd == false) { $E('input.text', 'vraagstellen').setProperty('value', ''); vraag_gewijzigd = true; }
		});
	}
	if ($('vraagstellen_content')) {
	    var vraag_gewijzigd_content = false;
	    $E('input.text', 'vraagstellen_content').addEvent('click', function() {
	        if (vraag_gewijzigd_content == false) { $E('input.text', 'vraagstellen_content').setProperty('value', ''); vraag_gewijzigd_content = true; }
	    });
	}
});

// wanneer de volledige pagina geladen is
window.addEvent('load', function() {
    initQgo();
    //initQgo_content();
});


/* 	Replaces specific HTML fonts with sIFR Flash variants. */
function ReplaceHeadsWithFlashFont()
{
	if (typeof sIFR == "function") {
		// leave the order of the following lines intact
		sIFR.replaceElement("#contentpane h2", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#003081", sWmode: "transparent", sFlashVars:"fontsize=22"}));
		sIFR.replaceElement("h3.sifr", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#003081", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement("legend.sifr", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#003081", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement("h2.sifr_wit", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=30"}));
		sIFR.replaceElement("#footer h3", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#7e7e7e", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement(".alsosee_home_blue h3", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=18"}));
		sIFR.replaceElement(".alsosee_home h3", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#003081", sWmode: "transparent", sFlashVars:"fontsize=18"}));
		sIFR.replaceElement(".bottomoptions h3", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#003081", sWmode: "transparent", sFlashVars:"fontsize=18"}));
		sIFR.replaceElement("h3.sifr_wit", named({sFlashSrc: "/html/swf/sifr.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement("h1.paginatitel", named({sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=18"}));
		sIFR.replaceElement("h2.hoofdmenu", named({sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=18"}));	
		sIFR.replaceElement("ul.buttons li h4", named({sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=18"}));		
		sIFR.replaceElement("ul.buttons li h5", named({sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars:"fontsize=14"}));
		sIFR.replaceElement("div.button_rechts h4", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#003081", sWmode: "transparent", sFlashVars: "fontsize=20" }));
		sIFR.replaceElement("div.button_rechts h5", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#003081", sWmode: "transparent", sFlashVars: "fontsize=14" }));		
		sIFR.replaceElement("h2.matrix_zwart", named({sFlashSrc: "/html/swf/matrix.swf", sColor: "#000000", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement("p.matrix_groen", named({sFlashSrc: "/html/swf/matrix.swf", sColor: "#009534", sWmode: "transparent", sFlashVars:"fontsize=16"}));
		sIFR.replaceElement("h2.matrix_item", named({sFlashSrc: "/html/swf/matrix.swf", sColor: "#009534", sWmode: "transparent", sFlashVars:"fontsize=14"}));
		sIFR.replaceElement("h2.matrix_titel", named({ sFlashSrc: "/html/swf/matrix.swf", sColor: "#009534", sWmode: "transparent", sFlashVars: "fontsize=11" }));


		sIFR.replaceElement("div.color1 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#e2007a", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color2 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#fcc000", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color3 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#f49a00", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color4 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#c90039", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color5 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#462682", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color6 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#007bbe", sWmode: "transparent", sFlashVars: "fontsize=28" }));
		sIFR.replaceElement("div.color7 div.bottomoptions div.column_wide h2.landing", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ddd100", sWmode: "transparent", sFlashVars: "fontsize=28" }));

		sIFR.replaceElement("div.color1 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#e2007a", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color2 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#fcc000", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color3 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#f49a00", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color4 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#c90039", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color5 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#462682", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color6 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#007bbe", sWmode: "transparent", sFlashVars: "fontsize=18" }));
		sIFR.replaceElement("div.color7 div.bottomoptions div.column_voordelen h2.voordelen", named({ sFlashSrc: "/html/swf/franklindemi.swf", sColor: "#ddd100", sWmode: "transparent", sFlashVars: "fontsize=18" }));

	}
}


// Caroussel met situaties op de homepage
function init_caroussel() {
	var caroussels = $$('#carousselcontainer .caroussel');
	var icons = $$('#carousselcontainer li');
	var buttons = $$('#situaties h4');
	
	caroussels.each(function(item) {
		item.setStyle('display', 'none');
	});
	caroussels[0].setStyle('display', 'block');
	buttons[0].className = 'active';
	
	buttons.each(function(item, index){
		item.addEvent('click', function() {
			caroussels.each(function(item2) {
				item2.setStyle('display', 'none');
			});
			buttons.each(function(item2) {
				item2.className = '';
			});
			caroussels[index].setStyle('display', 'block');
			buttons[index].className = 'active';
		});
	});
	
	icons.each(function(item, index) {
		item.setStyle('opacity', '0.4');
		item.addEvents({
			'mouseover': function() {
				item.setStyle('opacity', '1');
				$E('span', item).setStyle('display', 'block');
			},
			'mouseleave': function() {
				item.setStyle('opacity', '0.4');
				$E('span', item).setStyle('display', 'none');
			}
		});
	});
}


// mouseover gedrag bij hoofdnavigatie
function init_navigatie() {
	$$('#navigatie li').each(function(item) {
		item.addEvents({
			'mouseenter': function() {
				item.addClass('hover');
			},
			'mouseleave': function() {
				item.removeClass('hover');
			}
		});
	});
}


// initialize q-go lightbox
function initQgo() {
	if(!$('question') || !$('zoekbutton')) return false;
	
	var sbContent = $('qgo_container').clone(false);
	sbContent.adopt($('qgo_container').getChildren());
	$('qgo_container').remove();
	
	var qgoFrame = new Element('iframe', {
		'frameborder':	0,
		'height':		366,
		'width':		866,
		'scrolling':	'no'
	});
	
	var orgHref = new Array;
	
	sbContent.getElements('ul.qgo_nav a').each(function(item, index) {
		orgHref[index] = item.getProperty('href');
		item.href = 'javascript:void(0)';
	});
	
	Shadowbox.init({
		overlayColor:	'#fff',
		overlayOpacity:	0.85,
		enableKeys:		false,
		animSequence:	'sync',
		loadingImage:	'/HTML/images/quickwins/loading.gif'
	});
	
	var switchTab = function(tab) {
		$('shadowbox').getElements('ul.qgo_nav li').removeClass('active');
		$('shadowbox').getElements('ul.qgo_nav li')[tab].addClass('active');
		
		var url = orgHref[tab];
		if(tab == 0) url += '&q=' + $('question').value
		qgoFrame.setProperty('src', url);
	};
	
	var openLightbox = function(tab) {
	
		Shadowbox.open(
			{
				type:		'html',
				content:	sbContent.innerHTML,
				height:		429,
				width:		914
			},
			{
				onFinish:	function() {
					qgoFrame.injectInside($('shadowbox_content'));
					
					$('shadowbox').getElements('ul.qgo_nav li').each(function(item, index) {
						item.addEvent('click', function(ev) {
							var ev = new Event(ev);
							ev.stop();
							switchTab(index);
						});
					});
					
					switchTab(tab);
				}
			}
		);
};

	$('question').addEvent('keydown', function(event) {
		event = new Event(event);
		if (event.key == 'enter') {
			openLightbox(0);
			$('question').blur();
		}
	});
	
	$('zoekbutton').addEvents({
		'keydown': function(event) {
			event = new Event(event);
			if (event.key == 'enter') openLightbox(0)
		},
		'click': function(event) { openLightbox(0) }
	});
	
	
	if($('allevragen_link')) {
		$('allevragen_link').setProperty('href', 'javascript:void(0)');
		$('allevragen_link').addEvents({
			'keydown': function(event) {
				event = new Event(event);
				if (event.key == 'enter') openLightbox(2)
			},
			'click': function(event) { openLightbox(2) }
		});
	}

	if (!$('question_content') || !$('zoekbutton_content')) return false;

	var switchTab_content = function(tab) {
	    $('shadowbox').getElements('ul.qgo_nav li').removeClass('active');
	    $('shadowbox').getElements('ul.qgo_nav li')[tab].addClass('active');

	    var url = orgHref[tab];
	    if (tab == 0) url += '&q=' + $('question_content').value
	    qgoFrame.setProperty('src', url);
	};

	var openLightbox_content = function(tab) {

	    Shadowbox.open(
			{
			    type: 'html',
			    content: sbContent.innerHTML,
			    height: 429,
			    width: 914
			},
			{
			    onFinish: function() {
			        qgoFrame.injectInside($('shadowbox_content'));

			        $('shadowbox').getElements('ul.qgo_nav li').each(function(item, index) {
			            item.addEvent('click', function(ev) {
			                var ev = new Event(ev);
			                ev.stop();
			                switchTab_content(index);
			            });
			        });

			        switchTab_content(tab);
			    }
			}
		);
};
	
	$('question_content').addEvent('keydown', function(event) {
	    event = new Event(event);
	    if (event.key == 'enter') {
	        openLightbox_content(0);
	        $('question_content').blur();
	    }
	});

	$('zoekbutton_content').addEvents({
	    'keydown': function(event) {
	        event = new Event(event);
	        if (event.key == 'enter') openLightbox_content(0)
	    },
	    'click': function(event) { openLightbox_content(0) }
	});

	if ($('allevragen_link_content')) {
	    $('allevragen_link_content').addEvents({
	        'keydown': function(event) {
	            event = new Event(event);
	            if (event.key == 'enter') openLightbox_content(2)
	        },
	        'click': function(event) { openLightbox_content(2) }
	    });
	}

}