	function stripTypeFromId(element, type) {
  return $(element).attr('id').replace(type + '_', '');
};

function extractIdFromHtml(html, selector) {
  if (!selector) { var selector = 0; }
  return '#' + $(html).get(selector).id;
}

activatorClass = function(klass) {
  for (key in klass) {
    if (key.match(/^activate/) && typeof klass[key] == 'function')
      $(document).ready(klass[key]);
  }
}

var Application = {
  resetPulse: function () {
	PAS.load('Resetting CityPulse...')
    $.post('/cityscape/reset.js', function(rf) {
		if (getFlashMovie("intro") && rf) {  getFlashMovie("intro").sendTextToFlash("refresh",cs.comm,cs.tower,cs.worksp,-1);  }; 
		PAS.load()
		
    });
  }	,
  loading: function(message){
	   if (message) {
	     	$('#ajax_loading').html('<div><img src="/images/loader.gif"></img>'+ message +'</div>').show();
	     } else {
	     	$('#ajax_loading').hide();
	     }
	}
}

var PAS = {
  showError: function(status){
	var message_box = $('#ajax_loading');
	
	 if(status == 404) {
	   message_box.show().html("<div>The page you requested cannot be found. <a href='/#/communities'>Click here to return to all Communities.</a></div>"); 
	   return false;
	 }
	 else if(status == 403) {
	   message_box.show().html("<div>You do not have permission to view that page <a href='/#/communities'>Click here to return to all Communities.</a></div></div>"); 
	   return false;
	 }
	 else if(status == 408) {
	   message_box.show().html("<div>Your request has timed out <a href='"+ window.location.href + "?" + Math.floor(Math.random() * 12456) +"' id='reload_page'>Click here to try again.</a></div>"); 
	 }
	 else if (status == 'cityscape') {
	   message_box.show().html("<div>There was an error with the CityScape. <a href='"+ window.location.hash +"' id='reload_page' onclick='javascript: window.location.reload()'>Click here reload the page.</a></div>");
	 }
	 else {
	   message_box.show().html("<div>There was an error. <a href='"+ window.location.hash +"' id='reload_page' onclick='javascript: window.location.reload()'>Click here reload the page.</a></div>");
	 }
  },
  say: function(message, load){
	var message_box = $('#ajax_loading');
	   if (message) {
			message_box.html('<div>'+ message +'</div>').show(); 
		} else { 
			message_box.html().hide();
		}
	},
  load: function(message){
	var message_box = $('#ajax_loading');
	   if (message) {
	     	message_box.html('<div><img src="/images/loader.gif"></img>'+ message +'</div>').show();
	     } else {
	     	message_box.hide();
	     }
	},
	reload: function(){
	    var event = new Object;
	    event.path = $.address.value()
	    Navigation.change(event)
	    return false
	}
}

jQuery.fn.resetUpdateRowClasses = function() {
    $.each(['without_files', 'files'], function(i, klass) {
      var rows = $('.updates.' + klass + ' .actual_updates div.update').removeClass('light_bg').removeClass('dark_bg');
      rows.filter(':even').addClass('light_bg');
      rows.filter(':odd').addClass('dark_bg');
    }); }

// Configuration stuff
jQuery.easing.def = 'easeInOutQuint';

// Get Cityscape
function getFlashMovie(movieName) {   var isIE = navigator.appName.indexOf("Microsoft") != -1;   return (isIE) ? window[movieName] : document[movieName];  }  function formSend() {   var text = document.htmlForm.sendField.value;   getFlashMovie("intro").sendTextToFlash(text);     }    function getTextFromFlash(str) {   document.htmlForm.receivedField.value = "From Flash: " + str;   return str + " received";  };

//faster remove from dom
$.fn.removefromdom = function(s) {
		
    if (!this) return;

    var el = document.getElementById(this.attr("id"));

    if (!el) return;

    var bin = document.getElementById("GarbageBin");

    //before deleting el, recursively delete all of its children.
    while (el.childNodes.length > 0) {
        if (!bin) {
            bin = document.createElement("DIV");
            bin.id = "GarbageBin";
            document.body.appendChild(bin);
        }

        bin.appendChild(el.childNodes[el.childNodes.length - 1]);
        bin.innerHTML = "";
    }

    el.parentNode.removeChild(el);

    if (!bin) {
        bin = document.createElement("DIV");
        bin.id = "GarbageBin";
        document.body.appendChild(bin);
    }

    bin.appendChild(el);
    bin.innerHTML = "";
};
