function MeatPackingMap(domObjectID, XMLPath, cycleDelay, filter) {
    var domObject = $("#" + domObjectID)[0];
    var observers = {};

    if (GBrowserIsCompatible()) {
        var map = new GMap2(domObject);
        var projection = map.getCurrentMapType().getProjection();
        var blankMap = new GMapType([], projection, "blank");
        map.addMapType(blankMap);
        map.setMapType(blankMap);

        //var boundaries = new GLatLngBounds(new GLatLng(40.73493, -74.01349), new GLatLng(40.74527, -73.9954));
        var boundaries = new GLatLngBounds(new GLatLng(40.736655, -74.013478), new GLatLng(40.745462, -73.998196));
        var meatMap = new GGroundOverlay("/map/img/map.png", boundaries);

        map.addOverlay(meatMap);

        map.disablePinchToZoom();


        var minMapScale = 17;
        var maxMapScale = 17;
        var mapTypes = map.getMapTypes();

        for (var i = 0; i < mapTypes.length; i++) {
            mapTypes[i].getMinimumResolution = function() {
                return minMapScale;
            }
            mapTypes[i].getMaximumResolution = function() {
                return maxMapScale;
            }
        }
        map.setCenter(new GLatLng(40.739586, -74.006692), 17);


        var topRight = map.fromLatLngToDivPixel(boundaries.getNorthEast());
        var bottomLeft = map.fromLatLngToDivPixel(boundaries.getSouthWest());

        topRight.x -= map.getSize().width / 2;
        topRight.y += map.getSize().height / 2;
        bottomLeft.x += map.getSize().width / 2;
        bottomLeft.y -= map.getSize().height / 2;

        topRight = map.fromDivPixelToLatLng(topRight);
        bottomLeft = map.fromDivPixelToLatLng(bottomLeft);
        var allowedBounds = new GLatLngBounds(bottomLeft, topRight);

        this.model = new MapModel(XMLPath, map, cycleDelay, filter);
        this.controller = new MapController(this.model);
        this.view = new MapView(this.model, map, this.controller, allowedBounds);

        this.model.addListener("change", dispatchChange.bindMethod(this));
    }



    function dispatchChange() {
        dispatch("change", this);
    }

    function dispatch(eventName, context) {
        if (observers[eventName]) {
            for (var i = 0; i < observers[eventName].length; i++) {
                observers[eventName][i](context);
            }
        }
    }

    this.addListener = function(eventName, fn) {
        if (!observers[eventName]) {
            observers[eventName] = [];
        }
        observers[eventName][observers[eventName].length] = fn;
    }



}

MeatPackingMap.prototype.getCurrentLocation = function() {
    // returns the id of the marker currently shown in the model's cycle
    return this.model.currentLocation;
}

MeatPackingMap.prototype.setCurrentLocation = function(id) {
    // sets marker currently shown in the model's cycle
    // tooltip will only appear if cycling is on
    this.model.setCurrentLocation(id);
}

MeatPackingMap.prototype.setCycle = function(value) {
    // turns the map cycling on or off
    this.model.cycle = value;
}

MeatPackingMap.prototype.getCycle = function() {
    // returns the running state of the map cycling
    return this.model.cycle;
}

MeatPackingMap.prototype.setCycleDelay = function(seconds) {
    // sets the delay of the tooltip cycling in seconds
    // if set to 0 tooltips must be cycled manuallywith setCurrentLocation()
    this.model.setCycleDelay(seconds);
}

MeatPackingMap.prototype.nextFeatured = function() {
    // advances the map cycling to the next featured location
    // tooltip will only appear if cycling is on
    this.model.nextFeatured();
}

MeatPackingMap.prototype.prevFeatured = function() {
    // moves the map cycling to the previous featured location
    // tooltip will only appear if cycling is on
    this.model.prevFeatured();
}

