Event.observe(window, 'load', function() 
{
//	if(typeof sIFR == "function")
//	{
////		sIFR.replaceElement("h1", named({sFlashSrc: "/libraries/sifr/netto_bold.swf", sSelector: ".nav", sColor: "#FFFFFF", sWmode: "transparent", sFlashVars: "offsetLeft=5"}));	    
//		sIFR.replaceElement("span", named({sFlashSrc: "/libraries/sifr/auto2smcp_bold.swf", sSelector: ".newstrailer_title", sColor: "#e3a615", sWmode: "transparent", sFlashVars: ""}));	    
//		sIFR.replaceElement("span", named({sFlashSrc: "/libraries/sifr/auto2smcp_bold.swf", sSelector: ".newstrailer_title_active", sColor: "#FFFFFF", sWmode: "transparent", sFlashVars: ""}));	    
//		sIFR.replaceElement("span", named({sFlashSrc: "/libraries/sifr/auto2smcp_bold.swf", sSelector: ".newstrailer_subtitle", sColor: "#e3a615", sWmode: "transparent", sFlashVars: ""}));	    
//		sIFR.replaceElement("h1", named({sFlashSrc: "/libraries/sifr/auto2smcp_bold.swf", sColor: "#FF0000", sWmode: "transparent", sFlashVars: ""}));	    
//	};

						
	if ($('stream'))
	{
		// global object
//		videoplayer		= new VideoPlayer();
////
//		//videoplayer.play('/video/kruiswijk.flv', 'stream', 400, 233, '/video/kruiswijk.jpg');
//		videoplayer.play('http://videostream.reformatorischeomroep.nl/JBGG', 'stream', 400, 233, '/video/kruiswijk.jpg');
	}
	
	if ($('mainmenu'))
	{
		if (($('mainmenu').hasClassName('homepage')))
		{
			newNavigator = new NavigatorCollection();
			newNavigator.getNavigator(
			{
				'id'				: "mainmenu",
				'submenu'			: "downblind"
			});
		}
		else
		{
			newNavigator = new NavigatorCollection();
			newNavigator.getNavigator(
			{
				'id'				: "mainmenu",
				//'activatesubmenu'	: "click",
				'submenu'			: "downblind"
			});
		}
	}
	
	if ($('flash'))
	{
		var so = new SWFObject("/flash/balk5.swf", "video", "906", "90", "8", "transparent");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("flash");
	}
	
	if($('newsbutton'))
	{
		Event.observe('newsbutton', 'click', function(event)
		{
			$('agendablock').hide();
			$('newsblock').show();
		});
	}
	
	if($('agendabutton'))
	{
		Event.observe('agendabutton', 'click', function(event)
		{
			$('agendablock').show();
			$('newsblock').hide();
		});
	}
	
	if($('uitgelicht_1'))
	{
		Event.observe('uitgelicht_1', 'mouseover', function(event)		{	$('moreinfo_1').style.background = "url('/images/orange/meer-informatie_a.jpg')";});
		Event.observe('uitgelicht_1', 'mouseout', function(event)		{	$('moreinfo_1').style.background = "url('/images/orange/meer-informatie.jpg')";	});
		Event.observe('uitgelicht_2', 'mouseover', function(event)		{	$('moreinfo_2').style.background = "url('/images/orange/meer-informatie_a.jpg')";});
		Event.observe('uitgelicht_2', 'mouseout', function(event)		{	$('moreinfo_2').style.background = "url('/images/orange/meer-informatie.jpg')";	});
		Event.observe('uitgelicht_3', 'mouseover', function(event)		{	$('moreinfo_3').style.background = "url('/images/orange/meer-informatie_a.jpg')";});
		Event.observe('uitgelicht_3', 'mouseout', function(event)		{	$('moreinfo_3').style.background = "url('/images/orange/meer-informatie.jpg')";	});
		Event.observe('uitgelicht_4', 'mouseover', function(event)		{	$('moreinfo_4').style.background = "url('/images/orange/meer-informatie_a.jpg')";});
		Event.observe('uitgelicht_4', 'mouseout', function(event)		{	$('moreinfo_4').style.background = "url('/images/orange/meer-informatie.jpg')";	});
	}
	
	if($$('.travelinfo').length){
		$$('.travelinfo').each(function(item){
			Event.observe(item, 'mouseover', function(event){
				el = Event.element(event);
				target = $(el.href.split('#')[1]);
				target.style.display = "block";
			})
			Event.observe(item, 'mouseout', function(event){
				el = Event.element(event);
				target = $(el.href.split('#')[1]);
				target.style.display = "none";
			})
		});
	}
	
	if($('danielmenu'))
	{
		Event.observe('daniel', 'mouseover', function(event)
		{
			$('danielmenu').show();
		});
		
		Event.observe('daniel', 'mouseout', function(event)
		{
			$('danielmenu').hide();
		});
		
		Event.observe('danielmenu', 'mouseout', function(event)
		{
			$('danielmenu').hide();
		});
	}
	
	
//	
//	if($('item_226'))
//	{
//		Event.observe('item_226', 'mouseover', function(event)
//		{
//			$('logo').style.zIndex = 1;
//		});
//		
//		Event.observe('item_226', 'mouseout', function(event)
//		{
//			$('logo').style.zIndex = 2;
//			
//		});
//		
//		Event.observe('list_226_mainmenu', 'mouseout', function(event)
//		{
//			$('logo').style.zIndex = 2;
//			
//		});
//	}
//	
//	if($('item_227'))
//	{
//		Event.observe('item_227', 'mouseover', function(event)
//		{
//			$('logo').style.zIndex = 1;
//		});
//		
//		Event.observe('item_227', 'mouseout', function(event)
//		{
//			$('logo').style.zIndex = 2;
//			
//		});
//		
//		Event.observe('list_227_mainmenu', 'mouseout', function(event)
//		{
//			$('logo').style.zIndex = 2;
//			
//		});
//	}
	
		if ($('submit_mailafriend'))
		{
			
			Event.observe($('submit_mailafriend'), 'click', function()
			{ 
				$('form_mailafriend').submit();
			}.bind(this));
		}

		if ($('stuur_door'))
		{
			Event.observe($('stuur_door'), 'click', function()
			{ 
				if (!$('mailafriend').visible())
				{
					$('mailafriend').show();
				}
				else
				{
					$('mailafriend').hide();
				}
				
			}.bind(this));
		}
		
		if($('map'))
		{
			var latlng = new google.maps.LatLng(52.08198, 4.88963); 
			    var myOptions = { 
			      zoom: 12, 
			      center: latlng, 
			      mapTypeId: google.maps.MapTypeId.ROADMAP 
			    }; 
			    var map = new google.maps.Map(document.getElementById("map"), 
			        myOptions); 
			        
			var marker = new google.maps.Marker({
		        position: latlng, 
		        map: map,
		        title:"Jeugdbond Gereformeerde Gemeente"
		    }); 
		}

		
		var newAnimation = new Animation();
			newAnimation.slideshow(1,3,3000,'trailer');
			
		if($('mijnjeugdbond'))
		{
			if ($('Gemeentenaam'))
			{
				Event.observe('Gemeentenaam', 'click', function(event)
				{
					if ($('Gemeentenaam').value == 'anders')
					{
						$('GemeentenaamAndersLabel').setStyle('display:block;');
						$('GemeentenaamAnders').setStyle('display:block;');
					}
					else
					{
						$('GemeentenaamAndersLabel').setStyle('display:none;');
						$('GemeentenaamAnders').setStyle('display:none;');
					}
				});
			}
			
			if($('Omschrijving'))
			{
				Event.observe('Omschrijving', 'click', function(event)
				{
					if ($('Omschrijving').value == 'anders')
					{
						$('anders_nl').setStyle('display:block;');
						$('anders_uitgave').setStyle('display:block;');
						$('anders_inkomst').setStyle('display:block;');
						$('aantal').setStyle('display:none;');
						$('radio_in').setStyle('display:none;');
						$('radio_uit').setStyle('display:none;');
					}
					else
					{
						$('anders_nl').setStyle('display:none;');
						$('anders_uitgave').setStyle('display:none;');
						$('anders_inkomst').setStyle('display:none;');
						$('aantal').setStyle('display:block;');
						$('radio_in').setStyle('display:block;');
						$('radio_uit').setStyle('display:block;');
					}
				});
			}
			
			if($('InkomstPrijs'))
			{
				Event.observe('InkomstPrijs', 'blur', function(event)
				{
					correctInput('InkomstPrijs');
				});
				
				Event.observe('InkomstPrijs', 'keyup', function(event)
				{
					if (event.keyCode == Event.KEY_RETURN)
			    	{
						correctInput('InkomstPrijs');
			    	}
				});
			}
			
			if($('UitgavePrijs'))
			{
				Event.observe('UitgavePrijs', 'blur', function(event)
				{
					correctInput('UitgavePrijs');
				});
				
				Event.observe('UitgavePrijs', 'keyup', function(event)
				{
					if (event.keyCode == Event.KEY_RETURN)
			    	{
						correctInput('UitgavePrijs');
			    	}
				});
			}
			
			if($('mjbestellen'))
			{
				$$('.ap_aantal_input').each(function(item) 
				{ 
					Event.observe(item.id, 'keyup', function()
							{
								splitid 									= item.id.split("_");
								elementid 									= splitid[1];
								itemprice 									= $('apprijs_'+elementid).value;
								itemtotalprice 								= item.value * itemprice;
								$('ap_totaalbedrag_'+elementid).innerHTML 	= (isValidBedrag(itemtotalprice)) ? "&euro; " + importBedrag(itemtotalprice) : "&euro; " + importBedrag(0);
								correctTotaalMJBestellen();
								
							}); 
					
				});
				
//				Inputs.each(function(s) {
//					  alert(s.id);
//				});

			}
		}
		
		
		if ($('field-gateway'))
	    {
	    	Event.observe('field-gateway', 'change', function(event)
			{
				if($('field-gateway').value == 'invoice')
				{
					$('checkout2').show();
					$('idealsubmit').hide();
	
				}
				else
				{
					$('checkout2').hide();
					$('idealsubmit').show();
				}
			});
			
	    }
		
		
});

