function printListLots(input){
	stukNr= input.substring(0,input.indexOf("|"))
	lotNr=input.substring((input.indexOf("|")+1),input.length);		
	$.ajax({
		url: '/templates/matexi/includes/getAvailableLots.asp',
		data:{kostenplaatsnr:lotNr,kostenplaats_stuknr:stukNr},
		success: function(data) {
			$("#divToPrint").show();
			$("#divToPrint").html(data);
			$("#divToPrint").jqprint();
			$("#divToPrint").hide();
		},
		dataType: "html"
	});
}

function showVerkaveling(kostenplaatsNummer,lotNummer,gemeente,imageWidth,imageHeight,zoektype) {
	showOverlay();		
	var verkaveling = document.createElement("DIV");
	verkaveling.id = "verkavelingContainer";
	document.body.appendChild(verkaveling);		

	var flashV = {
		xmlPath:"/templates/"+aspWebTemplate+"/includes/getCoordinaten.asp?kostenplaatsnr=" + kostenplaatsNummer + "&kostenplaats_stuknr=" + lotNummer,
		imgPath:"/write/images/verkavelingen/",
		kostenplaatsnummer:kostenplaatsNummer,
		lotnummer:lotNummer,
		title:verkavelingTitle,
		txtClose:txtClose,
		txtBack:txtBack,
		txtPrint:txtPrint,
		txtLegende:txtLegende,
		txtWoning:txtWoning,
		txtGrond:txtGrond,
		txtAppartement:txtAppartement,
		txtVerkocht:txtVerkocht,
		txtLotNr:txtLotNr,
		txtTypeGrond:txtTypeGrond,
		txtTypeBebouwing:txtTypeBebouwing,
		txtAantalSlaapkamers:txtAantalSlaapkamers,
		txtGrondOpp:txtGrondOpp,
		txtBrutoOpp:txtBrutoOpp,
		txtContact:txtContact,
		txtPdf:txtPdf,
		txtPartner:txtPartner,
		txtList:txtList,
		listUrl:listUrl,
		gemeente:gemeente,
		zoektype:zoektype
	};	
	
	var att = { data:"/templates/"+aspWebTemplate+"/swf/verkaveling.swf", width:imageWidth, height:imageHeight};
	var par = {flashvars:jQuery.param(flashV)};
	par.bgcolor="#FFFFFF";
	var id = "verkavelingContainer";	
	
	swfobject.createCSS("#verkavelingContainer", "left:" + Math.max(0, Math.round((getPageSize()[0]-imageWidth)/2))+"px");
	swfobject.createCSS("#verkavelingContainer", "width:" +  imageWidth+"px");
	swfobject.createCSS("#verkavelingContainer", "height:" + imageHeight+"px");	
	var myObject = swfobject.createSWF(att, par,id);
}


function vertaal(t,taal){
	if(t=="koopwoningen")return txtKoopwoningen;
	if(t=="appartementen")return txtAppartementen;
	if(t=="gronden")return txtGronden ;
}

		
function showKaart(title,zoektype){
	showOverlay();
	
	var kaartje = document.createElement("DIV");
	kaartje.id = "kaartContainer";
	document.body.appendChild(kaartje);
	
	var flashV = {
		zoektype:zoektype,
		title:title,
		txtSearch:txtZoek,
		txtZoomOut:txtZoomOut
	};				
	var att = { data:"/templates/"+aspWebTemplate+"/swf/gronden.swf", width:950, height:500, bgcolor:"#FFFFFF", wmode:"opaque"};
	var par = {flashvars:jQuery.param(flashV)};
	var id = "kaartContainer";	
	swfobject.createCSS("#kaartContainer", "left:" + Math.max(0, Math.round((getPageSize()[0]-950)/2))+"px");
	var myObject = swfobject.createSWF(att, par,id);						
	
}

function showProvincies(provincieType) {
	var flashV = {
		title:provinciesTitle,
		provincieType:provincieType
	};				
	var att = { data:"/templates/"+aspWebTemplate+"/swf/provincies.swf", width:700, height:440, bgColor:"#FFFFFF", wmode:"opaque" };
	var par = {flashvars:jQuery.param(flashV)};
	var id = "provincieContainer";	
	var myObject = swfobject.createSWF(att, par,id);			
}

function processZoomImages(path){

	$("a.zoomImage").each(
		function(){
			var obj=$(this);
			var thumbsize = obj.attr("rel");
			var thumbsizeArr = obj.attr("rel").split("x");
			var thumbwidth = thumbsizeArr[0];
			var thumbheight = thumbsizeArr[1];
			var urlParts = /^(https?:\/\/.+?)?(\/.+?)(\?.*?)?$/.exec(obj.attr("href")); 
			var server = urlParts[1]; // maybe be '' depending on the browser 
			var relpath = urlParts[2]; 
			var query = urlParts[3]; 
			$.ajax({
				  url: path,
				  data : {
				  	  file : relpath,
					  width : thumbwidth,
					  height : thumbheight
				  },
				  success: function(data) {
					obj.html("<img src='"  + data.thumb + "' alt='' />");
				  },
				  dataType:"json"
			});
			obj.fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	200, 
				'speedOut'		:	200, 
				'overlayShow'	:	false
			});
		}
	)
}