MeatPackingMap.prototype.filter = function(category) {
    // show only those locations in category
    this.model.filter(category);
}

MeatPackingMap.prototype.getFilter = function() {
    // show only those locations in category
    return this.model.currentFilter;
}

MeatPackingMap.prototype.showLocation = function(id) {
    // show a specific location
    this.model.showLocation(id);
}

MeatPackingMap.prototype.hideLocation = function(id) {
    // hide a specific location
    this.model.hideLocation(id);
}

MeatPackingMap.prototype.showAll = function() {
    // show all locations
    this.model.showAll();
}

MeatPackingMap.prototype.hideAll = function() {
    // hide all locations
    this.model.hideAll();
}

MeatPackingMap.prototype.getXML = function() {
    // returns the raw xml
    return this.model.xml;
}

MeatPackingMap.prototype.panMap = function(direction) {
    // will pan the map a small distance
    // direction should be one of 'north', 'east', 'south', 'west'
    this.view.panMap(direction);
}

function MapController(model) {

    var model = model;

    this.markerClickedHandler = function(marker) {
        //window.location = model.locations[marker.id].permalink;
        model.cycle = false;
        model.setSelectedLocation(marker.id);
    }


    this.markerOverHandler = function(marker) {
        }

    this.markerOutHandler = function() {
        }


    this.mapOverHandler = function() {
        model.cycle = false;
    }

    this.mapOutHandler = function() {
        model.setSelectedLocation( - 1);
        model.cycle = true;
    }

    this.mapClickHandler = function() {
        model.setSelectedLocation( - 1);
    }

}

function MapModel(XMLPath, domObject, cycleDelay, filter) {
    cycleDelay *= 1000;
    this.domObject = domObject;
    this.currentLocation = -1;
    this.selectedLocation = -1;
    this.cycle = true;
    this.filtered = new Array();
    this.currentFilter = filter;


    var observers = {};

    var xmlLoaded = function(data, responseCode) {
        this.xml = GXml.parse(data);
        this.locations = xml2json.parser(data).locations.location;
        for (j = 0; j < this.locations.length; j++) {
            this.locations[j].id = j;
            this.locations[j].visible = true;
            this.locations[j].featured = this.locations[j].featured == "true";
        }
        this.filter(filter);
        if (cycleDelay > 0) {
            $(this).everyTime(cycleDelay,
            function() {
                if (this.cycle == true) {
                    this.nextFeatured();
                }
            });
        }
    }

    GDownloadUrl(XMLPath, xmlLoaded.bindMethod(this));

    function dispatch(eventName) {
        if (observers[eventName]) {
            for (var i = 0; i < observers[eventName].length; i++) {
                observers[eventName][i].call();
            }
        }
    }

    this.addListener = function(eventName, fn) {
        if (!observers[eventName]) {
            observers[eventName] = [];
        }
        observers[eventName][observers[eventName].length] = fn;
    }

    this.setSelectedLocation = function(num) {
        this.selectedLocation = num;

        if (this.selectedLocation >= this.locations.length) {
            this.selectedLocation = -1;
        }
        dispatch("change");
    }

    this.setCurrentLocation = function(num) {
        this.currentLocation = num;

        if (this.currentLocation >= this.locations.length) {
            this.currentLocation = -1;
        }
        dispatch("change");
    }

    this.setCycleDelay = function(seconds) {
        cycleDelay = seconds * 1000;
    }

}

MapModel.prototype.filter = function(category) {
    this.filtered = new Array();
    this.currentFilter = category;
    if (category) {
        for (var m = 0; m < this.locations.length; m++) {
            if (this.locations[m].category == category) {
                this.filtered.push(this.locations[m]);
            }
        }
    }
    else {
        this.filtered = this.locations;
    }
    $(this.domObject).trigger("filtered");
    this.setCurrentLocation( - 1);
    this.setCurrentLocation( - 1);

}

