// http://paulirish.com/2009/markup-based-unobtrusive-comprehensive-dom-ready-execution/
var KAA = KAA || {};
KAA = {
    common : {
        init : function() {
            // Common scripts here
            getTwitters('latest-tweet', { 
              id: 'healthx', 
              count: 1, 
              enableLinks: true, 
              ignoreReplies: true, 
              clearContents: true,
              template: '<h2><a href="http://twitter.com/%user_screen_name%">%time%</a></h2><p>%text%</p>'
            });
            $("input.phone").mask("(999) 999-9999");
            $("#content").css({"opacity" : "1"});
            $("#subnav").css({"opacity" : "1"});
            $(".hx-rep h3").click(function () {
            	$(this).addClass("rep-form-active");
            	$(this).next("form").slideDown();	
            });
            // No input placeholders in IE. Show labels.
            if ( $.browser.msie ) {
            	$("label").css("display", "block");
            	$("#footer .newsletter form label").css("display", "block");
            } else {
            }
            if ( $.browser.mozilla ) {
            	$("label").css("display", "block");
            	$("#footer .newsletter form label").css("display", "block");
            } else {}},
        finalize : function() {}},
    home : {
    	init : function() {    		
			$("#questions ul li").hover(
				function () {
					if ( $.browser.msie && $.browser.version < 9 ) {
						// If IE
						$("#questions ul li").css({"background-color" : "#F9F9F9", "color" : "#B3B4B6"});
						$("#questions ul li h2 a").css("color", "#B3B4B6");
						$(this).css({"background-color" : "#FFF", "color" : "#2C3034", "height" : "auto"});
						$(this).children("h2").children("a").css("color", "#2C3034");
						$(this).children("p").css("visibility", "visible");
						$(this).children("h3").css("visibility", "visible");
					} else {
						$("#questions ul li").css("opacity",".33");
						$("#questions ul li:hover").css({"height" : $(this).children("h2").height() + $(this).children("p").height() + $(this).children("h3").height(), "opacity" : "1"});
						$(this).children("p").css("opacity","1");
					}
			    },
			    function () {
			    	if ( $.browser.msie && $.browser.version < 9 ) {
			    		// If IE
			    		$("#questions ul li").css({"background-color" : "#FFF", "color" : "#2C3034"});
			    		$("#questions ul li h2 a").css("color", "#2C3034");
			    		$(this).css("height","118px");
			    		$(this).children("p").css("visibility", "hidden");
			    		$(this).children("h3").css("visibility", "hidden");
			    	} else {
			      		$(this).children("p").css("opacity","0");
					$(this).css("height","118px");
			      		$("#questions ul li").css("opacity","1");
			      	}
			    }
			);
    	}
    },
    team : {
        init : function() {
            var top, y;
            if($('#team-nav').length) {
                top = $('#team-nav').offset().top - parseFloat($('#team-nav').css('marginTop').replace(/auto/, 0));
                $(window).scroll(function (event) {
                    y = $(this).scrollTop();
                    if(y >= top) {$('#team-nav').addClass('fixed');} else {$('#team-nav').removeClass('fixed');}
                });
            }
        }
    }, 
    contact : {
    	init : function() {
    		$('.show-map').click(function() {
    			$(this).css({"display" : "none"});
    			$('.hide-map').css({"display" : "block"});
   				$("#map-slider").css({"left" : "-575px"});
   			});
   			$('.hide-map').click(function() {
   				$(this).css({"display" : "none"});
   				$('.show-map').css({"display" : "block"});
   				$("#map-slider").css({"left" : "0"});
   			});					
    	}
    },
    products : {
    	init : function() {
    		$("#products-table ul li a.nav").hover(
    			function () {
    				$("#products-table ul li a.nav").css({
    					"background" : "transparent",
    					"border-top-color" : "#434343",
    					"border-bottom-color" : "#373737"
    				});
    				$("#products-table ul li a.nav").next("ul").css({
    					"opacity" : "0",
    					"z-index" : "1"
    				});
    				$(this).css({
    					"background" : "#303030",
    					"border-top-color" : "#292929",
    					"border-bottom-color" : "#303030"
    				});
    				$(this).next("ul").css({
    					"opacity" : "1",
    					"z-index" : "2"
    				});
    			}, function () {
    			}
    		);		
    	}
    },
    question : {
    	init : function() {
    		// Increase Font Size
    		$(".text-large").click(function(){
    		  var currentFontSize = $('#answer').css('font-size');
    		  var currentFontSizeNum = parseFloat(currentFontSize, 10);
    		  var newFontSize = currentFontSizeNum*1.2;
    		  $('#answer').css('font-size', newFontSize);
    		  return false;
    		});
    		// Decrease Font Size
    		$(".text-small").click(function(){
    		  var currentFontSize = $('#answer').css('font-size');
    		  var currentFontSizeNum = parseFloat(currentFontSize, 10);
    		  var newFontSize = currentFontSizeNum*0.8;
    		  $('#answer').css('font-size', newFontSize);
    		  return false;
    		});
    		// Print
    		$('.text-print').click(function() {
    		  window.print();
    		  return false;
    		});
    	}
    }
};

UTIL = {
    fire : function(func,funcname, args){
        var namespace = KAA;
        
        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()});

window.log = function(){
  log.history = log.history || [];   
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};
(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);