function showKijkboek(kijkboekTitle) {
	showOverlay();
	var kijkboek = document.createElement("DIV");
	kijkboek.id = "kijkboekContainer";
	document.body.appendChild(kijkboek);
	var att;

	if(websiteLanguage=="Dutch") {
		att = { data:"ibrochure/ibrochure.swf", width:1000, height:680, bgColor:"#FFFFFF", wmode:"opaque" };
	}	else{
		att = { data:"ibrochure/ibrochure2.swf", width:1000, height:680, bgColor:"#FFFFFF", wmode:"opaque" };
	}

	var par = {};
	var id = "kijkboekContainer";	
	swfobject.createCSS("#kijkboekContainer", "left:" + Math.max(0, Math.round((getPageSize()[0]-1000)/2))+"px");
	var myObject = swfobject.createSWF(att, par,id);			
	
	var kijkboekLink = document.createElement("DIV");
	kijkboekLink.id = "kijkboekLinkContainer";
	kijkboekLink.style.left = Math.max(0, Math.round((getPageSize()[0]-1000)/2))+"px";
	kijkboekLink.innerHTML="<a href=\"/index1.asp?menuId=25\">"+kijkboekTitle+"</a>";
	document.body.appendChild(kijkboekLink);
}		

function showPictures(divId, urls, body) {	
	var setWidth = body ? "395" : "378";
	var setHeight = body ? "255" : "203";	
	var fVars = "";

	for(var i = 0; i < urls.length; i++) {
		fVars = fVars + "&pictureUrl"+ i+"=" +urls[i];
	}
	if(!body) {
		fVars = fVars + "&showShadow=true&showCorner=true";
	}
	var att = { data:"templates/matexi/swf/pictures.swf", width:setWidth, height:setHeight, bgcolor:"#FFFFFF", wmode:"opaque"};
	var par = {
		flashvars:fVars
	};
	var myObject = swfobject.createSWF(att, par,divId);	
	$('#' + divId).addClass('searchDetailPictures');
}

function showBusyOverlay() {
	if($('#busyoverlay')!=null){
		updateBusyOverlayPosition();
		$('#busyoverlay').show();	
	}
}

function showOverlay(){
	hideDynamicBoxes();
	updateOverlaySize();
	if($('#overlay')!=null){
		$('#overlay').show();
	}
}

function hideBusyOverlay(){
	if($('#busyoverlay')!=null){
		$('#busyoverlay').hide();
	}
}

function hideOverlay(){
	if($('#overlay')!=null){
		$('#overlay').hide();
	}
}

function hideSidebar() {
	if($('#sidebarCell')!=null){
		$("#sidebarCell").hide();
	}
}

function showSidebar() {
	if($('#sidebarCell')!=null){
		$("#sidebarCell").show();
	}
}

function updateSelectedCities(cities) {
	$("gemeenteId").value = cities.join("; ");
}

function closeMap() {
	hideKaart();
}

function closeVerkaveling() {
	hideVerkaveling();
}

function search(zoektype,postcode) {
	hideKaart();
	zoek(zoektype,postcode);
}

function stretchBodyCell(){	
	var dochoogte = $(document).height()
	var headerhoogte = 179;
	var introhoogte = $("#introCell").height();
	var creditshoogte = $("#creditsCell").height();
	$("#bodyCell").height(dochoogte - headerhoogte - introhoogte - creditshoogte);	
}

function updateSelectedProvincieProjecten(prov){
	SWFAddress.setValue("/projecten/?provincie=" + prov);
}
function updateSelectedProvincieProjectenRef(prov){
	SWFAddress.setValue("/projecten/?provincie=" + prov + "&isReferentie=1");
}

function updateSelectedProvincieSfeerwoningen(prov){
	SWFAddress.setValue("/sfeerwoningen/?provincie=" + prov);
}

function updateOverlaySize() {
	var arrayPageSize = getPageSize();
	if($('#overlay')!=null){
		$('#overlay').width(arrayPageSize[0]);
		$('#overlay').height(arrayPageSize[1]);
	}
}

function updateBusyOverlayPosition() {
	var arrayPageSize = getPageSize();
	if($('#busyoverlay')!=null){
		$('#busyoverlay').css("left", Math.round((arrayPageSize[0]-156)/2));
		$('#busyoverlay').css("top", Math.round((arrayPageSize[1]-8)/2));
	}
}

function hideContainers(){
	try{
		hideKaart();
	}catch(e){
	}
	try{
		hideVerkaveling();
	}catch(e){
	}	
	try{
		hideKijkboek();
		SWFAddress.setValue("/");
	}catch(e){}
}

function removeFilter() {
	this.style.removeAttribute("filter");
}

