(function($)
 {


$(function() {

	$.browser.msie6 = !!($.browser.msie && typeof document.documentElement.style.maxHeight == 'undefined');

	// various fixes for IE < 7
	if ($.browser.msie6) {

		// transparent png support

		var base;

		if ((base = $('head>base')).length) {

			base = base.attr('href');

		} else {

			base = '';
		}

		// apply AlphaImageLoader filter
		$('img[src$=".trans.png"],#logo img').each(function() {

			var self = $(this), src = self.attr('src');

			if (src.substr(0, 1) != '/') {

				src = base + src;
			}

			self
				.attr('src', 'themes/skystorm/images/blank.gif')

				.css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')");
		});

		// replace with gif
		$('img[src$=".gif.png"]').each(function() {

			var self = $(this);

			self.attr('src', self.attr('src').replace(/\.png$/, ''));
		});


		// :last-child pseudo-class for some elements

		$('li:last-child,#page-content .article:last-child,#services .row .service:last-child,#study-content .study:last-child').each(function() {

			$(this).addClass('ie-last-child');
		});
	}


	// search box alternative text

	var search_alt = $('#search label').text() + '...';

	$('#search input')

		.val(search_alt)

		.focus(function() {

			if ($(this).val() == search_alt) {

				$(this).val('');
			}
		})

		.blur(function() {

			if (!$(this).val().length) {

				$(this).val(search_alt);
			}
		});



	// shadow

	setTimeout(function(){

		var left_col = $('#left-col'),
			right_col = $('#right-col');

		if (left_col.length + right_col.length == 2) {

			$(window).resize(function() {

				$('body').css('overflow-x', $(window).width() < 980 ? 'visible' : 'hidden');
			});

			var shadow = $('#content .shadow'),
				right_col_height = right_col.height();

			if (left_col.height() < right_col_height) {

				var height, page_content = $('#page-content');

				left_col.height(right_col_height);

				page_content.height(height = right_col_height - 28 - page_content.is('.small') * 267);

				if (page_content.is('.study-full')) {

					page_content.find('#study-content').height(height - 429);

				} else if (page_content.is('.study-featured')) {

					page_content.find('#study-content').height(height - 313);
				}

				if ($.browser.msie && !$.browser.msie6) {

					$('#page-content,#contact-form').css('top', '10px');
				}

			} else {

				left_col.find('>.border>.br').show();
			}

			shadow.height(right_col_height - 129).css('visibility', 'visible');
		}

	}, 50);

	// contact page textarea alttext
	var textarea = $('#contact-form textarea'), first_load = true;

	if (textarea.length == 1) {

		textarea

		.focus(function() {

			if ($(this).is('.empty')) {

				textarea.val('').removeClass('empty');
			}
		})

		.blur(function() {

			var text = 'Content of your email here.';

			if ($(this).val().length == 0 || (first_load && $(this).val() == text)) {

				textarea.val(text).addClass('empty');
			}

			first_load = false;
		})

		.blur();
	}


	// form validation
	if ($.fn.validator) {

		$('.binput[rel]').each(function() {

			var self = $(this);

			self.parent().find('input,textarea').addClass(self.attr('rel'));

		});

		$('form').validator();
	}
});

})(jQuery.noConflict());