function correctTotaalMJBestellen()
{
	totaalbedrag = 0;
	
	$$('.ap_aantal_input').each(function(item) 
	{
		splitid 		= item.id.split("_");
		elementid 		= splitid[1];
		itemprice 		= $('apprijs_'+elementid).value;
		itemtotalprice 	= item.value * itemprice;
		if (isValidBedrag(itemtotalprice))
		{
			totaalbedrag 	= totaalbedrag + itemtotalprice;
		}
	});
	
	$('mj_bestel_totaalbedrag').innerHTML =  "&euro; " + importBedrag(totaalbedrag);
}

function correctInput(id)
{
	if (isValidBedrag($(id).value, true)) 
	{
		value = $(id).value;
	}
	else
	{
		value = 0;
	}
	$(id).value = importBedrag(exportBedrag(value));
}


function isValidBedrag(cBedrag, onlyPositive) 
{
	// Wanneer 'onlyPositive' niet is meegegeven, dan worden zowel
	// positieve als negatieve waarden toegestaan.
	if (typeof(onlyPositive) == 'undefined')
		onlyPositive = false;

	cBedrag = trim(cBedrag);

	cBedrag = replace(cBedrag, ',', '');
	cBedrag = replace(cBedrag, '.', '');

	var validChars = '';

	if (onlyPositive)
		validChars = '0123456789+';
	else
		validChars = '0123456789-+';

	return(containsOnlyValidChars(cBedrag, validChars));
}

