﻿function vacaturePagina(paginaID) {
	//eerst alles verbergen
	for (var i=1; i<=2; i++) {
		document.getElementById('vacaturesItemsPagina'+i).style.display='none';
	}
	document.getElementById('vacaturesItemsPagina'+paginaID).style.display='';
	
	if (paginaID==1) {
		document.getElementById('vacaturesNavigatie').innerHTML='<a href="javascript:void(0);" onclick="vacaturePagina(2);">Meer vacatures</a>';
	}
	else {
		document.getElementById('vacaturesNavigatie').innerHTML='<a href="javascript:void(0);" onclick="vacaturePagina(1);">Vorige pagina</a>';
	}
}

function ajaxGetArticle(i) {
	sendRequest('xml/werkenbijpulse_article.aspx?id='+i,ajaxCallBackArticle, null);
}
function ajaxCallBackArticle(req) {
	document.getElementById("contentContainer").innerHTML= '<div id="innerContent">'+req.responseText+'</div>';
}
function getArticle(id, title) {
	hideAll();
	document.getElementById("contentContainer").innerHTML='';
	document.title = "Werken bij Pulse | " + title;    
	ajaxGetArticle(id);
}

function ajaxGetVacature(i) {
	sendRequest('xml/werkenbijpulse_vacature.aspx?id='+i,ajaxCallBackVacature, null);
}
function ajaxCallBackVacature(req) {
	document.getElementById("contentContainer").innerHTML= '<div id="innerContent">'+req.responseText+'</div>';
}
function getVacature(id, title) {
	hideAll();
	document.getElementById("contentContainer").innerHTML='';
	document.title = "Werken bij Pulse | " + title;    
	ajaxGetVacature(id);
	stopVideoFlash(); // stop the video from playing in flash
}


// ajax request functies
function sendRequest(url, callback, postData, isAsynch, params) {
	if (isAsynch==null) {
		isAsynch=true;
	}
	var req=new XMLHttpRequest();
	if (!req) return;
	var method = (postData) ? 'POST' : 'GET';
	//plak een random nummer achter de  om te voorkomen dat de browser de pagina uit de cache haalt
	if (url.indexOf('?')==-1) {
		//? zit niet in de url
		url+='?rnd='+Math.random();
	}
	else {
		//? zit wel in url
		url+='&rnd='+Math.random();
	}
	req.open(method,url,isAsynch);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData) {
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	}
	if (callback!==null && isAsynch) {
		req.onreadystatechange = function () {
			if (req.readyState != 4) return;
			if (req.status != 200 && req.status != 304) {
				alert('error in ajax call to '+url);
				return;
			}
			callback(req, params);
		}
	}
	if (req.readyState == 4) return;
	req.send(postData);
	if (callback!==null && !isAsynch) {
		//bij synchronized uitvoeren de callback zelf uitvoeren, in Firefox wordt daardoor onreadystatechange
		// niet uitgevoerd
		callback(req, params);
	}
}  
function tweenToState(target_int) {

	total_width = 984;
	widthFour = total_width/6*4;
	widthTwo = total_width/6*2
	widthZero = 0;
	
	var duration = 0.5;
	var easingFunc = eval("Tween.regularEaseOut");
	a_mc = document.getElementById('flashUNIQUEID');
	b_mc = document.getElementById('contentContainer');
	c_mc = document.getElementById('vacaturesContainer');
	d_mc = document.getElementById('flashContainer');
	
	    switch(target_int) {
		    case 0:
			    aTween = new Tween(a_mc.style,'width',easingFunc,getWidth(a_mc, false, false),widthFour,duration,'px');
			    dTween = new Tween(d_mc.style,'width',easingFunc,getWidth(d_mc, false, false),widthFour,duration,'px');
			    bTween = new Tween(b_mc.style,'width',easingFunc,getWidth(b_mc, false, false),widthZero,duration,'px');
			    cTween = new Tween(c_mc.style,'width',easingFunc,getWidth(c_mc, false, false),widthTwo, duration,'px');
			    document.getElementById('vacaturesExpander').style.width = '0px';
		    break;
		    case 1:
			    aTween = new Tween(a_mc.style,'width',easingFunc,getWidth(a_mc, false, false),188,duration,'px');
			    dTween = new Tween(d_mc.style,'width',easingFunc,getWidth(d_mc, false, false),188,duration,'px');
			    bTween = new Tween(b_mc.style,'width',easingFunc,getWidth(b_mc, false, false),779,duration,'px');
			    cTween = new Tween(c_mc.style,'width',easingFunc,getWidth(c_mc, false, false),16,duration,'px');
			    document.getElementById('vacaturesExpander').style.width = '16px';
		    break;
		    case 2:
			    aTween = new Tween(a_mc.style,'width',easingFunc,getWidth(a_mc, false, false),widthZero,duration,'px');
			    dTween = new Tween(d_mc.style,'width',easingFunc,getWidth(d_mc, false, false),widthZero,duration,'px');
			    bTween = new Tween(b_mc.style,'width',easingFunc,getWidth(b_mc, false, false),widthFour,duration,'px');
			    cTween = new Tween(c_mc.style,'width',easingFunc,getWidth(c_mc, false, false),widthTwo, duration,'px');
			    document.getElementById('vacaturesExpander').style.width = '0px';
		    break;
		    default:
			    // do nothing
		    break;
	    }
	    aTween.start();
	    bTween.start();
	    cTween.start();
	    dTween.start();
}

var timerId = 0;
var timerDuration = 8000;
var currentCat = 0;

function hideAll() {
	for(i = 0; i < 5; i++) {
		clearHover(i);
	}
}
function doLoop() {
	timerId = setTimeout(doLoop, timerDuration);
	showCategory(currentCat.toString());
	if(currentCat != 4) {
		currentCat++;
	} else {
		currentCat = 0;
	}		
}
function showCategory(id) {
	hideAll();
	pushXmlToFlash('xmlCat'+id);
	document.getElementById('btn_cat'+id).src = "/images/btn_"+id+"_on.gif";
    document.getElementById('btn_photo'+id).src = "/images/"+id+"_geel.jpg";
    document.getElementById('btn_item'+id).className = "categoryactive";
}
function doHover(id) {
	document.getElementById('btn_cat'+id).src = "/images/btn_"+id+"_on.gif";
    document.getElementById("btn_item"+id).className = "categoryactive";
	document.getElementById("btn_photo"+id).src = "/images/"+id+"_geel.jpg";
}
function clearHover(id) {
	document.getElementById('btn_cat'+id).src = "/images/btn_"+id+".gif";
    document.getElementById("btn_item"+id).className = "categoryitem";
	document.getElementById("btn_photo"+id).src = "/images/"+id+"_wit.jpg";
}
function _init() {
    vacaturePagina(1);
	document.getElementById('vacaturesExpander').onclick = function() {
		tweenToState(0);
	}
	var so = new SWFObject("images/flash.swf?"+Math.random(), "flashUNIQUEID", "1", "1", "9", "#FFFFFF");
	so.addParam("allowScriptAccess", "sameDomain");
	so.addParam("scaleMode","noBorder");
	so.addParam("align","TL");
	so.addVariable("xmlDir", "xmlCat0");
	so.write("flashMovie"); 
	doLoop();
}