var IMGpointer = 2;
var headerPointer = 1;
var fotoPointer = 1;
var headerTimer = setTimeout('volgendeHeader(0)', 5000);
var advertentieIMGpointer = 1;
var tabLocked = 0;
var quickblokPointer = 1;
var quickblokTimer = setTimeout('volgendeQuickblok()', 5000);
var bannerPointer = 1;
var homepageBannerPointer = 1;
var sluitTimers = new Array();
var bannerTimer = setTimeout('volgendeBanner()', 5000);
var homepageBannerTimer = setTimeout('volgendeHomepageBanner()', 5000);
	
$(document).ready(function() { 
  // Logo
	  $('#site-logo').html(weergeefSWF('/swf/logo.swf', 136, 86));
 
  // Topmenu
	  $('.topli').hover(function() {
		  if ($(this).find('.submenu').length > 0) {
  		  $(this).find('.submenu:hidden').slideDown('fast');
  			$(this).addClass('actiefTopLi');
  			$(this).addClass('openSubmenuLi');
        
        $('.header').css('height', '400px');
			} else {
  			$(this).addClass('actiefTopLi');
			}
		}, function() {
		  $(this).find('.subsubmenu:visible').slideUp('fast');
		  $(this).find('.submenu:visible').slideUp('fast');
			$(this).removeClass('actiefTopLi');
			$(this).removeClass('openSubmenuLi');
      $('.header').css('height', '158px');
		});
		
	  $('.subli').hover(function() {
      var aantal = $(this).find('.subsubmenu:hidden').length;

		  $(this).find('.subsubmenu:hidden').slideDown('fast');
			$(this).addClass('actiefSubLi');
		}, function() {
		  $(this).find('.subsubmenu:visible').slideUp('fast');
			$(this).removeClass('actiefSubLi');
		});
		
		$('.subsubmenu').hover(function() {
		
		}, function() {
		  $(this).slideUp('fast');
			$(this).removeClass('actiefSubLi');
		});
	
	// Zoekveld
		
		$('.zoekFilter .zoekSelect .zoekLabel').click(function() {
		  if($(this).parent().find('.zoekSelectie:hidden').length > 0) {
		    $(this).parent().find('.zoekSelectie:hidden').slideDown('fast');
			} else {
		    //$(this).parent().parent().find('.zoekSelectie:visible').slideUp('fast');
			}
		});
		
		$('.zoekFilter .zoekSelectie').hover(function() {
		
		}, function() {
		  $(this).slideUp('fast');
		});
		
		$('.zoekID input').blur(function() {
		  if ($(this).val() == '') {
			  $(this).val('Objectnummer');
			}
		});
		
  // woning scroller
    woningScrollerBinds();
  
	// Placeholder
	  $('input').each(function() {
		  if($(this).attr('placeholder')) {
			  if($(this).val() == '') {
			    $(this).val($(this).attr('placeholder'));
				}
				
				$(this).focus(function() {
				  if ($(this).val() == $(this).attr('placeholder')) { $(this).val(''); }
				});
				
				$(this).blur(function() {
				  if ($(this).val() == '') { $(this).val($(this).attr('placeholder')); }
				});
			}
		});
		
	// Footer logo's in nieuw venster
	  $('.footer .logos a').click(function(e) {
		  e.preventDefault();
			window.open($(this).attr('href'));
		});
		
	// Lightbox
	  $('.fotoalbumAfbeelding').lightBox();
		
    $('.thumbnails a, .lightbox').lightBox();

    $('#ad_afbeelding_img').click(function () { $('.thumbnails').find('a:first').click();  });
		
		$('.vorigeIMG img').click(function() {
		   $('.volgendeIMG img').fadeIn();
			 
			 IMGpointer--;
			 
			 var src = $('.thumbnails').find('li:nth-child(' + IMGpointer + ')').find('a').attr('href');
			 var aantal = $('.thumbnails').find('li').length;
			 
			 $('#ad_afbeelding_img').attr('src', src);
			 
			 if (IMGpointer == 2) {
			   $(this).fadeOut();
			 }
		});		
		
		$('.volgendeIMG img').click(function() {
		   $('.vorigeIMG img').fadeIn();
			 
			 IMGpointer++;
			 
			 var src = $('.thumbnails').find('li:nth-child(' + IMGpointer + ')').find('a').attr('href');
			 var aantal = $('.thumbnails').find('li').length;
			 
			 $('#ad_afbeelding_img').attr('src', src);
			 
			 if (IMGpointer >= aantal - 1) {
			   $(this).fadeOut();
			 }
		});
		
		$('.buttonDoorsturen').click(function() {
		  var html = $('.doorstuurContent').html();
			
			$.fancybox({
			  content: '<div class="doorstuurVak">' + html + '</div>',
				autoDimensions: false,
				height: 150,
				width: 450,
				onComplete:function() {

				}
			});
		});
	
	
	  $('.bottomFotos .vorigeBanner').click(function() {
		  bannerPointer--;
			
			if (bannerPointer < 1) {
			  bannerPointer = $('.bottomFotos .banners .banner').length;
			}
			
			weergeefBanner(bannerPointer);
		});
	
	  $('.bottomFotos .volgendeBanner').click(function() {
		  bannerPointer++;
			
			var aantal = $('.bottomFotos .banners .banner').length;
			
			if (bannerPointer > aantal) {
			  bannerPointer = 1;
			}
			
			weergeefBanner(bannerPointer);
		});
		
	  $('.vorigeHomepageBanner').click(function() {
		  homepageBannerPointer--;
			
			if (homepageBannerPointer < 1) {
			  homepageBannerPointer = $('.homepageBanners .homepageBannersLijst .homepageBanner').length;
			}
			
			weergeefHomepageBanner(homepageBannerPointer);
		});
	
	  $('.volgendeHomepageBanner').click(function() {
		  homepageBannerPointer++;
			
			var aantal = $('.homepageBanners .homepageBannersLijst .homepageBanner').length;
			
			if (homepageBannerPointer > aantal) {
			  homepageBannerPointer = 1;
			}
			
			weergeefHomepageBanner(homepageBannerPointer);
		});
		
		if($('.homepageBanners .homepageBannersLijst .homepageBanner').length < 2) {
		  clearTimeout(homepageBannerTimer);
		}
	
  /* tabbladen */
    $('.tabNav a').click(function(e) {
      e.preventDefault();

      var klasse = $(this).attr('class');
      var mag = klasse.indexOf('actieveTab');

      if (tabLocked == 0 && mag == -1) {        
        $('.tabNav .actieveTab').removeClass('actieveTab');
        $(this).addClass('actieveTab');
        
        $('.tabContent .actieveTab:visible').slideUp('fast', function() {
          $(this).removeClass('actieveTab');
          $('.tabContent .' + klasse + ':hidden').slideDown('fast').addClass('actieveTab');
          tabLocked = 0;
        });
      
      }
    }); 
  
  /* advertentie foto slider */
	/*
    if ($('.advertentieFotos .directLijst li').length > 1) {
      setInterval('volgendeAdvertentieFoto()', 5000);
    }
		*/
    
    $('.advertentieFotos .directLijst a').lightBox();

  
  $('.nieuwsbriefFormulier').submit(function(e) {
    e.preventDefault();
    
    var emailadres = $(this).find('.emailAdres').val();
		var naam = $(this).find('.emailNaam').val();
		
		var emailPlaceholder = $(this).find('.emailAdres').attr('placeholder');
		var naamPlaceholder = $(this).find('.emailNaam').attr('placeholder');
    
    if(emailadres.length > 0 && emailadres != emailPlaceholder && naam.length > 0 && naam != naamPlaceholder) {
      $.ajax({ 
        url: '/php/verwerk/maillist.php?emailadres=' + emailadres + '&naam=' + naam,
        success: function(response) {
          $.fancybox({content: '<div style="padding:15px;width:200px;">' + response + '</div>'});
        }
      });
    } else if(naam.length == 0 || naam == naamPlaceholder) {
      $.fancybox({content: '<div style="padding:15px;width:200px;color:red">Vul uw naam in</div>'});
		} else {
      $.fancybox({content: '<div style="padding:15px;width:200px;color:red">Vul uw e-mail adres in</div>'});
    }
  });
	
	$('#blijfopdehoogte .toggle').click(function() {
	  if ($('#blijfopdehoogte .inner:visible').length) {
		  $('#blijfopdehoogte .inner').slideUp('fast');
		} else {
		  $('#blijfopdehoogte .inner').slideDown('fast');
			$('html, body').animate({ scrollTop: 60000 }, 'slow'); 
		}
	});
	
  $('.blijfopdehoogteForm').submit(function(e) {
    e.preventDefault();
    
    var emailadres = $(this).find('.emailAdres').val();
		var minimaal = $(this).find('#minimaal_field').val();
		var maximaal = $(this).find('#maximaal_field').val();
		
		var emailPlaceholder = $(this).find('.emailAdres').attr('placeholder');

    if(emailadres.length > 0 && emailadres != emailPlaceholder) {
      $.ajax({ 
        url: '/php/verwerk/maillistWoningen.php?emailadres=' + emailadres + '&minimaal='+  minimaal + '&maximaal=' + maximaal,
        success: function(response) {
          $.fancybox({content: '<div style="padding:15px;width:200px;">' + response + '</div>'});
        }
      });
    } else {
      $.fancybox({content: '<div style="padding:15px;width:200px;color:red">Vul uw e-mail adres in</div>'});
    }
  });
	
	$('.objectFotoLink').click(function() {
	    var url = $(this).parent().find('.leesmeer').attr('href');
		  document.location.href = url;
	});
	
	$('.objectFotoLijst .objectFoto').lightBox();
	
	$('.categorieKeuze .custom_list_item').click(function() {
	  setTimeout('verzendSorteren()', 300);
	}); 
  
  $('.fotoLast').click(function() {
    var nr = $('.fotoGroot .foto img').attr('pointer');

    groteFotoLaden(nr - 1);
  });
  
  $('.fotoNext').click(function() {
    var nr = $('.fotoGroot .foto img').attr('pointer');

    groteFotoLaden(parseInt(nr) + 1);
  });
  
  $('.videoBlok').click(function() {
    var code = $(this).find('.embedCode');

    $.fancybox({
      content: htmlspecialchars_decode(code.html()),
      padding: 0
    });
  });
	
	$('.tabAdvertentieVideo').click(function() {
	  $(window).scrollTop(0);
	
	  var code = $('.embed_code').html();

    $.fancybox({
      content: htmlspecialchars_decode(code),
      padding: 0
    });
	});
	
	$('.voorkeurselectieLijst li').click(function() {
	    var aantal = $(this).find('.aantal').html();
			var keuze = $(this).attr('nr');
			
			$('.voorkeurselectieLijst .geselecteerd').removeClass('geselecteerd');
			
			$(this).find('.selectie').addClass('geselecteerd');
			
			$('.voorkeurAantal .aantal').html(aantal);
			$('.voorkeurAantal').show();
			$('.voorkeurselectieForm .button').show();
			$('.voorkeurSelectieWaarde').val(keuze);
	});
  
  $('#reageer_bron').change(function() {
    var waarde = $(this).val();
    
    if(waarde == 'Anders') {
      $('#bron_anders_rij').show();
    } else {
      $('#bron_anders_rij').hide();
    }
  });
	
	$('.koperContact').fancybox( { type: 'iframe', padding: 0, autoDimensions: false, height: 500, width: 420 });
});

