
/* 
 * Auto Expanding Text Area (1.02)
 * by Chrys Bader (www.chrysbader.com)
 * chrysb@gmail.com
 *
 * Special thanks to:
 * Jake Chapa - jake@hybridstudio.com
 * John Resig - jeresig@gmail.com
 *
 * Copyright (c) 2008 Chrys Bader (www.chrysbader.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses. 
 *
 *
 * NOTE: This script requires jQuery to work.  Download jQuery at www.jquery.com
 *
 */
 
(function($) {
		  
	var self = null;
 
	$.fn.autogrow = function(o)
	{	
		return this.each(function() {
			new $.autogrow(this, o);
		});
	};
	

    /**
     * The autogrow object.
     *
     * @constructor
     * @name $.autogrow
     * @param Object e The textarea to create the autogrow for.
     * @param Hash o A set of key/value pairs to set as configuration properties.
     * @cat Plugins/autogrow
     */
	
	$.autogrow = function (e, o)
	{
		this.dummy			= null;
		this.interval		= null;
		this.line_height	= parseInt($(e).css('line-height'));
		this.min_height		= parseInt($(e).css('min-height'));
		this.options		= o;
		this.textarea		= $(e);
		
		// Only one textarea activated at a time, the one being used
		this.init();
	};
	
	$.autogrow.fn = $.autogrow.prototype = {
        autogrow: '1.1'
    };
	
 	$.autogrow.fn.extend = $.autogrow.extend = $.extend;
	
	$.autogrow.fn.extend({
						 
		init: function() {
			
			self = this;
			
			this.textarea.css({overflow: 'hidden', display: 'block'});
			this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand });	
		},
						 
		startExpand: function() {
			
	
			this.interval = window.setInterval(function() {self.checkExpand()}, 500);
		},
		
		stopExpand: function() {
			clearInterval(this.interval);	
		},
		
		checkExpand: function() {
			
			if (this.dummy == null)
			{
				this.dummy = $('<div></div>');
				this.dummy.css({
												'font-size': 	this.textarea.css('font-size'),
												'font-family': 	this.textarea.css('font-family'),
												'width': 		this.textarea.css('width'),
												'padding': 		this.textarea.css('padding'),
												'line-height':  this.textarea.css('line-height'),
												'overflow-x':   'hidden',
												'display':		'none',
												'position':     'absolute',
												'top':			0,
												'left':			'-9999px'
												}).appendTo('body');
			}
			
			
			var html = this.textarea.val().replace(/\n/g, '<br>new');
			
			if (this.dummy.html() != html)
			{
				this.dummy.html(html);	
				
				if (this.textarea.height() != this.dummy.height() + this.line_height)
				{
					this.textarea.animate({height: (this.dummy.height() + this.line_height) + 'px'}, 100);	
				}
			}
		}
						 
	 });
})(jQuery);


$(function() {
	$("<div id='faux-hover'></div>").hide().prependTo("#logo");
	$("#logo a").bind("mouseenter",
		function(){
			$("#faux-hover").fadeIn("fast");
		}
	)
	$("#logo a").bind("mouseleave",
		function(){
			$("#faux-hover").fadeOut("slow");
		}
	)
});

function fademenu(el){
	if(!$("#nav #"+el).hasClass("active")){
		$("#nav #"+el+" a").clone().removeAttr("id").attr("id",el+"-hover").hide().appendTo("#nav #"+el);
		
		$("#nav #"+el).bind("mouseenter",
			function(){
				$("#"+el+" a:last-child").fadeIn("fast");
			}
		)
		$("#nav #"+el).bind("mouseleave",
			function(){
				$("#"+el+" a:last-child").fadeOut("fast");
			}
		)
	}
};

$(function(){
	$("pre").each(function(){
		var type = this.getAttribute("class");
		$("<span class='code-type'>"+type+"</span>").prependTo(this);
	});
	
	
});


$(function(){
		   // IE6 support :hover
		$("form input.submit").bind("mouseenter",function(){
			$(this).addClass("hover"); // over
		});
		$("form input.submit").bind("mouseleave",function(){
			$(this).removeClass("hover"); // leave
		});

})

// Let's load the fading menu
$(function(){
	$("body").addClass("hasJS");
	fademenu("home");
	fademenu("about");
	fademenu("work");
	fademenu("articles");
	if(!($.browser.version == "6.0" && $.browser.msie)){
		$('textarea').autogrow();
	}
});

