Array.prototype.shuffle = function() {
	o = this;
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};


/**
 * External Links
 */
$(document).ready(function(){
	$('a[rel="external"]').attr('target', '_blank').removeAttr('rel');
	$('a[rel="_blank"]').attr('target', '_blank').removeAttr('rel');
});

/**
 * Printable Link
 */
$(document).ready(function(){
	return;
	$('#sidebar').append('<li id="printable"><h4>Print this Page</h4><ul class="widget-links"><li><a href="#">Printable Version &gt;</a></li></ul></li>');	
	$('#sidebar #printable').bind('click', function(e){
		$('link[media="print"]').each(function(){
			$(this).attr('media', 'all');
		});
	});
});

/**
 * Our Studios
 */
$(document).ready(function(){
	if($('body.create.our-studios').length == 0) return;
	$('#building-map').after('<img src="./../style/img/trans.gif" id="building-map-overlay" usemap="#new_Map"/>');
	var offset = $('#building-map').offset();
	$('#building-map-overlay').css('top', offset.top+'px');
	$('#building-map-overlay').css('left', offset.left+'px');
	$('area').hover(
		function(){ $('#'+$(this).attr('id').replace(/^map/, 'bld')+' img').toggleClass('hover');},
		function(){ $('#'+$(this).attr('id').replace(/^map/, 'bld')+' img').toggleClass('hover');}
	);
	$('#content .pdfs').remove();
});	

/**
 * Dev Process
 */
$(document).ready(function(){
	if($('#dev-process').length == 0) return;	
	$('#dev-process').after('<ul class="tabs-nav clearfix"></ul>');
	var mx = 0;
	$('#dev-process h2').each(function(){
		alt = $(this).text().replace(/\n/, ' ');
		idx = $('#dev-process h2').index(this);
		$('#dev-process').next().append('<li id="btab'+idx+'"><img src="'+HTPATH+'/style/img/dev-process-tab'+idx+'.png" alt="'+alt+'" title="'+alt+'"/></li>');
		$('#dev-process').next().after('<div id="ctab'+idx+'" class="tcontent"></div>');
		$(this).nextAll().each(function(){
			$(this).clone().appendTo('#ctab'+idx);			
		});
		mx = mx > $('#ctab'+idx).height() ? mx : $('#ctab'+idx).height();
	});
	$('.tcontent').css('height', mx);
	$('.tabs-nav li').bind('click', function(e){
		$('.tcontent').hide();
		$('#'+$(this).attr('id').replace(/^b/, 'c')).show();
		$('img', $(this).parent()).each(function(){
			$(this).attr('src', $(this).attr('src').replace(/-selected/, ''));
		});
		$('img', this).removeClass('hovered');
		$('img', this).attr('src', $('img', this).attr('src').replace(/.png/, '-selected.png'));
	});
	
	$('.tabs-nav img').bind('mouseenter', function(e){	
		if($(this).attr('src').match(/-selected.png$/)) return;
		$(this).attr('src', $(this).attr('src').replace(/\.png$/, '-selected.png'));
		$(this).addClass('hovered');
	});	
	$('.tabs-nav img').bind('mouseleave', function(e){	
		if(!$(this).hasClass('hovered')) return;
		$(this).attr('src', $(this).attr('src').replace(/-selected\.png$/, '.png'));
		$(this).removeClass('hovered');
	});	
	$('.tabs-nav li:first').click();	
	$('#dev-process').remove();	
});

/**
 * Navigation (stupid blue glow and idiotic bubbles)
 */
$(document).ready(function(){
	$('#navigation a img').each(function(){
		$(this).closest('li').append('<img class="bubble" src="'+HTPATH+'/style/img/bubble-'+$(this).attr('alt').toLowerCase()+'.png" alt=""/>');
	});
	$('#navigation a').hover(
		function(){
			$(this).closest('li').toggleClass('hover');		
			$('img.bubble', $(this).closest('li')).fadeIn(400);
		},
		function(){
			$(this).closest('li').toggleClass('hover');		
			$('img.bubble', $(this).closest('li')).hide();
		}
	);
});

