$.fn.stripTags = function() { return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') ); };


$(document).ready(function($) {
	
	var videocontent = $("#satevideo").html();
	if (videocontent > "" && videocontent != null) {
		$(".case_studies tbody tr:last").append('<td>' + videocontent + '</td>');
	}

	$.fn.pngFix = function() {
	  if (!$.browser.msie || $.browser.version >= 9) { return $(this); }
	
	  return $(this).each(function() {
	    var img = $(this),
	        src = img.attr('src');
	
	    img.attr('src', 'wp-content/themes/wbi/images/transparent.gif')
	        .css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + src + "')");
	  });
	};
	
	$("#slider ul li img").pngFix();

	$(".case_studies a").each(function() {
		var title = $(this).attr('title');
		var rel = $(this).attr('rel');
		$(this).attr('rel', title);
		$(this).attr('title', title.stripTags().substring(0, 90) + "...");
	});

	$(".dialog").click(function() {
		$("#dialog").dialog({
			width: 433,
			modal: true
		});
	});

	$("#leftnav li").click(function() {
		var url = $(this).find('a').attr('href');
		window.location = url;
	});
	
	$('.gfield_description').each(function(i,e){
		fielddesc = jQuery('<div>').append(jQuery(e).clone()).remove().html();
		$(e).siblings('label.gfield_label').after(fielddesc);
		$(e).remove();
	});
	
	if ($.browser.mozilla) {
		$("#nav ul li.last a").css('padding-right', '48px');
	}
	
	if ($.browser.msie && $.browser.version >= 9) {
		$("#nav ul li.last a").css('padding-right', '48px');
	}

	$("#nav ul li").hover(
		function() {
		var width = $(this).width();
		
		$(this).children("ul").fadeIn('fast');
		$(this).children("ul").css('min-width', width);
		},
		function() {
			$(this).children("ul").fadeOut('fast');
		}
	);
	
	$("#nav ul li.first").hover(
		function() {
			$(this).css('border-top-left-radius', '13px');
		},
		function() {
		}
	);
	
	$("#nav ul li.last").hover(function() {
		$(this).css('border-top-right-radius', '13px');
		$(this).css('border-bottom-right-radius', '13px');
	});
	
	$("#workwith .learnmore").hover(
		function() {
			$(this).parent().children('h5').css('color', '#193d4f');
		},
		function() {
			$(this).parent().children('h5').css('color', '#478eb8');
		}
	);
	
	$("#slider-prev").click(function() {
		$(".prev a").click();
	});
	
	$("#slider-next").click(function() {
		$(".next a").click();
	});
	
	$('#mini-contact form').jqTransform({imgPath:'/js/jqtransform/img/'});
	$('#gform_1').jqTransform({imgPath:'/js/jqtransform/img/'});
	
	$('#bigform form').jqTransform({imgPath:'/js/jqtransform/bigform/img/'});
	$('#gform_3').jqTransform({imgPath:'/js/jqtransform/bigform/img/'});
	
	$("form input").each(function() {
		if (!$(this).hasClass('datepicker')) {
			$(this).attr('onfocus', 'if(this.value==this.defaultValue) this.value="";');
			$(this).attr('onblur', 'if(this.value=="") this.value=this.defaultValue;');
		}
	});
	
	$("form textarea").each(function() {
		$(this).attr('onfocus', 'if(this.value==this.defaultValue) this.value="";');
		$(this).attr('onblur', 'if(this.value=="") this.value=this.defaultValue;');
	});
	
	$("#team .member .thing").each(function() {
		var thing_height = $(this).children(".short").height();
		var computed_top = 162 - thing_height;
		$(this).css('top', computed_top);
	});
	
	$("#team .member").hover(
		function() {
			$(this).children('.thing').animate({
				top: 0
			}, 400, function() {
				// Animation complete.
			});
		},
		function() {
			var thing_height = $(this).children('.thing').children(".short").height();
			var computed_top = 162 - thing_height;
			$(this).children('.thing').animate({
				top: computed_top
			}, 400, function() {
				// Animation complete.
			});
		}
	);
	
	$("#bigform #city").next("div").css('margin', '7px 9px 4px 0px');
	
	$(".case_studies a").lightBox();
	
	$(".case_studies tr").each(function() {
		var tallest = 0;
		$(this).find(".lightbox-title").each(function() {
			if($(this).height() > tallest) tallest = $(this).height();
		});
		$(this).find(".lightbox-title").css("height", tallest + "px");
	});
	
	
});

window.onload = function() {
var settings = {
  tl: { radius: 13 },
  tr: { radius: 13 },
  bl: { radius: 13 },
  br: { radius: 13 },
  antiAlias: true
}

// or, equivalently:
curvyCorners(settings, '#nav ul li.first:hover');
}