var Project = {
	html: "",
	current: 1,
	starthtml: "<ul id=\"pagination\">",
	endhtml: "</ul><div id=\"arrows\">	<span id=\"left\"><a href=\"#\" title=\"Previous project\" onclick=\"projects.previous();return false\">&laquo;</a></span>	<span id=\"right\"><a href=\"#\" title=\"Next project\" onclick=\"projects.next();return false\">&raquo;</a></span></div>",
	initialize: function(projects){
		this.projects = projects
		var html = "";
		var j = projects+1; // j = project to include
		for(var i = 0; i < projects;i++){
			j--;
			if(i == 0){
				html += "<li class=\"active\"><a href=\"#\" onclick=\"projects.switchTo("+(i+1)+");return false\">"+(i+1)+"</a></li>"
			}else{
				html += "<li><a href=\"#\" onclick=\"projects.switchTo("+(i+1)+");return false\">"+(i+1)+"</a></li>"
			}
		}
		this.html = this.starthtml+html+this.endhtml
	},
	switchTo: function(n){
		this.current = n
		$("#portfolio-slide #project-image img").remove();
		$("#portfolio-slide #project-info .info-container").fadeOut().remove();
		$("<img src=\"wp-content/themes/bitsandpixels/images/ajax2.gif\" alt=\"\" class=\"ajax-loader\" />").hide().appendTo("#portfolio-slide #project-image").fadeIn();
		
		this.activateMenu(n);
		$.get("wp-content/themes/bitsandpixels/projects/"+n+".html",{},
			function(data)
			{
				var data = "<div class=\"info-container\">"+data+"</div>";
				$(data).prependTo("#portfolio-slide #project-info").hide().fadeIn();
				sIFR.replace(font, {
					selector: '#wrapper #project-info h2',
					wmode: 'transparent',
					knockout: false,
					css: [
						  '.sIFR-root { font-size: 24px; font-weight: bold; color: #00D8FF; }',
						  'a { color: #00D8FF; text-decoration: none; }',
						  'a:hover { color: #ffffff; }'
							 ],
					ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
				});

			});
		var preload = new Image();
		preload.onload = function(){
			$("#portfolio-slide #project-image img").hide();
			$(preload).hide().appendTo("#portfolio-slide #project-image").fadeIn();
		};
		preload.src = "wp-content/themes/bitsandpixels/images/projects/"+n+".jpg";
			  
		//$("#portfolio-slide #project-image img").fadeOut()
	},
	activateMenu: function(n){
		$("#portfolio-slide #pagination a").each(function(i){
														  
			if($(this).html() == n){
				$(this).parent().addClass("active");
				}else{
				$(this).parent().removeClass("active");
			}
		});
	},
	next: function(){
		if(this.current == this.projects){
		this.current = 1
		}else{
			this.current += 1
		}
		this.switchTo(this.current)
	},
	previous: function(){
		if(this.current == 1)
		{
			this.current = this.projects
		}else{
			this.current -= 1
		}
		this.switchTo(this.current)
	}
};


$(function(){
	projects = Project;
	projects.initialize(3);
	$(projects.html).appendTo($("#portfolio-slide #controls"))
})


/* Here comes the sIFR goodness */

var font = {
  src: 'http://bitsamppixels.com/wp-content/themes/bitsandpixels/flash/sifr.swf',
  highsrc: 'http://bitsamppixels.com/wp-content/themes/bitsandpixels/flash/sifr.swf'
};
sIFR.prefetch(font);
sIFR.compactMode = true;

sIFR.activate(font);

sIFR.replace(font, {
	selector: '#wrapper #project-info h2',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 24px; font-weight: bold; color: #00D8FF; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
	ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});


sIFR.replace(font, {
	selector: '#wrapper .column-1 h2',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 30px; font-weight: bold; color: #00D8FF; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
	ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});

sIFR.replace(font, {
	selector: '#wrapper #top-column h1',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 30px; font-weight: bold; color: #EC008C; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
		ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});

sIFR.replace(font, {
	selector: '#wrapper .column-1 .post h1',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 30px; font-weight: bold; color: #EC008C; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
		ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});

sIFR.replace(font, {
	selector: '#wrapper .column-1 h1',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 24px; font-weight: bold; color: #EC008C; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
		ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});

sIFR.replace(font, {
	selector: '#wrapper .column-2 h3',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 20px; font-weight: bold; color: #EC008C; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
	ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});

sIFR.replace(font, {
	selector: '#wrapper .column-1 h3',
	wmode: 'transparent',
	knockout: false,
	css: [
		  '.sIFR-root { font-size: 20px; font-weight: bold; color: #00D8FF; }',
		  'a { color: #00D8FF; text-decoration: none; }',
		  'a:hover { color: #ffffff; }'
			 ],
	ratios: [6,1.41,9,1.35,15,1.29,21,1.25,23,1.22,28,1.23,34,1.22,41,1.21,53,1.2,54,1.19,58,1.2,96,1.19,98,1.18,100,1.19,104,1.18,105,1.19,109,1.18,110,1.19,1.18]
});