/*----------------------------------------------------------------------------*/
/* Geneal HTML changes */

$(function () {
	//open doc or external links in new window
	$(
		'a[href^="http://"],' +
		'a[href^="https://"],' +
		'a[href*="class=link&link=http://"],' +
		'a[href*="class=link&link=https://"],' +
		'a[href$=".pdf"],' +
		'a[rel="external"]'
	).attr("target", "_blank");

	$('body').addClass('jsEnabled');
	$('.column').each(function () { if (jQuery('.column', this).length == 0) { jQuery(this).wrapInner('<div class="colPad"></div>'); } });
	$('.row').after('<br class="clear />');

	$('blockquote').wrap('<div class="quote"></div>');
	$('#introButton').wrap('<div class="introButtonWrap"></div>');
	$('#homeIntro .button').wrap('<div class="shade"></div>');

	$('.eventslist').before('<hr class="plusRight" />');
	$('.eventslist li').append('<br class="clear" /><hr class="plusRight" />');
	$('#homeFour .column').addClass('homeFourHover');
	$('#homeFour .column').click(function () {
		window.location = $(this).find("h3 a").attr("href"); return false;
	});
	$('#landingThree .col30').addClass('landingThreeHover');
	$('#landingThree .col30').click(function () {
		window.location = $(this).find("h3 a").attr("href"); return false;
	});
	$('.blockList li').addClass('blockListHover');
	$('.blockList li').click(function () {
		window.location = $(this).find("h4").attr("href"); return false;
	});

	$('img.overhang').removeClass('overhang').wrap('<div class="overhang"></div>');
	$('img.shadow, .editor img, .overhang img').each(function () {
		$(this).wrap('<div class="shade"><div class="imageReplace"><div class="imgTL"><div class="imgTR"><div class="imgBR"><div class="imgBL" style="position: relative;"></div></div></div></div></div></div>');
		$(this).css("opacity", "0");
		$(this).after('<br class="clear"/>');
	});

	$('img.shadow, .editor img, .overhang img').each(function () {
		var image = $(this).attr("src");
		$(this).closest('.imageReplace').css({ 'background-image': 'url(\'' + image + '\')' });
	});
	$('#siteTools .searchField').focus(function () {
		if ($(this).data('default') == null)
			$(this).data('default', $(this).val());
		if ($(this).data('default') == $(this).val())
			$(this).val('');
	}).blur(function () {
		if ($(this).val() == '')
			$(this).val($(this).data('default'));
	});
});

/*
 * Changes dependent on all content having loaded first. (eg. ie image fixes)
 */

$(window).load(function () {
	//apply captions for images
	$('.editor img[title]').each(function () {
		$(this).removeAttr("width").removeAttr("height").css({ width: "", height: "" });
		var pic_real_height = this.height;
		$(this).after('<div class="captionText" style="top: ' + pic_real_height + 'px;">' + $(this).attr('title') + '</div>');
	});

	jQuery.each(jQuery.browser, function (i) {
		if ($.browser.msie) {
			$('img.shadow, .editor img, .overhang img').each(function () {
				$(this).removeAttr("width").removeAttr("height").css({ width: "", height: "" });
				var pic_real_width = this.width;
				var pic_real_height = this.height;
				$(this).parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
				$(this).parent().parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
				$(this).parent().parent().parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
				$(this).parent().parent().parent().parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
				$(this).parent().parent().parent().parent().parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
			});
		} else {
			$('img.shadow, .editor img, .overhang img').load(function () {
				$(this).removeAttr("width").removeAttr("height").css({ width: "", height: "" });
				var pic_real_width = this.width;
				var pic_real_height = this.height;
				$(this).parent().parent().parent().parent().parent().css({ 'width': '' + pic_real_width + 'px', 'height': '' + pic_real_height + 'px' });
			});
		}
	});
});


/*
 * IE7 rounded corners
*/
$(window).load(function () {
	if ($.browser.msie && $.browser.version.substr(0,1)<9) {
		$('#siteTools, #navigation, #homeIntro, .blockList li, .subNav, #homeIntro .button, .quote').each(function () {
			$(this).append('<div class="ie7cornerTL"></div><div class="ie7cornerTR"></div><div class="ie7cornerBR"></div><div class="ie7cornerBL"></div>');
			$(this).css("position", "relative");
		});
	}
});