function groteFotoLaden(nr) {
  if(nr > 0) {
    var src = $('.fotoThumbnails .woningAfbeelding' + nr + ' img');
    
    if(src.length > 0) {
      src = src.attr('src').replace('thumb2','thumb1');
      
      groteFotoBekijken(src, nr);
    }
  }
}

function groteFotoBekijken(src, nr) {
  $('.fotoGroot .foto').html('<img src="' + src + '" alt="" pointer="' + nr + '" />');
}

function verzendSorteren() {
  $('.sorteerBalkFormulier').submit();
}

function volgendeBanner() {
  bannerPointer++;
	
	var aantal = $('.bottomFotos .banners .banner').length;
	
	if (bannerPointer > aantal) {
	  bannerPointer = 1;
	}
	
	weergeefBanner(bannerPointer);
}

function weergeefBanner(nr) {
  $('.banners .banner:visible').fadeOut('fast', function() {
    $('.banners .banner:nth-child(' + nr + ')').fadeIn();
    
    var titel = $('.banners .banner:nth-child(' + nr + ')').attr('title');
    
    $('.bottomFotos .kop').html(titel);
	});
	
	clearInterval(bannerTimer);
  bannerTimer = setTimeout('volgendeBanner()', 5000);	
}

function volgendeHomepageBanner() {
  homepageBannerPointer++;
	
	var aantal = $('.homepageBanners .homepageBannersLijst .homepageBanner').length;
	
	if (homepageBannerPointer > aantal) {
	  homepageBannerPointer = 1;
	}
	
	weergeefHomepageBanner(homepageBannerPointer);
}

