﻿$(document).ready(function()
{
	// **** remove basic styling ****
	if($('link[href]').length)
	{
		$('link[href$="/styles.css"]').remove();
	}
	$('*[style]').removeAttr("style");
	$('*[align]').removeAttr("align");
	$('*[valign]').removeAttr("valign");
	$('*[width]').removeAttr("width");
	$('*[height]').removeAttr("height");
	// make tables all nice and uniform
	$('table').attr("width","100%");
	$('table').attr("cellspacing","0");
	$('table').attr("cellpadding","0");
	$('table').attr("valign","top");
	// **** front gate bar ****
	if ($('table.topnav').length)
	{
		// lines break when i say they do
		$('table.topnav br').replaceWith(' ');
		// get old nav content
		var topNav = $('table.topnav td.topnav table tr').html();
		// create new front gate bar and put old nav content inside it
		$('body').prepend('<div id="fgtBar"><div class="inner"><a href="http://frontgatetickets.com/" target="_blank"><img src="//fgt-static.s3.amazonaws.com/label_935/images/fgt-logo.png" /></a><div id="nav">'+topNav+'</div></div></div>');
		// remove the old nav
		$('table.topnav').remove();
	}
	// **** main attraction ****
	if ($('#fgtBar').length)
	{
		$('body').append('<div id="master"></div>');
		$('body').attr("class","custom");
		$('html').attr("class","custom");
	}
	// **** sidebar ****
	if ($('table.main table.nav').length)
	{
		// create sidebar
		$('#master').prepend('<div id="sidebar"></div>');
		// fill it up with all the existing sidebar sections
		$('table.nav th').wrap('<h2 />');
		$('table.nav').each(function()
		{
			$('#sidebar').append('<div class="section" id="' + $("th", this).text() + '">' + $(this).html() + '</div>');
		});
		// kthxbye
		$('table.main table.nav').remove();
	}
	// **** calendar ****
	if ($('table.calendar').length)
	{
		// create container
		$('table.calendar').wrap('<div class="section" id="calendar" />');
		// throw it in the sidebar
		$('#calendar').prependTo('#sidebar');
	}
	// **** search ****
	if ($('#SEARCH').length)
	{
		$('#SEARCH').wrapInner('<form action="/search.php" method="POST" />');
	}
	// **** on sale soon ****
	if ($("th:contains('ON SALE SOON')").length)
	{
		// this thing totally breaks the page if we don't account for it
		$("table:contains('ON SALE NOW')").css("width","440px");
		$("table:contains('ON SALE NOW')").css("margin-right","16px");
		$("table:contains('ON SALE SOON')").css("width","208px");
	}
	// **** content container ****
	if ($('table.main').length)
	{
		// remove extra line breaks
		$('br').remove();
		// make buy buttons awesome
		$("a:contains('Buy Now >>')").wrap('<span class="buynow" />');
		// get rid of those rediculous '>>' things
		$("span.buynow a").html('Buy Now');
		// grab old content
		var mainContent = $('table.main').html();
		// create container and put old content inside it
		$('#master').append('<div id="content">'+mainContent+'</div>');
		// remove the old content
		$('table.main').remove();
	}
	// **** awesomebox ****
	if ($('#master').length)
	{
		// make the cool logo/whatever area to replace that no-fun table thing
		$('body').prepend('<div id="awesomebox"><a class="logo" href="http://highergroundmusic.com/"></a><div class="info">1214 WILLISTON RD.<br />SO. BURLINGTON, VT 05403 <a href="http://maps.google.com/?q=1214+Williston+Rd+Burlington+VT+05403&output=embed&iframe=true">[MAP]</a><br />PHONE 802-652-0777<br />TICKETS 888-512-7469<br /><a href="mailto:info@highergroundmusic.com">INFO@HIGHERGROUNDMUSIC.COM</a></div></div>');
	}
	// **** timer ****
	if ($('table.order').length)
	{
		// get the stuff
		var orderContent = $('table.order').html();
		// put it in the sidebar
		$('#master').prepend('<div class="section" id="timer"><div id="orderTimer">' + orderContent + '</div></div>');
		// boot the old thing
		$('table.order').remove();
		// wait... this should already have happened in the inital prepend -- ######## FIX ME ########
		$('#timer').prependTo('#sidebar');
	}
	// **** billing page ****
	if ($('form[action*="checkout.php"]').length)
	{
		// the checkout form is getting mangled -- this line to the rescue
		$('#content').wrap('<form name="order" action="/secure/checkout.php" method="POST" />');
	}
	// **** processing page ****
	if ($("th:contains('PROCESSING...')").length)
	{
		$('th').wrapInner('<h2 />');
		$('table.bigForm').attr("id","processingBigForm");
		$('body').attr("class","custom");
		$('html').attr("class","custom");
	}
	// **** new footer ****
	if ($('table.browse').length)
	{
		// kick the old one out
		$('table.browse').remove();
		// create new
		$('body').append('<div id="footer"><a class="logo" href="http://frontgatetickets.com/" target="_blank"><img src="//fgt-static.s3.amazonaws.com/label_935/images/fgt-logo.png" /></a><div id="copyright">©2011 FRONT GATE SOLUTIONS, INC.<br />ALL RIGHTS RESERVED.</div><div class="right"><a id="sell" href="http://www.frontgatetickets.com/support/sell/" target="_blank">SELL TICKETS<br />WITH <span>US</span></a><a id="verisign" href="https://seal.verisign.com/splash?form_file=fdf/splash.fdf&amp;lang=en&amp;dn=secure.independenttickets.com" target="_blank"><img src="//fgt-static.s3.amazonaws.com/common/vsseal.gif" height="36"></a></div></footer>');
	}

	// **** misc. ****
	// make radio buttons not break lines
	$('input[type="radio"]').attr("style","display:inline;");
	// make that darn Larger Image link quit floating out in space
	$('a:contains("View Larger Image")').attr("style","display:block;margin-bottom:16px;");
	// size the title cool-ly
	$('td:has(span.title)').attr("style","width:100%;");
	// spacing issue
	$('a:contains("[Read more]")').attr('style','display:block;margin-bottom:16px;');
	// make the sold out thing not be cast thoughtlessly onto the page
	$('p:contains("Sold out!")').attr('class','soldOut');
});

