// Delay Plugin for jQuery
// - http://www.evanbot.com
// - © 2008 Evan Byrne

jQuery.fn.delay = function(time,func){
	return this.each(function(){
		setTimeout(func,time);
	});
};
//*****Replace target attribute with class**************************************************//
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}
//*****The following function make it possible to have web standard popups**************************************************//
function strictNewWindow() {
  if (!document.getElementsByTagName('a')) return false;
  $('a.newwindow').click(function() {
		window.open($(this).attr('href'));
    return false;
	});
}
//*****Add swfobject flash call**************************************************//
function initializeFlash() {
	if (!document.getElementById('flash-header')) return false;
	var flashvars = {};
	var params = {wmode: 'transparent'};
	var attributes = {};
	attributes.id = "flash";
	swfobject.embedSWF("/wp-content/themes/cranedurham/swf/loader.swf", "noFlash", "294", "119", "8.0.0", "/wp-content/themes/cranedurham/swf/expressInstall.swf", flashvars, params, attributes);
}
//*****Extend the sidebar**************************************************//
function extendSidebar() {
  var mainHeight = $('#main').height() - 49;
  var sidebarHeight = $('#sidebar').height();
  if (sidebarHeight < mainHeight) {
    $('#sidebar').height(mainHeight);
  } else {
    $('#contentContainer').height(sidebarHeight - 20);
  }
}
//*****Load all functions**************************************************//
$(document).ready(function(){
  replaceTarget();
  strictNewWindow();
  initializeFlash();
  $(this).delay(500,function(){
    extendSidebar();
  });
});
$('#main').bind('change',extendSidebar);