function weergeefHomepageBanner(nr) {
  $('.homepageBannersLijst .homepageBanner:visible').fadeOut('fast', function() {
    $('.homepageBannersLijst .homepageBanner:nth-child(' + nr + ')').fadeIn();
    
    var titel = $('.homepageBannersLijst .homepageBanner:nth-child(' + nr + ')').attr('title');
    
    $('.homepageBanners .homepageKop .titel').html(titel);
	});
	
	clearInterval(homepageBannerTimer);
  homepageBannerTimer = setTimeout('volgendeHomepageBanner()', 5000);	
}

function customSelectieOpenen(id) {
  box = $('#' + id + '_list');
  
  $('#blijfopdehoogte').css('z-index', 10000);

	if ($('#' + id + '_list:visible').length) {
	  box.hide();
	} else {
	  box.show();
	}
}

function customSelectieSluiten(id) {
	$('#' + id + '_list').hide();
  
   if ($('.custom_selectie_list:visible').length == 0) {
     $('#blijfopdehoogte').css('z-index', 1);
   }
}

function customSelectieKeuze(id, waarde, bedrag, k) {
  customSelectieWaarde(id, waarde, bedrag, k);
  customSelectieSluiten(id);
}

function customSelectieWaarde(id, waarde, bedrag, k) {
	if (bedrag) {
	  $('#' + id + '_content').html('&euro; ' + waarde);
	} else {
	  $('#' + id + '_content').html(waarde);
	}
	
	if(k) {
	  $('#' + id + '_field').val(k);
	} else {
	  $('#' + id + '_field').val(waarde);
	}
}

