

document.write("<style type='text/css'>");
document.write("#current-investment");
document.write("{");
document.write("display: none;");
document.write("}");
document.write("</style>");
function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}

function jqPngFix() {
    try {
        //ie6 png transperency fix
        $.each($("img[src$=.png],img[src$=.PNG]"), function () {
            var img = $(this);
            img.css({"width": img.width(),"height": img.height(), "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.attr("src") + "', sizingMethod='scale')"});
            img.attr("src","../images/construct/blank.gif");
        });
    } catch(e) {
        alert(e.description)
    }
}
$(document).ready(function(){
	if ($.browser.msie && $.browser.version == '6.0') {
		jqPngFix();
	}
	$('#sitesearch input[type="text"]').fadeTo('fast',0.8);
	$('#sitesearch label').hide();
	$('#sitesearch input[type="text"]').each(function() {
		$(this).attr('value',$(this).prev().html());
	});
	$('#sitesearch input[type="text"]').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
			if ($(this).attr("value") == $(this).prev().html()) {
				$(this).attr("value","");
			}
		},
		blur: function() {
			$(this).fadeTo('fast',0.8);
			if (!$(this).attr("value")) {
				$(this).attr("value",$(this).prev().html());
			}
		}
	});
	
	
	$('.formRow input[type="text"], .formRow textarea').fadeTo('fast',0.5);
	$('.formRow input[type="text"], .formRow textarea').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
		}
	});
	$('#signUpEbull input[type="submit"]').each(function() {
		$(this).replaceWith('<p class="cta ebull-submit"><a href="#">'+$(this).attr('value')+'</a></p>');
	});
	$('p.cta.ebull-submit a').click(function() {
		
					//$(this).parents('form').submit();
		
		// First, disable the form from submitting
			$(this).parents('form').submit(function() { return false; });
			
			// Grab form action
			formAction = $(this).parents('form').attr("action");
			
			// Hack together id for email field
			emailId = formAction.replace("http://ebull.dusteddesign.com/t/r/s/", "");
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;

			emailChk = true;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				
				$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
				$("#confirmation").addClass("panel");
				$("#confirmation").html("Please enter a valid email address");
				return false;
			}
			
			// Serialize form values to be submitted with POST
			var str = $(this).parents('form').serialize();
	
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			// Submit the form via ajax
			$.ajax({
				url: "http://www.yfm.co.uk/proxy.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
					$("#confirmation").addClass("panel");
					$("#confirmation").html("Thanks for subscribing");
				}
			});
			return false;
	});
	
	$('input[type="submit"]').each(function() {
		$(this).replaceWith('<p class="cta submit"><a href="#">'+$(this).attr('value')+'</a></p>');
	});
	$('p.cta.submit a').click(function() {
		$(this).parents('form').submit();
		return false;
	});
	$('.tabbed').addClass('jsActive').wrapInner('<div class="tabWrap">');
	$(".tabbed").prepend('<ul class="tabs"></ul>');
	$('.tabbed h2').each(function() {
		$(this).parents('.tabbed').children('.tabs').append('<li>'+$(this).html()+'</li>');
	});
	$('.tabbed h2').remove();
	$('.tabs li:nth-child(1)').addClass('selected');
	$('.tabWrap').each(function() {
		$(this).children('.panel:gt(0)').hide();
	});
	
	$('.tabs li').click(function() {
		$(this).siblings('li').removeClass('selected');
		$(this).addClass('selected');
		$whatPanel = $(this).index();
		$(this).parents('ul').siblings('.tabWrap').children('.panel').hide();
		$(this).parents('ul').siblings('.tabWrap').children('.panel:eq('+$whatPanel+')').show();
		if(typeof mapPan == 'function') {
			mapPan(PanArray[$(this).index()]);
			if ($(this).index() == 0) {
				mapLDN.setZoom(14);
			}
		}
	});
	$('.standfirst p:first, .standfirst .panel p:first-child').addClass('standfirst');
	
	
	
	// INFOPANELS
	
    //$(".investmentTable").tablesorter( {sortList: [[0,0]]} ); 
	
	$('.infoPanel').css({ display: "none" });
	$('.investmentTable tbody tr').addClass('toggler');
	$('.investmentTable tbody tr').after('<tr class="extraInfo"><td class="investmentInfo" colspan="4"></td></tr>');
	$('.investmentInfo').hide();
	$('.investmentInfo').css({ padding: "0" });
	$('.infoPanel h2').css({ display: "none" });
	$('.investmentTable tbody tr td').wrapInner('<span>');
	
	$('.investmentTable tbody tr th a').each(function() {
		$whatHTML = $(this).html();
		$whatLink = $(this).attr('href');
		$whatLinkArray = $whatLink.split('#');
		$whatLink = $whatLinkArray[1];
		$(this).parents('tr').next().children('.investmentInfo').append($('#'+$whatLink));
		$(this).parents('tr').next().children('.investmentInfo').addClass($whatLink);
		$(this).replaceWith('<span>'+$whatHTML+'</span>');
	});
	
	
	$('.investmentTable tbody tr.toggler').click(function() {
		if ($(this).attr('class').indexOf('revealed') == -1) {
			
			//HIDE OPEN PANEL
			$('.revealed').next('tr').children('.investmentInfo').children('.infoPanel').slideUp(1000, function() {
				$(this).parents('.investmentInfo').hide();
				$(this).parents('tr').prev('tr').removeClass('revealed');
				$(this).parents('tr').prev('tr').children('td').children('span').fadeIn();
			});
			
			$(this).addClass('revealed');
			$(this).children('td').children('span').fadeOut();
			$(this).next('tr').children('.investmentInfo').show();
			$(this).next('tr').children('.investmentInfo').children('.infoPanel').slideDown(1000);
		} else {
			$(this).removeClass('revealed');
			$(this).children('td').children('span').fadeIn();
			$(this).next('tr').children('.investmentInfo').children('.infoPanel').slideUp(1000, function() {
				$(this).parents('.investmentInfo').hide();
			});
		}
	});
	
	$('.investmentTable tbody tr').hover(function() {
		$(this).addClass('hovered');
	}, function() {
		$(this).removeClass('hovered');
	});
	
	$('#current-investment').css({display:"block"});
	
	// PEOPLEPANELS
	$('.peoplePanel').wrapInner('<div class="panelWrap">');
	$('.panelWrap p').hide();
	$('.panelWrap').append('<img src="/assets/images/construct/people_arrow.gif" width="27" height="14" alt="" class="arrow" />');
	
	$('.panelWrap')
	.hover(function() {
		$(this).addClass('hovered');
		$(this).children('p').show();
	}, function() {
		$(this).removeClass('hovered');
		$(this).children('p').hide();
	})
	.click(function() {
		window.location.href = "/"+$(this).children('h2').children('a').attr('href');
	});
	
});