window.addEvent('load', function() {
	addLiefDagboek();
	addRollOverBoeken();
	addSIFRKoppen();
	detectEcardOpener();
});

window.addEvent('domready', function() {
	addMarquee();
});

/** defaults **/
var openProject;

/**	function addLiefDagboek
		functionaliteit bij items
**/

function addLiefDagboek () {
				
	var dagboekitems = ($$('div.liefdagboekitem'));
	if (dagboekitems.length > 0) {
		
		dagboekitems.each(function(item, index) {
			
			/* eerste item openen */
			if (index == 0) {
				item.addClass("liefdagboekitemactief");
				item.effect('height',{
							duration: 0
				}).start(item.scrollHeight);
				openProject = item;
			}
			
			item.addEvent('click', function() {
				opencloseLiefDagboekItem(item);
			});
			
		});
		
	}
		
}

/**	function openLiefDagboekItem
		opent of sluit items bij onclick
**/

function opencloseLiefDagboekItem (item) {
	
	/* sluit open item */
	if (openProject) {
		openProject.removeClass("liefdagboekitemactief");
		openProject.effect('height',{
					duration: 300
		}).start($E('h2', openProject).scrollHeight);
	}
	
	/* open item */
	item.addClass("liefdagboekitemactief");
	item.effect('height',{
				duration: 300
	}).start(item.scrollHeight);
	
	openProject = item;
	
}

/**	function addRollOverBoeken
		rollover bij blok en bij button in blok boeking
**/

function addRollOverBoeken () {
	
	var nieuwsblok = ($$('img#nieuwsbutton'));
	
	if (nieuwsblok.length > 0) {
		
		nieuwsblok.each(function(item, index) {
			
			item.addEvent('mouseenter', function() {
				this.src = "/siteimg/button_meernieuws_over.gif";
			});
						
			item.addEvent('mouseleave', function() {
				this.src = "/siteimg/button_meernieuws.gif";
			});
			
		});
	}
	
	var boekblok = ($$('div.blokboeking'));
	if (boekblok.length > 0) {
		
		boekblok.each(function(item, index) {
			
			item.addEvent('mouseenter', function() {
				item.addClass("blokboekingaan");
			});
			
			item.addEvent('mouseleave', function() {
				item.removeClass("blokboekingaan");
			});
			
		});
	}
	
	var boekblokbutton = ($$('div.blokboeking img'));
	if (boekblokbutton.length > 0) {
		
		boekblokbutton.each(function(item, index) {
			
			item.addEvent('mouseenter', function() {
				this.src = "/siteimg/button_boeking_over.gif";
			});
						
			item.addEvent('mouseleave', function() {
				this.src = "/siteimg/button_boeking.gif";
			});
			
		});
	}
	
	var shopbutton = ($$('div#footerkolomlinks img'));
	if (shopbutton.length > 0) {
		
		shopbutton.each(function(item, index) {
			
			item.addEvent('mouseenter', function() {
				this.src = "/siteimg/button_shop_over.gif";
			});
						
			item.addEvent('mouseleave', function() {
				this.src = "/siteimg/button_shop.gif";
			});
			
		});
	}
	
}

function addSIFRKoppen () {
	
	if(typeof sIFR == "function"){
			 sIFR.replaceElement("h2.sifr", named({sFlashSrc: "/swf/neville.swf", sColor: "#ffffff", sWmode: "transparent" }));
	};
	
}

function addMarquee() {
	
	var lichtkrant = ($$('div#lichtkrant'));
	if (lichtkrant.length > 0) {
		
		 var so = new SWFObject("/swf/lichtkrant.swf", "movie", "650", "42", "8", "#ffffff");
	   so.addParam("wmode", "transparent");
	   so.addVariable("xmlURL", "/swf/lichtkrant.xml");
	   so.write("lichtkrant");
		
	}
	
}

/**
 *
 * Pim : Add 22-09-2008 (shadowbox voor fotoboek pagina)
 * initBandOverlays, toggleSendForm, detectEcardOpener
 *
 */

/**
 * initBandOverlays
 * starts overlay functionallity
 *
 * @author Rocco Janse <rocco@efocus.nl>
 */

function initBandOverlays() {
	
	var bandButtons = $$('a.band');
	
	bandButtons.each(function(button) {
	
		var currentButton = button.getProperty('class').split(' ');
		var currentOverlay = $(currentButton[2]);
		
		currentOverlay.setStyles({'opacity': 0, 'display': 'none'});
		
		var fade = new Fx.Style(currentOverlay, 'opacity', {duration: 300, wait:false});
		
		button.addEvent('mouseenter', function() {
			currentOverlay.setStyles({'opacity': 0, 'display': 'block'});
			fade.start(0,0.9);
		});
		button.addEvent('mouseleave', function() {
			fade.start(0.9,0);
			currentOverlay.setStyles({'opacity': 0, 'display': 'none'});
		});
	});
}


/**
 * toggleSendForm
 * toggles send ecard form in shadowbox
 *
 * @author Rocco Janse <rocco@efocus.nl>
 */
 
function toggleSendForm() {

	var sendForm = $('sendform');

	if (sendForm.status != 'open') {					
		var fade = new Fx.Style(sendForm, 'opacity', {duration: 300}).set(0);
		sendForm.setStyles({'display': 'block'});
		fade.start(0,0.9);
		sendForm.status = 'open';
	} else {
		var fade = new Fx.Style(sendForm, 'opacity', {duration: 300}).set(0.9);
		fade.start(0.9,0).chain(function() { 
			sendForm.setStyles({'display': 'none'});
			sendForm.status = 'closed'; 
		});					
	}
}

/**
 * detectEcardOpener
 * detects get var from querystring to open ecard shadowbox automatically
 *
 * @author Rocco Janse <rocco@efocus.nl>
 */
 
function detectEcardOpener() {

	var url = 'PhotoViewer.aspx';
	var firstPart = false;
	var secondPart = false;

	// detect querystring
	var queryString = location.search.substring(1, location.search.length);
		
	if (queryString.length != 0) {				
		queryString = queryString.replace(/\+/g, ' ');
		
		// split querystring
		var queryArguments = queryString.split('&');
		
		for (var i = 0; i < queryArguments.length; ++i) {
			
			// detect var we need (ex. &card=1)
			var queryPair = queryArguments[i].split('=');

			if (queryPair[0] == 'Id' && queryPair[1] != null) {
				firstPart = true;
				url += '?gId=' + queryPair[1];
			}
			
			if (queryPair[0] == 'card' && queryPair[1] != null) {
				secondPart = true;
				url += '&page=' + queryPair[1];
			}
			
		}
		
		if (firstPart != false && secondPart != false) {
					
			// detect is shadowbox is defined
			try { var exists = (Shadowbox != undefined) }
			catch(e) { var exists = false }
			
			// if defined, open shadowbox
			if (exists) {
				Shadowbox.open({
					type: 'iframe',
					content: url,
					width: 573,
					height: 480						
				});
			} else {
				return;
			}
		}

	} else {
		return;
	}	
}