function customSelectieSluitenTimer(id) {
  sluitTimers[id] = setTimeout("customSelectieSluiten('" + id + "')", 300);
}

function customSelectieVerwijderTimer(id) {
	clearTimeout(sluitTimers[id]);
}

function woningScrollerBinds() {
    $('.woningenScroller .vorigeTab').click(function() {
		  var scroller = $(this).parent();
      var aantal = $(scroller).find('.scroller ul').length;
			var huidignr = parseInt($(scroller).attr('pointer')) - parseInt(1);					

      if (huidignr > 0) {
  			$(scroller).attr('pointer', huidignr);
        weergeefScroller(scroller, huidignr);
      }
    });
    
    $('.woningenScroller .volgendeTab').click(function() {
		  var scroller = $(this).parent();
      var aantal = $(scroller).find('.scroller ul').length;
			var huidignr = parseInt($(scroller).attr('pointer')) + parseInt(1);

      if (huidignr <= aantal) {
  			$(scroller).attr('pointer', huidignr);				
        weergeefScroller(scroller, huidignr);
      }
    });
    
    $('.woningenScroller .tab').click(function(e) {
      e.preventDefault();
			
			var scroller = $(this).parent().parent();
			
      if ($(this).hasClass('actieveTab')) {
      
      } else {
        var url = $(this).attr('href');
        
        $.ajax({
          url: url,
          success: function(data){
            $(scroller).html($(data).find('.woningenEchteScroller').html());
            woningScrollerBinds();
            $(scroller).attr('pointer', 1);
          }
        });
      }
    });
    
    
    $('.woningenScroller .scroller li').click(function(e) {

    });    
}