MapModel.prototype.showLocation = function(id) {
    this.locations[id - 1].visible = true;
    $(this.domObject).trigger("updateVisibllity");
}

MapModel.prototype.hideLocation = function(id) {
    this.locations[id - 1].visible = false;
    $(this.domObject).trigger("updateVisibllity");
}
MapModel.prototype.showAll = function() {
    for (j = 0; j < this.locations.length; j++)
    {
        this.locations[j].visible = true;
    }
    $(this.domObject).trigger("updateVisibllity");
}
MapModel.prototype.hideAll = function() {
    for (j = 0; j < this.locations.length; j++)
    {
        this.locations[j].visible = false;
    }
    $(this.domObject).trigger("updateVisibllity");
}
MapModel.prototype.nextFeatured = function() {
    var num = this.currentLocation + 1;
    if (num >= this.filtered.length) {
        num = 0;
    }

    while (num < this.filtered.length && (!this.filtered[num].featured || !this.filtered[num].visible)) {
        num++;
    }
    if (num >= this.filtered.length) {
        num = 0;
        while (num < this.filtered.length && (!this.filtered[num].featured || !this.filtered[num].visible)) {
            num++;
        }
    }
    if (num >= this.filtered.length) {
        num = -1;
    }

    this.setCurrentLocation(this.locations[num].id);



}

MapModel.prototype.prevFeatured = function() {
    var num = this.currentLocation - 1;
    if (num < 0) {
        num = this.filtered.length - 1;
    }

    while (num >= 0 && (!this.filtered[num].featured || !this.filtered[num].visible)) {
        num--;
    }
    if (num < 0) {
        num = this.filtered.length - 1;
        while (num >= 0 && (!this.filtered[num].featured || !this.filtered[num].visible)) {
            num--;
        }
    }
    if (num < 0) {
        num = -1;
    }

    this.setCurrentLocation(this.locations[num].id);

}