function importBedrag(cBedrag)
{
	var isNegative = false;

	cBedrag = trim(cBedrag);

	if (cBedrag == '')
		cBedrag = '0';

	if (cBedrag.charAt(0) == '-') {
		isNegative = true;

		cBedrag = cBedrag.substring(1, cBedrag.length);
	}

	// Splits het bedrag op in euro's en centen...
	var cCenten = (cBedrag.length < 2) ? ("0" + cBedrag) : cBedrag.substring(cBedrag.length - 2, cBedrag.length);
	var cEuros = (cBedrag.length < 3) ? "0" : cBedrag.substring(0, cBedrag.length - 2);

	// Plaats punten op de duizend tallen
	var len = cEuros.length;
	var pos = cEuros.length - 3;

	while (pos > 0) {
		cEuros = cEuros.substring(0, pos) + '.' + cEuros.substring(pos);

		pos = pos - 3;
	}

	if (isNegative)
		cEuros = '-' + cEuros;

	return(cEuros + "," + cCenten);
}

function exportBedrag(cBedrag) {
	// Verwijder alle whitespaces voor en na het bedrag
	var tmpBedrag = trim(cBedrag);

	// Verwijder alle '+' en spaties
	tmpBedrag = replace(tmpBedrag, '+', '');
	tmpBedrag = replace(tmpBedrag, ' ', '');


	var nComma = tmpBedrag.lastIndexOf(',');
	var nDot = tmpBedrag.lastIndexOf('.');

	var nPos = Math.max(nComma, nDot);

	var cEuro = '';
	var cCent = '';

	if (nPos < 0) {
		cEuro = tmpBedrag;
		cCent = "00";
	} else {
		cEuro = tmpBedrag.substring(0, nPos);
		cCent = tmpBedrag.substring(nPos + 1, nPos + 3);

		while (cCent.length < 2)
			cCent += "0";

		cEuro = replace(cEuro, ',', '');
		cEuro = replace(cEuro, '.', '');
	}

	tmpBedrag = removeLeadingZeros(cEuro + cCent);

	if (tmpBedrag == '' && cBedrag != '')
		tmpBedrag = "0";

	return(tmpBedrag);
}