function weergeefScroller(scroller, nr) {
  $(scroller).find('.scroller ul:visible').fadeOut('fast', function() {
    $(scroller).find('.scroller .scrollercontent' + nr).fadeIn('fast');
  });
}

function volgendeAdvertentieFoto() {
  advertentieIMGpointer++;
  
  var aantal = $('.advertentieFotos .directLijst li').length;
  
  if (advertentieIMGpointer > aantal) { advertentieIMGpointer = 1; }

  var src = $('.advertentieFotos .directLijst li:visible').html();
  $('.advertentieFotos .bg').html(src);
  $('.advertentieFotos .directLijst li:visible').fadeOut('fast',  function() {
    $('.advertentieFotos .directLijst li:nth-child(' + advertentieIMGpointer + ')').fadeIn('fast');
  });
}

function actieveHeader(nr) {
  headerPointer = nr;

  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijstContainer').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (nr - 1) + ')').addClass('actiefHeaderNummer');
	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (nr - 1) + ')').fadeIn('fast').addClass('actieveHeaderFoto');
	
	//clearInterval(headerTimer);
  //headerTimer = setInterval('volgendeHeader(0)', 5000);
}

function vorigeHeader(handmatig) {
  headerPointer--;
	
	if (headerPointer < 1) {
	  headerPointer = $('.headerFoto').length;
	}
	
  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijstContainer').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (headerPointer - 1) + ')').addClass('actiefHeaderNummer');	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (headerPointer - 1) + ')').fadeIn().addClass('actieveHeaderFoto');
	
  clearInterval(headerTimer);
	
	if (!handmatig) {
    headerTimer = setTimeout('volgendeHeader(0)', 5000);
	}
}

function volgendeHeader(handmatig) {
  headerPointer++;
	
	if (headerPointer > $('.headerFoto').length) {
	  headerPointer = 1;
	}
	
  var bg = $('.actieveHeaderFoto').css('backgroundImage');
	
	$('.headerfotosLijstContainer').css('backgroundImage', bg);

	$('.actiefHeaderNummer').removeClass('actiefHeaderNummer');
	$('.headersNav li:eq(' + (headerPointer - 1) + ')').addClass('actiefHeaderNummer');	
	
  $('.actieveHeaderFoto').hide().removeClass('actieveHeaderFoto');
	$('.headerFoto:eq(' + (headerPointer - 1) + ')').fadeIn().addClass('actieveHeaderFoto');

  clearInterval(headerTimer);	

	if (!handmatig) {
    headerTimer = setTimeout('volgendeHeader(0)', 5000);
	}
}

function volgendeQuickblok() {
  quickblokPointer++;
	
  if ($('.blokkenLijst').length <= 1) {
  	clearInterval(quickblokTimer);
    return false;
  }
  
	if (quickblokPointer > $('.blokkenLijst').length) {
	  quickblokPointer = 1;
	}
	
	$('.quickblokken .quickblokNav .actiefBlokIcon').removeClass('actiefBlokIcon');
	$('.quickblokken .quickblokNav .BlokIcon' + quickblokPointer).addClass('actiefBlokIcon');
	
	$('.quickblokken .actieveBlokkenLijst').fadeOut('fast', function() {
	  $('.quickblokken .blokkenLijst:nth-child(' + quickblokPointer + ')').addClass('actieveBlokkenLijst').slideDown('fast');
	});
	
	clearInterval(quickblokTimer);
  quickblokTimer = setTimeout('volgendeQuickblok()', 5000);
}

