cookieName = "innovacorp_font_size";

function changeSheets(whichSheet) {

	// Set styleName.
	styleName = "font_size_" + whichSheet;
	
	// Set cookie.
	if(whichSheet !=0 && $.cookie(cookieName) != whichSheet){
		// Save whichSheet within a cookie.
		$.cookie(cookieName, whichSheet, { path: '/', expires: 10 });
	} else if(whichSheet == 0 && $.cookie(cookieName) != null){
		// Delte cookie if using default stylesheet.
		$.cookie(cookieName, null, { path: '/' });
	}
	
	// Enable/disable stylesheets.
	$("style").each(function(){
		if (this.getAttribute('title') == 'font_size_1' || this.getAttribute('title') == 'font_size_2') this.disabled = true;
		if (this.getAttribute('title') == styleName) this.disabled = false;
	});
}

var ify = function() {
  return {
    "link": function(t) {
      return t.replace(/(^|\s+)(https*\:\/\/\S+[^\.\s+])/g, function(m, m1, link) {
        return m1 + '<a href=' + link + '>' + ((link.length > 25) ? link.substr(0, 24) + '...' : link) + '</a>';
      });
    },
    "at": function(t) {
      return t.replace(/(^|\s+)\@([a-zA-Z0-9_]{1,15})/g, function(m, m1, m2) {
        return m1 + '@<a href="http://twitter.com/' + m2 + '">' + m2 + '</a>';
      });
    },
    "hash": function(t) {
      return t.replace(/(^|\s+)\#([a-zA-Z0-9_]+)/g, function(m, m1, m2) {
        return m1 + '#<a href="http://search.twitter.com/search?q=%23' + m2 + '">' + m2 + '</a>';
      });
    },
    "clean": function(tweet) {
      return this.hash(this.at(this.link(tweet)));
    }
  };
}();

$(document).ready(function(){
	// Enable/disable stylesheets when page loads.
	if($.cookie(cookieName) == null){
		$("style").each(function(){
			if (this.getAttribute('title') == 'font_size_1' || this.getAttribute('title') == 'font_size_2') this.disabled = true;
		});
	} else {
		changeSheets($.cookie(cookieName));
	}

	/* Font Toggler Menu */
	var timerId = 0;
	var overFontToggler = false;

	$(".font_toggler").hover(
		function(){
			clearTimeout(timerId);
			$(".font_toggler_menu").animate({width: $(".font_toggler_menu ul").width()}, "slow");
		},
		function(){ 
			timerId = setTimeout ( hideFontTogglerMenu, 1000 );
		}
	);

	$(".font_toggler_menu").hover(
		function(){
			clearTimeout(timerId);
			overFontToggler = true;
		},
		function(){
			overFontToggler = false;
			timerId = setTimeout ( hideFontTogglerMenu, 1000 );
		}
	);

	var hideFontTogglerMenu = function(){ 
		if(!overFontToggler){
			$(".font_toggler_menu").animate({width: 1}, "slow");
		}
	}

});