function MapView(mapModel, domObject, mapController, allowedBounds) {
    var insert;
    var model = mapModel;
    var controller = mapController;
    var markers = new Array();
    var tooltip = null;
    var panning = false;


    function updateVisibllity() {

        for (var j = 0; j < markers.length; j++) {
            if (model.filtered[j].visible) {
                $(markers[j].domObject).css({
                    "display": "none"
                });
            }
            else {
                $(markers[j].domObject).css({
                    "display": "block"
                });
            }
        }
    }

    function buildMarkers() {

        for (var j = 0; j < markers.length; j++) {
            $(markers[j].domObject).remove();
        }

        var locations = model.filtered;

        markers = new Array();

        for (var i = 0; i < locations.length; i++) {
            var point = new GLatLng(parseFloat(locations[i].lat), parseFloat(locations[i].lng));
            var markerPt = domObject.fromLatLngToContainerPixel(point);
            $(domObject.getContainer()).css("overflow-x", "hidden").css("overflow-y", "hidden");
            
            markers[i] = new CustomMarker(model, locations[i].id, getIcon(locations[i].category), i + 1);

            $(markers[i].domObject).css({
                "position": "absolute",
                "z-index": "1",
                "left": markerPt.x + "px",
                "top": markerPt.y + "px"
            }).appendTo(domObject.getContainer());

            markers[i].addListener("mouseenter", controller.markerOverHandler.bindMethod(controller, markers[i]));
            markers[i].addListener("mouseleave", controller.markerOutHandler.bindMethod(controller, markers[i]));
            markers[i].addListener("click", controller.markerClickedHandler.bindMethod(controller, markers[i]));



        }
    }

    $(domObject).bind("filtered", buildMarkers.bindMethod(this));
    $(domObject).bind("updateVisibllity", updateVisibllity.bindMethod(this));

    var update = function() {
        $(".marker .large").removeClass("large").addClass("small").parent().css({
            "margin": "0px",
            "z-index": "1"
        });

        if (panning) {
            return;
        }
        if (tooltip) {
            tooltip.lowerMarker();
            $(tooltip.domObject).remove();
            tooltip = null;
        }
        if (model.selectedLocation >= 0) {

            $(markers[model.filtered.indexOf(model.locations[model.selectedLocation])].domObject).css({
                "margin-left": "-4px",
                "margin-top": "-4px",
                "z-index": "0"
            })
            .children().first().removeClass("small").addClass("large");
            if (model.locations[model.selectedLocation]) {
                tooltip = new CustomToolTip(model, markers[model.filtered.indexOf(model.locations[model.selectedLocation])]);
            }
        }
        else if (model.currentLocation >= 0 && model.cycle) {
            tooltip = new CustomToolTip(model, markers[model.filtered.indexOf(model.locations[model.currentLocation])]);
            tooltip.raiseMarker();
        }
        if (tooltip) {
            $(domObject.getContainer()).append(tooltip.domObject);
            positionMapToTooltip();
            if ($('#mapCycle').length) {
              updateFeature();
            }
        }


        // Crappy Hack to get this to work on home page
        function updateFeature() {
            var $tooltip = $('#tooltip');
            var title = $tooltip.find('.name').html();
            var category = $tooltip.find('.name a').attr('rel');
            var description = $tooltip.find('img').attr('alt');
            var permalink = $tooltip.find('.name a').attr('href');
            $('#mapCycle h3').html(title);
            $('#mapCycle span.category').html(category);
            $('#mapCycle a.permalink').attr('href', permalink);
            $('#mapCycle p').html(description);
            $('#mapCycle').removeClass('loading');

        }
        


    }

    model.addListener("change", update.bindMethod(this));


    var checkBounds = function() {

        if (allowedBounds.containsLatLng(domObject.getCenter())) {
            return;
        }

        var c = domObject.getCenter();
        var x = c.lng();
        var y = c.lat();
        var maxX = allowedBounds.getNorthEast().lng();
        var maxY = allowedBounds.getNorthEast().lat();
        var minX = allowedBounds.getSouthWest().lng();
        var minY = allowedBounds.getSouthWest().lat();

        if (x < minX) {
            x = minX;
        }
        if (x > maxX) {
            x = maxX;
        }
        if (y < minY) {
            y = minY;
        }
        if (y > maxY) {
            y = maxY;
        }

        domObject.setCenter(new GLatLng(y, x));

    }

    var moveMarkers = function() {
        for (var i = 0; i < markers.length; i++) {
            var markerPt = domObject.fromLatLngToContainerPixel(new GLatLng(parseFloat(model.filtered[i].lat), parseFloat(model.filtered[i].lng)));
            $(markers[i].domObject).css({
                "left": markerPt.x + "px",
                "top": markerPt.y + "px"
            });
        }
        if (tooltip) {
            moveToolTip();
        }
    }

    GEvent.addListener(domObject, "move", checkBounds);
    GEvent.addListener(domObject, "move", moveMarkers);

    GEvent.addListener(domObject, "mouseover", controller.mapOverHandler.bindMethod(controller));
    GEvent.addListener(domObject, "mouseout", controller.mapOutHandler.bindMethod(controller));
    GEvent.addListener(domObject, "click", controller.mapClickHandler.bindMethod(controller));



    function getIcon(cat) {
        var iconURL = $("." + cat).css("background-image");
        iconURL = iconURL.replace(/"/g,"").replace(/url\(|\)$/ig, "");
        return iconURL;
    }


    function moveToolTip() {
        var tooltipOffsetLeft = -197;
        var tooltipOffsetTop = -190;
        var markerPt = domObject.fromLatLngToContainerPixel(new GLatLng(parseFloat(model.locations[tooltip.markerID].lat), parseFloat(model.locations[tooltip.markerID].lng)));
        $(tooltip.domObject).css({
            "left": (markerPt.x + tooltipOffsetLeft) + "px",
            "top": (markerPt.y + tooltipOffsetTop) + "px"
        });
    }

    function positionMapToTooltip() {
        moveToolTip();
        var tooltipOffsetLeft = -197;
        var tooltipOffsetTop = -190;

        panning = true;
        GEvent.addListener(domObject, "moveend",
        function() {
            panning = false;
        })
        domObject.panTo(new GLatLng(parseFloat(model.locations[tooltip.markerID].lat), parseFloat(model.locations[tooltip.markerID].lng)));


    }

    this.panMap = function(direction) {
        switch (direction) {
        case "north":
            domObject.panDirection(0, 1);
            break;
        case "east":
            domObject.panDirection( - 1, 0);
            break;
        case "south":
            domObject.panDirection(0, -1);
            break;
        case "west":
            domObject.panDirection(1, 0);
            break;
        default:
            return;
        }
    }

}

function CustomToolTip(model, marker) {
    this.marker = marker;
    this.markerID = marker.id;
    this.domObject = $("#meatMapTemplate .tooltip").clone();

    $(this.domObject).attr("id", "tooltip");
    if (! (typeof(model.locations[this.markerID].logo) == "string")) {
        $(this.domObject).find(".logo img").remove();
    }
    else {
        $(this.domObject).find(".logo img").attr("src", model.locations[this.markerID].logo);
        $(this.domObject).find(".logo img").attr("alt", model.locations[this.markerID].description);
    }
    $(this.domObject).find(".name a").html(model.locations[this.markerID].title);
    $(this.domObject).find(".address").text(model.locations[this.markerID].address);
    $(this.domObject).find(".phone").html(model.locations[this.markerID].phone);
    $(this.domObject).find(".url a").html(model.locations[this.markerID].url);
    $(this.domObject).find("a").attr("href", model.locations[this.markerID].permalink);
    $(this.domObject).find("a").attr("rel", model.locations[this.markerID].category);
    $(this.domObject).find(".url a").attr("href", model.locations[this.markerID].url);
    
    


}

CustomToolTip.prototype.raiseMarker = function() {
    $(this.marker.domObject).css("z-index", "100").find('.small').removeClass('small').addClass('large');
}

CustomToolTip.prototype.lowerMarker = function() {
    $(this.marker.domObject).css("z-index", "1").find('.large').removeClass('large').addClass('small');
}

function CustomMarker(model, markerID, iconURL, number) {
    var observers = {};

    this.id = markerID;
    this.domObject = $("#meatMapTemplate .marker").clone();

    $(this.domObject).find(".circle img").attr("src", iconURL);
    $(this.domObject).find(".number p").text(model.locations[this.id].index);
    
    if (model.locations[this.id].featured) {
      $(this.domObject).css('z-index', 100).addClass('featured');
    }
    
    
    // Changed to reflect the location in the backend

    /*
  $(this.domObject).hover(function(e) {
    $(this).find('>div').removeClass('small').addClass('large');
  }, function(){
    $(this).find('>div').removeClass('large').addClass('small'); 
  });     
        */


    $(this.domObject).mouseenter(function(e) {
        dispatch("mouseenter");
    });

    $(this.domObject).mouseleave(function(e) {
        dispatch("mouseleave");
    });

    if (model.locations[this.id].featured) {
      $(this.domObject).click(function(e) {
          dispatch("click");
      });
    }
    


    function dispatch(eventName) {
        if (observers[eventName]) {
            for (var i = 0; i < observers[eventName].length; i++) {
                observers[eventName][i]();
            }
        }
    }

    this.addListener = function(eventName, fn) {
        if (!observers[eventName]) {
            observers[eventName] = [];
        }
        observers[eventName][observers[eventName].length] = fn;
    }

}

Function.prototype.bindMethod = function(context) {
    var fn = this,
    ap,
    concat,
    args,
    isPartial = arguments.length > 1;
    // Strategy 1: just bind, not a partialApply
    if (!isPartial) {
        return function() {
            if (arguments.length !== 0) {
                return fn.apply(context, arguments);
            } else {
                return fn.call(context);
                // faster in Firefox.
            }
        };
    } else {
        // Strategy 2: partialApply
        ap = Array.prototype,
        args = ap.slice.call(arguments, 1);
        concat = ap.concat;
        return function() {
            return fn.apply(context,
            arguments.length === 0 ? args:
            concat.apply(args, arguments));
        };
    }
};

if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return - 1;
    }
}