function actieveQuickblok(i) {

  quickblokPointer = i;

	$('.quickblokken .quickblokNav .actiefBlokIcon').removeClass('actiefBlokIcon');
	$('.quickblokken .quickblokNav .BlokIcon' + quickblokPointer).addClass('actiefBlokIcon');
	
	$('.quickblokken .actieveBlokkenLijst').fadeOut('fast', function() {
	  $('.quickblokken .blokkenLijst:nth-child(' + quickblokPointer + ')').addClass('actieveBlokkenLijst').slideDown('fast');
	});

	clearInterval(quickblokTimer);
}

function zoekSelectWaarde(type, id, titel) {
  $('#' + type + 'Input').val(id);
  $('#' + type + 'Text').html(titel);
	$('#' + type + 'Keuze').slideUp('fast');
}


function vorigeFoto() {
  fotoPointer--;
	
	if (fotoPointer < 1) {
	  fotoPointer = $('.detailFotos img').length;
	}
	
  var bg = $('.detailFotos .actieveFoto').css('backgroundImage');
	
	$('.detailFotos .actieveFotoContainer').css('backgroundImage', bg);
	
  $('.detailFotos .actieveFoto').hide().removeClass('actieveFoto');
	$('.detailFotos img:eq(' + (fotoPointer - 1) + ')').fadeIn().addClass('actieveFoto');
}

function volgendeFoto() {
  fotoPointer++;
	
	if (fotoPointer > $('.detailFotos img').length) {
	  fotoPointer = 1;
	}
	
  var bg = $('.detailFotos .actieveFoto').css('backgroundImage');
	
	$('.detailFotos .actieveFotoContainer').css('backgroundImage', bg);
	
  $('.detailFotos .actieveFoto').hide().removeClass('actieveFoto');
	$('.detailFotos img:eq(' + (fotoPointer - 1) + ')').fadeIn().addClass('actieveFoto');
}

function controleerReactie() {
  box1 = document.getElementById('reageer_naam');
  box2 = document.getElementById('reageer_email');
  box3 = document.getElementById('reageer_titel');
  box4 = document.getElementById('reageer_inhoud');	
  box5 = document.getElementById('reageer_telefoon');
	
	if (!box1.value || !box2.value || !box3.value || !box4.value || !box5.value) {
	  alert('Niet alle velden zijn ingevuld.');
		return false;
	} else {
	  return true;
	}
}

function weergeefSWF(src, width, height) {
    var output = '';
		output += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '">';
		output += '  <param name="movie" value="' + src + '">';
		output += '  <param name=quality value=high>';
		output += '  <param name="allowScriptAccess" value="always" />';
		output += '  <param name="wmode" value="transparent" /><param name="SCALE" value="exactfit">';
		output += '  <embed wmode="transparent" src="' + src + '" width="' + width + '" height="' + height + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" scale="exactfit"></embed>';
		output += '</object>';
		
		return output;
}

function htmlspecialchars_decode (string, quote_style) {
    // Convert special HTML entities back to characters  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/htmlspecialchars_decode    // +   original by: Mirek Slugen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Mateusz "loonquawl" Zalega
    // +      input by: ReverseSyntax
    // +      input by: Slawomir Kaniecki    // +      input by: Scott Cariss
    // +      input by: Francois
    // +   bugfixed by: Onno Marsman
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)    // +      input by: Ratheous
    // +      input by: Mailfaker (http://www.weedem.fr/)
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');    // *     returns 1: '<p>this -> &quot;</p>'
    // *     example 2: htmlspecialchars_decode("&amp;quot;");
    // *     returns 2: '&quot;'
    var optTemp = 0,
        i = 0,        noquotes = false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE': 1,
        'ENT_HTML_QUOTE_DOUBLE': 2,
        'ENT_COMPAT': 2,        'ENT_QUOTES': 3,
        'ENT_IGNORE': 4
    };
    if (quote_style === 0) {
        noquotes = true;    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i = 0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4            
						if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            } else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should 
				// string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');
 
    return string;
}