/**
 * Tab Hovers
 */
$(document).ready(function(){
	$('.tabs li').bind('mouseenter mouseleave', function(e){
		$(this).toggleClass('hover');
	});
	$('.tabs li').bind('click', function(e){
		window.location = $('a', this).attr('href');
	});
	$('.tabs li').css('cursor', 'pointer');
});


/**
 * Banners
 */
$(document).ready(function(){
	b = false;
	switch(true){
		case $('body').hasClass('page-id-13'):
			b = 'create';
			break;
		case $('body').hasClass('page-id-3'):
			b = 'collaborate';
			break;		
		case $('body').hasClass('page-id-11'):
			b = 'connect';
			break;
	}
	if(!b) return;
	$('h1').addClass('annoying');
	$('h1').append('<img id="b-bg"/>').append('<div id="b-ani"></div>').append('<div id="b-ol"></div>').append('<div id="b-fr"></div>');
	$('#b-bg').attr('title', $('h1').text());
	$('#b-bg').attr('alt', $('h1').text());
	$('#b-bg').attr('src', HTPATH+'/style/banners/banner-'+b+'-background.jpg');		
	swfobject.embedSWF(HTPATH+'/style/banners/banner-'+b+'-animated.swf', 
		'b-ani', '735', '146', "9.0.0", HTPATH+'/js/swfobject/expressInstall.swf', 
		false, {menu: "false", wmode: "transparent"}
	);
	swfobject.embedSWF(HTPATH+'/style/banners/banner-'+b+'-overlay.swf', 
		'b-ol', '735', '146', "9.0.0", HTPATH+'/js/swfobject/expressInstall.swf', 
		false, {menu: "false", wmode: "transparent"}
	);	
}); 
$(document).ready(function(){
	if($('body.home').length == 0) return;
	$('#banner-group img.bg').after('<div id="b-ani"></div>').next().after('<div id="b-ol"></div>');
	swfobject.embedSWF(HTPATH+'/style/banners/banner-home-animated.swf', 
		'b-ani', '980', '260', "9.0.0", HTPATH+'/js/swfobject/expressInstall.swf', 
		false, {menu: "false", wmode: "transparent"}
	);
	swfobject.embedSWF(HTPATH+'/style/banners/banner-home-overlay.swf', 
		'b-ol', '980', '260', "9.0.0", HTPATH+'/js/swfobject/expressInstall.swf', 
		false, {menu: "false", wmode: "transparent"}
	);	
});

/**
 * Animated SO Logo
 */
 $(document).ready(function(){
	if($('body.home').length == 0) return;
	swfobject.embedSWF(HTPATH+'/style/swf/logo-main.swf', 'logo', '220', '81', "9.0.0", HTPATH+'/js/swfobject/expressInstall.swf', false, {menu: "false", wmode: "transparent"}	);	
});
/**
 * News Images Lightbox
 */
$(document).ready(function(){
	if($('body').hasClass('archive')) return;
	if($('.news-images a').length == 0) return;
	$('.news-images a').each(function(){
		$(this).parent().append('<div id="id' + $('.news-images a').index(this) + '"><img src="'+$(this).attr('href')+'"/></div>');
		$(this).attr('href', '#id' + $('.news-images a').index(this));
	});
	$('.news-images a').fancyZoom({scaleImg: true, closeOnClick: true});
});

/**
 * IE6
 */
$(document).ready(function(){
	if(!$.browser.msie && !parseFloat($.browser.version) < 7) return;	
	$('body.news #content .post').append('<div class="ieClear"></div>');
}); 




/**
 * Conversion Tracking
 */
$(function(){
	$('a[href="mailto:connect@silveroaks.com"]').click(function(){
		var leadimg = new Image();
		leadimg.src = "http://www.googleadservices.com/pagead/conversion/1071231353/?label=lead&amp;guid=ON&amp;script=0";	
	});
});