//xml2json.js

/*
xml2json v 1.1
copyright 2005-2007 Thomas Frank

This program is free software under the terms of the 
GNU General Public License version 2 as published by the Free 
Software Foundation. It is distributed without any warranty.
*/

xml2json={
	parser:function(xmlcode,ignoretags,debug){
		if(!ignoretags){ignoretags=""};
		xmlcode=xmlcode.replace(/\s*\/>/g,'/>');
		xmlcode=xmlcode.replace(/<\?[^>]*>/g,"").replace(/<\![^>]*>/g,"");
		if (!ignoretags.sort){ignoretags=ignoretags.split(",")};
		var x=this.no_fast_endings(xmlcode);
		x=this.attris_to_tags(x);
		x=escape(x);
		x=x.split("%3C").join("<").split("%3E").join(">").split("%3D").join("=").split("%22").join("\"");
		for (var i=0;i<ignoretags.length;i++){
			x=x.replace(new RegExp("<"+ignoretags[i]+">","g"),"*$**"+ignoretags[i]+"**$*");
			x=x.replace(new RegExp("</"+ignoretags[i]+">","g"),"*$***"+ignoretags[i]+"**$*")
		};
		x='<JSONTAGWRAPPER>'+x+'</JSONTAGWRAPPER>';
		this.xmlobject={};
		var y=this.xml_to_object(x).jsontagwrapper;
		if(debug){y=this.show_json_structure(y,debug)};
		return y
	},
	xml_to_object:function(xmlcode){
		var x=xmlcode.replace(/<\//g,"§");
		x=x.split("<");
		var y=[];
		var level=0;
		var opentags=[];
		for (var i=1;i<x.length;i++){
			var tagname=x[i].split(">")[0];
			opentags.push(tagname);
			level++
			y.push(level+"<"+x[i].split("§")[0]);
			while(x[i].indexOf("§"+opentags[opentags.length-1]+">")>=0){level--;opentags.pop()}
		};
		var oldniva=-1;
		var objname="this.xmlobject";
		for (var i=0;i<y.length;i++){
			var preeval="";
			var niva=y[i].split("<")[0];
			var tagnamn=y[i].split("<")[1].split(">")[0];
			tagnamn=tagnamn.toLowerCase();
			var rest=y[i].split(">")[1];
			if(niva<=oldniva){
				var tabort=oldniva-niva+1;
				for (var j=0;j<tabort;j++){objname=objname.substring(0,objname.lastIndexOf("."))}
			};
			objname+="."+tagnamn;
			var pobject=objname.substring(0,objname.lastIndexOf("."));
			if (eval("typeof "+pobject) != "object"){preeval+=pobject+"={value:"+pobject+"};\n"};
			var objlast=objname.substring(objname.lastIndexOf(".")+1);
			var already=false;
			for (k in eval(pobject)){if(k==objlast){already=true}};
			var onlywhites=true;
			for(var s=0;s<rest.length;s+=3){
				if(rest.charAt(s)!="%"){onlywhites=false}
			};
			if (rest!="" && !onlywhites){
				if(rest/1!=rest){
					rest="'"+rest.replace(/\'/g,"\\'")+"'";
					rest=rest.replace(/\*\$\*\*\*/g,"</");
					rest=rest.replace(/\*\$\*\*/g,"<");
					rest=rest.replace(/\*\*\$\*/g,">")
				}
			} 
			else {rest="{}"};
			if(rest.charAt(0)=="'"){rest='unescape('+rest+')'};
			if (already && !eval(objname+".sort")){preeval+=objname+"=["+objname+"];\n"};
			var before="=";after="";
			if (already){before=".push(";after=")"};
			var toeval=preeval+objname+before+rest+after;
			eval(toeval);
			if(eval(objname+".sort")){objname+="["+eval(objname+".length-1")+"]"};
			oldniva=niva
		};
		return this.xmlobject
	},
	show_json_structure:function(obj,debug,l){
		var x='';
		if (obj.sort){x+="[\n"} else {x+="{\n"};
		for (var i in obj){
			if (!obj.sort){x+=i+":"};
			if (typeof obj[i] == "object"){
				x+=this.show_json_structure(obj[i],false,1)
			}
			else {
				if(typeof obj[i]=="function"){
					var v=obj[i]+"";
					//v=v.replace(/\t/g,"");
					x+=v
				}
				else if(typeof obj[i]!="string"){x+=obj[i]+",\n"}
				else {x+="'"+obj[i].replace(/\'/g,"\\'").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r")+"',\n"}
			}
		};
		if (obj.sort){x+="],\n"} else {x+="},\n"};
		if (!l){
			x=x.substring(0,x.lastIndexOf(","));
			x=x.replace(new RegExp(",\n}","g"),"\n}");
			x=x.replace(new RegExp(",\n]","g"),"\n]");
			var y=x.split("\n");x="";
			var lvl=0;
			for (var i=0;i<y.length;i++){
				if(y[i].indexOf("}")>=0 || y[i].indexOf("]")>=0){lvl--};
				tabs="";for(var j=0;j<lvl;j++){tabs+="\t"};
				x+=tabs+y[i]+"\n";
				if(y[i].indexOf("{")>=0 || y[i].indexOf("[")>=0){lvl++}
			};
			if(debug=="html"){
				x=x.replace(/</g,"&lt;").replace(/>/g,"&gt;");
				x=x.replace(/\n/g,"<BR>").replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;")
			};
			if (debug=="compact"){x=x.replace(/\n/g,"").replace(/\t/g,"")}
		};
		return x
	},
	no_fast_endings:function(x){
		x=x.split("/>");
		for (var i=1;i<x.length;i++){
			var t=x[i-1].substring(x[i-1].lastIndexOf("<")+1).split(" ")[0];
			x[i]="></"+t+">"+x[i]
			}	;
			x=x.join("");
			return x
		},
		attris_to_tags: function(x){
			var d=' ="\''.split("");
			x=x.split(">");
			for (var i=0;i<x.length;i++){
				var temp=x[i].split("<");
				for (var r=0;r<4;r++){temp[0]=temp[0].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")};
				if(temp[1]){
					temp[1]=temp[1].replace(/'/g,'"');
					temp[1]=temp[1].split('"');
					for (var j=1;j<temp[1].length;j+=2){
						for (var r=0;r<4;r++){temp[1][j]=temp[1][j].replace(new RegExp(d[r],"g"),"_jsonconvtemp"+r+"_")}
					};
					temp[1]=temp[1].join('"')
				};
				x[i]=temp.join("<")
			};
			x=x.join(">");
			x=x.replace(/ ([^=]*)=([^ |>]*)/g,"><$1>$2</$1");
			x=x.replace(/>"/g,">").replace(/"</g,"<");
			for (var r=0;r<4;r++){x=x.replace(new RegExp("_jsonconvtemp"+r+"_","g"),d[r])}	;
			return x
		}
	};


	if(!Array.prototype.push){
		Array.prototype.push=function(x){
			this[this.length]=x;
			return true
		}
	};

	if (!Array.prototype.pop){
		Array.prototype.pop=function(){
			var response = this[this.length-1];
			this.length--;
			return response
		}
	};



