/* Contactpunt Vlaamse Infolijn - Unobtrusive Javascript */


/* Preloading images */

function preload() {
	pic1= new Image(22,21); 
	pic1.src="/w3vlaanderen/VlaamseInfolijn/images/quotearrowright_hover.png"; 

	pic2= new Image(22,21); 
	pic2.src="/w3vlaanderen/VlaamseInfolijn/images/quotearrowright.png"; 
	
	pic3= new Image(22,21); 
	pic3.src="/w3vlaanderen/VlaamseInfolijn/images/quotearrowleft_hover.png"; 
	
	pic4= new Image(22,21); 
	pic4.src="/w3vlaanderen/VlaamseInfolijn/images/quotearrowleft.png"; 
	
	pic5= new Image(131,500); 
	pic5.src="/w3vlaanderen/VlaamseInfolijn/images/tekstballon_onder.gif"; 
	
	pic6= new Image(131,9); 
	pic6.src="/w3vlaanderen/VlaamseInfolijn/images/tekstballon_boven.gif"; 	
		
}

/* Functie die aantal quotes opvraagt, er een uitkiest, onclick event toevoegt op pijltjes en daarbij als parameter currentquoteId doorgeeft */

function addclicks(z) {

	var	currentquoteId;
	
	currentquoteId = z;

	document.getElementById('quoteknop_next').onclick=function(){shownextquote(currentquoteId);};
	document.getElementById('quoteknop_previous').onclick=function(){showpreviousquote(currentquoteId);};

}

/* Functie die */

function shownextquote(z)
{
	var z, currentquote, currentfoto, nextquoteId, nextnextquoteId, nextfoto, nextnextfoto, tekstballon;
	
	currentquote = document.getElementById('quote-' + z);
	currentfoto = document.getElementById('quotefoto-' + z);
	nextquoteId = z + 1;
	nextnextquoteId = z + 2;
	
	switch(nextquoteId) {
		case 4:
		nextquoteId = 1;
		break;
	}

	switch(nextnextquoteId) {
		case 4:
		nextnextquoteId = 1;
		break;
		
		case 5:
		nextnextquoteId = 2;
		break;		
	}
	
	currentfoto.className = 'current';
	nextfoto = document.getElementById('quotefoto-' + nextquoteId);
	nextfoto.className = 'next';
	nextnextfoto = document.getElementById('quotefoto-' + nextnextquoteId);
	nextnextfoto.className = 'previous';
	
	tekstballon = document.getElementById("tekstballon");
	if (tekstballon != null) {
		if (z == 1) 
			hidetekstballon();
			else {}
	}
	else {}
	
	$(currentquote).fadeTo("medium", 0, function(){fnextquote(currentquote, nextquoteId);});
	$(currentfoto).fadeTo("medium", 0, function(){fnextfoto(currentfoto, nextquoteId, nextnextquoteId);});	

	z = nextquoteId;
	addclicks(z);

}

function showpreviousquote(y)
{
	var y, currentquote, currentfoto, prevquoteId, prevprevquoteId, tekstballon;
	
	currentquote = document.getElementById('quote-' + y);
	currentfoto = document.getElementById('quotefoto-' + y);
	prevquoteId = y - 1;
	prevprevquoteId = y - 2;
	
	switch(prevquoteId) {
		case 0:
		prevquoteId = 3;
		break;
	}

	switch(prevprevquoteId) {
		case 0:
		prevprevquoteId = 3;
		break;
		
		case -1:
		prevprevquoteId = 2;
		break;		
	}
	
	currentfoto.className = 'current';
	prevfoto = document.getElementById('quotefoto-' + prevquoteId);
	prevfoto.className = 'next';
	prevprevfoto = document.getElementById('quotefoto-' + prevprevquoteId);
	prevprevfoto.className = 'previous';

	tekstballon = document.getElementById("tekstballon");
	if (tekstballon != null) {
		if (y == 1) 
			hidetekstballon();
			else {}
	}
	else {}

	$(currentquote).fadeTo("medium", 0, function(){fprevquote(currentquote, prevquoteId);});
	$(currentfoto).fadeTo("medium", 0, function(){fprevfoto(currentfoto, prevquoteId, prevprevquoteId);});	

	y = prevquoteId;
	addclicks(y);

}