(function($){
$.fn.fancyZoom = function(options){

  var options   = options || {};
  var directory = options && options.directory ? options.directory : 'images';
  var zooming   = false;

  if ($('#zoom').length == 0) {
    var html = '<div id="zoom" style="display:none;"><div id="zoom_content"></div></div>';				
    $('body').append(html);
    $('html').click(function(e){if($(e.target).parents('#zoom:visible').length == 0) hide();});


    $('#zoom_close').click(hide);
  }

  var zoom          = $('#zoom');
  var zoom_table    = $('#zoom_table');
  var zoom_close    = $('#zoom_close');
  var zoom_content  = $('#zoom_content');
  var middle_row    = $('td.ml,td.mm,td.mr');

  this.each(function(i) {
    $($(this).attr('href')).hide();
    $(this).click(show);
  });

  return this;

  function show(e) {
    if (zooming) return false;
		zooming         = true;
	var content_div = $($(this).attr('href'));
  	var zoom_width  = options.width;
	var zoom_height = options.height;

	var width       = window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth);
  	var height      = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
  	var x           = window.pageXOffset || (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
  	var y           = window.pageYOffset || (window.document.documentElement.scrollTop || window.document.body.scrollTop);
  	var window_size = {'width':width, 'height':height, 'x':x, 'y':y}

		var width              = (zoom_width || content_div.width()) + 60;
		var height             = (zoom_height || content_div.height()) + 60;
		var d                  = window_size;

		// ensure that newTop is at least 0 so it doesn't hide close button
		var newTop             = Math.max((d.height/2) - (height/2) + y, 0);
		var newLeft            = (d.width/2) - (width/2);
		var curTop             = e.pageY;
		var curLeft            = e.pageX;

		zoom_close.attr('curTop', curTop);
		zoom_close.attr('curLeft', curLeft);
		zoom_close.attr('scaleImg', options.scaleImg ? 'true' : 'false');

    $('#zoom').hide().css({
			position	: 'absolute',
			top				: curTop + 'px',
			left			: curLeft + 'px',
			width     : '1px',
			height    : '1px'
		});

    fixBackgroundsForIE();
    zoom_close.hide();

    if (options.closeOnClick) {
      $('#zoom').click(hide);
    }
	if (options.scaleImg) {
	zoom_content.html(content_div.html());
	$('#zoom_content img').css('width', '100%');
	} else {
	  zoom_content.html('');
	}

    $('#zoom').animate({
      top     : newTop + 'px',
      left    : newLeft + 'px',
      opacity : "show",
      width   : width,
      height  : height
    }, 500, null, function() {
      if (options.scaleImg != true) {
    		zoom_content.html(content_div.html());
  		}
			unfixBackgroundsForIE();
			zoom_close.show();
			zooming = false;
    })
    return false;
  }

  function hide() {
    if (zooming) return false;
		zooming         = true;
	  $('#zoom').unbind('click');
		fixBackgroundsForIE();
		if (zoom_close.attr('scaleImg') != 'true') {
  		zoom_content.html('');
		}
		zoom_close.hide();
		$('#zoom').animate({
      opacity : "hide",
      width   : '1px',
      height  : '1px'
    }, 500, null, function() {
      if (zoom_close.attr('scaleImg') == 'true') {
    		zoom_content.html('');
  		}
      unfixBackgroundsForIE();
			zooming = false;
    });
    return false;
  }

  function switchBackgroundImagesTo(to) {
		
    $('#zoom_table td').each(function(i) {
      var bg = $(this).css('background-image').replace(/\.(png|gif|none)\"\)$/, '.' + to + '")');
      $(this).css('background-image', bg);
    });
  }

  function fixBackgroundsForIE() {
    if ($.browser.msie && parseFloat($.browser.version) >= 7) {
      switchBackgroundImagesTo('gif');
    }
	}

  function unfixBackgroundsForIE() {
    if ($.browser.msie && $.browser.version >= 7) {
      switchBackgroundImagesTo('png');
    }
	}
}
})(jQuery);




