function SwapImage(element)
{
	this.active = element;
}

	SwapImage.prototype.swap = function(element, id, src)
	{
		if (this.active.id != element.id)
		{
			element.className = 'active';
			
			document.getElementById(id).src = src;
			
			this.active.className = '';
			this.active = element;
		}
	}
	
function showHideElement(source, target)
{	
	if(document.getElementById(source).checked == 1)
	{
		document.getElementById(target).style.display = 'block';
	}
	else
	{
		document.getElementById(target).style.display = 'none';
	}
}

function changeQuantity(objectinstanceid, count, udcsizeitemid, udccoloritemid)
{
	new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/'+ udcsizeitemid +'/'+ udccoloritemid +'', {
			onSuccess: function(transport) 
			{
				document.location.href='/_ctrl/shop/cart/list';
			}
		});
}



function updateCart(cartcollection)
{
	 var totalamount = cartcollection.jsonobj.totalcleanprice;

//   	 if (cartcollection.jsonobj.shippingcosts == 0)
//   	 {
//     	document.getElementById('tr_1a').style.display = 'none';
//   	 }
//   	 else
//   	 {
//   	 	
//   	 	if (isie)
//   	 	{
//   	 		document.getElementById('tr_1a').style.display = 'block';
//   	 	}
//   	 	else
//   	 	{
//   	 		document.getElementById('tr_1a').style.display = 'table-row';
//   	 	}
//   	 	
//   	 }
   	 //document.getElementById("quantity").innerHTML = cartcollection.jsonobj.totalquantity;
   	 document.getElementById("totalprice_1").innerHTML = '&euro; ' + cartcollection.jsonobj.totalprice;
}



function addCard(nr, totalcard)
{
	
	nr = Number(cardcount);
	
	var html = 
		Builder.node
			('tr', {},
					[
					 
					 Builder.node ('td', {style:'width:140px'}, 
							 [
							  	
							  ]
					 ),
					 Builder.node ('td', {style:'width:115px'}, 
							 [
							  	Builder.node('input', { id: 'artcode_'+nr, className:'artcode', type: 'text', name: 'artcode[]'})
							  ]
					 ),
					 Builder.node ('td', {style:'width:45px'}, 
							 [
							  	Builder.node('input', {id: 'cardcount_'+nr ,className:'aantal', type: 'text', name: 'cardcount[]'})
							  ]
					 ),
					 Builder.node ('td', {}, 
							 [
							  
							  ]
					 ),
					 
					 ]
			);
	
	var desc = $('cardcol').descendants();
	
	desc[0].appendChild(html);
	
	$('artcode_'+nr).className = 'artcode';
	$('cardcount_'+nr).className = 'aantal';
	
	cardcount++;
}

