// Markup based unobtrusive comprehensive dom ready execution
// http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/
// Remove these comments and replace CLIENTNAME with the name of the client or site.
SIXMS = {
    common: {
        init: function() {
            // Common scripts here
            $('input').placeholder();
            $('#homeaccordion .toggler').click(function() {
                $('#homeaccordion .element').hide('fast');
                $('#homeaccordion .toggler').removeClass("togglerOpen");
                $(this).addClass("togglerOpen");
                $(this).next().show('fast');
            });
            $($('#homeaccordion .element')[0]).show();
        },
        finalize: function() {
            // Low priority scripts here
        }
    },
    patients: {
        init: function() {
            // Scripts for patieints section here...
        }
    },
    dentists: {
        init: function() {
            // Scripts for dentists section here...

        }
    },
    home: {
        init: function() {
            // Home page specific script example (for the home page)
            


            //$('#flash').append('<p style="padding: 130px 20px; background: #EEE; color: #999; font-style: italic; text-align: center;">Flash content here (script generated from base.js line 16)</p>');

        }

    }
};

UTIL = {
	fire : function(func,funcname, args){
		var namespace = SIXMS;
		
		funcname = (funcname === undefined) ? 'init' : funcname;
		if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
			namespace[func][funcname](args);
		}
	},
	loadEvents : function() {
		var bodyId = document.body.id;
		
		// Fire common scripts first.
		UTIL.fire('common');
		
		// Fire scripts based on body class and id.
		$.each(document.body.className.split(/\s+/),function(i,classnm){
			UTIL.fire(classnm);
			UTIL.fire(classnm,bodyId);
		});
		
		// Fire low priority scripts last.
		UTIL.fire('common','finalize');
	}
};

$(function() { UTIL.loadEvents() });

// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

// catch all document.write() calls
(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);