function fnextquote(a, b) {

	var a, b, nextquote;

	nextquote = document.getElementById('quote-' + b);

	togglert(a);
	togglert(nextquote);

}

function fprevquote(g, h) {

	var g, h, prevquote;

	prevquote = document.getElementById('quote-' + h);

	togglert(g);
	togglert(prevquote);

}

function fnextfoto(c, d, e) {

	var c, d, e, nextfoto, nextnextfoto;

	nextfoto = document.getElementById('quotefoto-' + d);
	nextnextfoto = document.getElementById('quotefoto-' + e);

	c.className = c.className.replace('current','previous');
	$(c).fadeTo("fast", 1);

	nextfoto.className = nextfoto.className.replace('next','current');
	
	nextnextfoto.className = nextnextfoto.className.replace('previous','next');
	
}

function fprevfoto(i, j, k) {

	var i, j, k, prevfoto, prevprevfoto;

	prevfoto = document.getElementById('quotefoto-' + j);
	prevprevfoto = document.getElementById('quotefoto-' + k);

	i.className = i.className.replace('current','previous');
	$(i).fadeTo("fast", 1);

	prevfoto.className = prevfoto.className.replace('next','current');
	
	prevprevfoto.className = prevprevfoto.className.replace('previous','next');
	
}

function togglert(f) {
	
	$(f).fadeTo("fast", 1);
	
	if(/hide/.test(f.className))
	{
		f.className = f.className.replace('hide','show');
	}
	else
	{	
		f.className = f.className.replace('show','hide');
	}
}

/* Functie zoekt quoteknoppen en zet deze aan */
/* Quoteknoppen enkel zichtbaar als Javascript enabled is */

function showquoteknoppen()
{
	var quoteknoppen;
	quoteknoppen = document.getElementById('quoteknoppen');
	quoteknoppen.className = quoteknoppen.className.replace('hide','show');
}

/* Cookie zetten */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* Cookie lezen */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* Code toevoegen */
function checkcookie()
{

	var inhoudcookie = readCookie("cookie_tekstballon");
	if (inhoudcookie == null) {
		setTimeout("insertcode()", 2000);
	}
	else {}
}

function insertcode()
{

var code ="<div><h4>TIP</h4><p>Klik op het pijltje om de volgende foto te tonen.</p><a href=\"javascript:;\" onClick=\"hidetekstballon()\" title=\"sluiten\"><span>sluiten</span></a></div>";
var myContainer = document.createElement('div');
myContainer.setAttribute('id','tekstballon');
myContainer.innerHTML = code;
document.getElementById("quotetekstboven").appendChild(myContainer);
$(myContainer).fadeIn("slow");
}

function hidetekstballon() {
	var tekstballon = document.getElementById("tekstballon");
	$(tekstballon).fadeOut("slow");
	createCookie("cookie_tekstballon","yes","10000");
}


// Bij laden van de pagina moet de eerste functie uitgevoerd worden

$(document).ready(function(){
	preload();
	addclicks(1);
	showquoteknoppen();
	checkcookie();
 });


function sitestat(ns_l){
        ns_l+='&amp;ns__t='+(new Date()).getTime();ns_pixelUrl=ns_l;
        ns_0=document.referrer;
        ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;
        if(ns_0.length>0)ns_l+='&amp;ns_referrer='+escape(ns_0);
        if(document.images){ns_1=new Image();ns_1.src=ns_l;}else
        document.write('<img src="'+ns_l+'" width="1" height="1" alt="">');
}