var Animation = Class.create(
{
	initialize: function() 
	{
		this.go_to 		= null;
		this.freeze		= false;
		
		this.last		= null
		this.interval	= null;
		this.target		= null;
	},
	slideshow: function(start,last,interval,target)
	{
		this.last		= 0;
		
		$$('.li_trailer').each(function(item, index)
		{
			this.last 	= this.last + 1;
		}.bind(this));
		
		last		= this.last;
		
		this.interval	= interval;
		this.target		= target;
		
		var frame 		= start;   
		var nextframe 	= start+1;   
		var that		= this;

		this.attachEvents(target);
		
		if ($(target+frame))
		{
			Effect.Appear(target+frame,{duration:.5,from:0.0,to:1.0});   
			
			setInterval(function()
			{
				// when freezed, nothing will happen
				if (!that.freeze || that.go_to != null)
				{
					// an other next frame will be set
					if (that.go_to != null)
					{
						nextframe 	= that.go_to;
						that.go_to	= null;
					}
					
					Effect.Fade(target+frame,
					{
						duration:.5,
						from:1.0,
						to:0.0,
						afterFinish:function()
						{
							$(target+frame).hide();
							
						    frame = nextframe;
						    nextframe = (frame == last) ? start : nextframe+1;
						},
						beforeStart:function()
						{
						    Effect.Appear(target + nextframe,{duration:.5,from:0.0,to:1.0});
						    
						    $(target + '_li_' + frame).removeClassName('active');
						    $(target + '_li_' + nextframe).addClassName('active');
						    
//						    $('newstrailer_title_' + frame).removeClassName('newstrailer_title_active');
//						    $('newstrailer_title_' + frame).addClassName('newstrailer_title');
//						    
//						    $('newstrailer_title_' + nextframe).removeClassName('newstrailer_title');
//						    $('newstrailer_title_' + nextframe).addClassName('newstrailer_title_active');
							//sIFR.redraw();

						}
					});
				}
			}, interval);
		}
		return; 
	},
	attachEvents: function()
	{
		$$('.li_trailer').each(function(item, index)
		{
			Event.observe(item.id, 'mouseover', this.goToFrame.bindAsEventListener(this, item));
			Event.observe(item.id, 'mouseover', this.freezeFrame.bindAsEventListener(this, item));
			Event.observe(item.id, 'mouseout', this.freezeFrame.bindAsEventListener(this, item));
		}.bind(this));
	},
	goToFrame: function(event, elm)
	{
		var exploded 	= elm.id.split('_');
		this.go_to 		= parseInt(exploded[2]);
	},
	freezeFrame: function(event, elm)
	{
		if (event.type == 'mouseover')
		{
			this.freeze = true;
		}
		if (event.type == 'mouseout')
		{
			this.freeze = false;
		}
	}
});

function showFaq(id)
{
	if (!$('faq_text_' + id).visible())
	{
		$('faq_text_' + id).show();
		$('faq_h1_' + id).src = '/images/min.gif';
//		$('text').style.offsetHeight = ($('text').style.offsetHeight  + $('faq').style.offsetHeight ) +"px";
	}
	else
	{
		$('faq_text_' + id).hide();
		$('faq_h1_' + id).src = '/images/plus.gif';
//		$('text').style.offsetHeight  = ($('text').style.offsetHeight  + $('faq').style.offsetHeight ) +"px";
	}
	
}



var VideoPlayer = Class.create(
{
	initialize: function()
	{
		
	},
	play: function(source, target, width, height, prerollimage)
	{
		
		var flashvars = {
			flvpFolderLocation: "/flvplayer/",
			flvpAutoStartMovie: false,
			flvpPreRollImage: prerollimage,
			flvpVideoSource: source,
			flvpWidth: width,
			flvpHeight: height,
			flvpTurnOnCorners: false,
			flvpShowbInfo: false,
			flvpShowbCc: false,
			flvpShowbMenu: false,
			flvpInterfaceDisplay : "autohide",
			flvpBackButtonRollOverColor: "0x546472",
			flvpPlayButtonRollOverColor: "0x546472",
			flvpPauseButtonRollOverColor: "0x546472",
			flvpStopButtonRollOverColor: "0x546472",
			flvpForwardButtonRollOverColor: "0x546472",
			flvpInfoButtonRollOverColor: "0x546472",
			flvpCCButtonRollOverColor: "0x546472",
			flvpFullscreenButtonRollOverColor: "0x546472",
			flvpMenuButtonRollOverColor: "0x546472",
			flvpCloseMenuButtonRollOverColor: "0x546472",
			flvpScrubBarDragRollOverColor: "0x546472",
			flvpVolumeButtonOnRollOverColor: "0x546472",
			flvpVolumeButtonOffRollOverColor: "0x546472",
			flvpVolumeDragRollOverColor: "0x546472",
			flvpScrubBarFrontColor : "0x546472",
			flvpVolumeFrontColor : "0x546472"
		};
		
		var params = {
			wmode: "transparent",
			menu: "true", 
			allowfullscreen: "true"
		};
		
		swfobject.embedSWF("/video/flvplayer.swf", target, width, height, "9.0.0", "/flash/expressInstall.swf", flashvars, params);
	}
});

var isie = (document.all) ? true : false;

function toggle (id, display, hide)
{
	var element = document.getElementById(id);
	
	if (isie)
	{
		element.style.display = (element.style.display == 'none') ? '' : 'none';
	}
	else
	{
		element.style.display = (element.style.display == 'none') ? display : 'none';
	}
	
	if (hide && document.getElementById(hide))
	{
		document.getElementById(hide).style.display = 'none';
	}
}