function hideDynamicBoxes(){
	$('object').each(function(){$(this).hide()});
	$('select').each(function(){$(this).hide()});
	$('embed').each(function(){$(this).hide()});
}
function showDynamicBoxes(){
	$('object').each(function(){$(this).show()});
	$('select').each(function(){$(this).show()});
	$('embed').each(function(){$(this).show()});
}

function hideKaart() {
	hideOverlay();
	$('#kaartContainer').html='';
	$('#kaartContainer').remove();
	showDynamicBoxes();
}

function hideKijkboek() {
	hideOverlay();	
	$('#kijkboekContainer').html='';
	$('#kijkboekLinkContainer').html='';
	$('#kijkboekContainer').remove();
	$('#kijkboekLinkContainer').remove();
	showDynamicBoxes();
}

function hideVerkaveling() {
	hideOverlay();
	$('#verkavelingContainer').html='';
	$('#verkavelingContainer').remove();	
	showDynamicBoxes();
}

function loadKaart(params){
	$.ajax({
		url: '/templates/matexi/includes/kaart.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadGallery(galleryId){
	$.ajax({
		url: '/templates/matexi/includes/fotoboek.asp',
		data:{galleryId:galleryId},
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadJobs(){
	$.ajax({
		url: '/templates/matexi/includes/toonJobs.asp',
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function showJob(jobId,jobLanguage){	
	$.ajax({
		url: '/templates/matexi/includes/toonJobs.asp',
		data:{jobId:jobId, jobLanguage:jobLanguage},
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadProjecten(params){
	$.ajax({
		url: '/templates/matexi/includes/projecten.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadReferenties(params){
	$.ajax({
		url: '/templates/matexi/includes/referenties.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadSfeerwoningen(params){
	$.ajax({
		url: '/templates/matexi/includes/sfeerwoningen.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function showLot(kostenplaatsNummer,lotNummer,oppervlakte,gemeente,typewoning,zoektype){
	$.ajax({
		url: '/templates/matexi/includes/toonLot.asp',
		data:{kostenplaatsNummer:kostenplaatsNummer,lotNummer:lotNummer,oppervlakte:oppervlakte,gemeente:gemeente,typewoning:typewoning,zoektype:zoektype},
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});

}
function loadCalendar(params){
	$.ajax({
		url: '/templates/matexi/includes/includeCalendarEvents.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function loadNews(params){
	$.ajax({
		url: '/templates/matexi/includes/includeNewsEvents.asp',
		data:params,
		ajaxStart:showBusyOverlay(),
		success: function(data) {
			hideBusyOverlay();
			$("#bodyMain").html(data);
		},
		dataType: "html"
	});
}
function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

/*****************************
/* zoek functies
/****************************/

function zoek(zoektype,postcode){
	SWFAddress.href("index1.asp?menuId=37#/tekoop/?kostenplaatsNummer=&gemeente="+postcode+"&zoektype="+zoektype+"&browseCounter=1");		
}
/*****************************
/* algemene functies
/****************************/

function get_windowHeight()
{
   var myWidth = 0, myHeight = 0;
   if( typeof( window.innerWidth ) == 'number' )
   { //Non-IE
      myHeight = window.innerHeight;
   }
   else
   {
      if ( document.documentElement && ( document.documentElement.clientWidth ||    document.documentElement.clientHeight ) )
   { //IE 6+ in 'standards compliant mode'
      myHeight = document.documentElement.clientHeight;
   }
   else
   {
      if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
      { //IE 4 compatible
         myHeight = document.body.clientHeight;
      }
   }
}
   return myHeight;
}

function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

function handleChange(event) {
    var parameters = new Array();
	var parameterNames = new Array();
	var parameterList = '';
	var i=0;
    for (var p in event.parameters) {
		parameterNames[i] = p;
        parameters[i] = event.parameters[p];
		parameterList+=parameterNames[i] + '=' + parameters[i] + '&';
		i++;
    }

	try{
		hideKijkboek();
	}catch(e){}					

	
	switch(SWFAddress.getPathNames()[0]){
		case 'projecten':				
			loadProjecten(parameterList);
			break;
		case 'referenties':
			loadProjecten("isReferentie=1");
			break;
		case 'tekoop':
			loadKaart(parameterList);
			break;
		case 'calendar':
			loadCalendar(parameterList);
			break;
		case 'news':
			loadNews(parameterList);
			break;
		case 'sfeerwoningen':
			loadSfeerwoningen(parameterList);
			break;
		case 'jobs':
			SWFAddress.href("http://jobs.matexigroup.be", "_blank");
			break;				
		case 'fotoboek':
			loadGallery(parameters[0]);
			break;
		case 'job':
			showJob(parameters[0],parameters[1]);
			break;					
		case 'verkaveling':
			showVerkaveling(parameters[0],parameters[1],parameters[2],parameters[3],parameters[4],parameters[5],parameters[6],parameters[7]);				
			break;
		case 'kijkboek':
			showKijkboek(txtOntvangKijkboek);
			break;					
	}
}

$(function(){

	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
	
	window.onload = stretchBodyCell;
	window.onresize = stretchBodyCell;

	// overlay code
	$('#overlay').click(hideContainers);
	

});
