jQuery(document).ready(function($){
	
	//get some colors from the label settings
	var color1 = $('.q').css('background-color'); //links #25787B
	var color2 = $('.error A').css('color'); //highlight #455138
	var color3 = $('table.main').css('background-color'); // background #9EBE7D
	var color4 = $('body').css('color'); // text #EEFFDF
	var color5 = $('.error').css('color'); //errors-alerts #F00000
	var color6 = $('h1').css('color'); //header #213D21
	var color7 = $('body').css('background-color'); //outer background #090903
	
	//add a custom class to the body tag so that we only target custom css when javascript has edited the dom, otherwise its a stock label pg
	$('body').addClass('custom');
	
	//****** FGT TOP BAR  ***********//
	if($('table.topnav').length){

			
		//get the fgt top nav html so we can move it somewhere else
		var topNavTable = $('table.topnav td.topnav table tr').html();
		
					
		
		//add the fgt top nav to beginning of page
		$('body').prepend('<div class="fgtTop"><div class="fgtNav"><ul>'+topNavTable+'</ul><div class="clear"></div></div></div>');
		
		//set css of various 
		$('.fgtTop').css({
			'position':'fixed',
			'top':'0',
			'width':'100%',
			'height':'40px',
			'margin':'0',
			'padding':'0',
			'background':'transparent url(//fgt-static.s3.amazonaws.com/label_859/images/fgtTop-bg.png) repeat-x top left',
			'z-index':'99'
		});
		$('.fgtNav').css({
			'width':'960px',
			'margin':'0 auto',
			'position':'relative',
			'left':'0px'
		});
		$('.fgtNav ul').css({
			'margin':'0',
			'display':'block',
			'position':'absolute',
			'right':'0'
		});
		
	
		$('.fgtNav a').wrap('<li />');
		$('.fgtNav li').css({
			'float':'left',
			'background':'transparent',
			'list-style-type':'none',
			'border-right':'1px solid #333',
			'padding':'0',
			'margin':'0',
			'width':'auto'
		});
		$('.fgtNav li a').css({
			'display':'block',
			'line-height':'30px',
			'font-size':'12px',
			'padding':'0 15px',
			'color':'#fff',
			'font-size':'10px'
		});
		$('.fgtNav li a').hover(function(){
			$(this).css({
				'background-image':'url(//fgt-static.s3.amazonaws.com/label_859/images/transBlack20.png)',
				'text-decoration':'none'
			});
		},
		function(){
			$(this).css({
				'background-image':'none',
				'text-decoration':'none'
			});
		});
		$('.fgtNav li:first').addClass('first').css('border-left','1px solid #333');
		
		
		
		//get rid of hard coded <br>'s in the nav
		$('.fgtNav li a br').remove();
		
		//hide original top nav
		$('table.topnav').hide();
		
		//add fgt logo to fgt top bar
		$('.fgtTop .fgtNav').prepend('<div class="fgtLogo" style="float:left;padding-top:2px;"><a href="http://www.frontgatetickets.com" title="Powered By Front Gate Tickets"><img height="26" border="0" src="//fgt-static.s3.amazonaws.com/label_859/images/logoFGT.png"></a></div>');
		
		
		//set the width of the nav based on the total link width
		var wholeNavWidth = $('.fgtTop .fgtNav').width();
		var logoWidth = $('.fgtTop .fgtNav .fgtLogo').width();
		$('.fgtNav ul').width(wholeNavWidth - logoWidth);
		var navUlWidth = 0;
		$('.fgtNav li').each(function(){
			navUlWidth = $(this).outerWidth() + navUlWidth;
		});
		$('.fgtNav ul').width(navUlWidth);
	
	}//end if statement to check for nav to replace (this avoids putting nav bar on pupups)
	//******* end fgt top bar *****/
	

	//add a 'align left' class to the fgt top nav
	$('.fgtTop').addClass('leftAligned');
	
	
	//wrap the main table in a div
	$('table.main').wrap('<div class="wrapper" id="wrapper"/>');
	$('table.main').wrap('<div id="body" />');
	$('table.main').wrap('<div id="content" />');
		
	//wrap the top header in a new div
	$('table.topnav').wrap('<div class="headerWrapper fgtOrigHeader" />');
		
	
	//add transmissions's nav 
	$('#wrapper').before('<!-- start of masthead --><div id="masthead"><div id="breadcrumb"><h1 class="clear"><a href="http://www.transmissionentertainment.com/" id="logo">Transmission Entertainment</a> &raquo; Ticketing</h1></div></div><!-- end masthead --><!-- start of nav --><ul id="nav_categories" class="nav clear"><li><a href="http://www.transmissionentertainment.com/upcoming/"><h3>Calendar</h3></a></lid><li><a href="http://www.transmissionentertainment.com/features/"><h3>Features</h3></a></li><li><a href="http://www.transmissionentertainment.com/archive/category/sights/"><h3>Sights</h3></a></li><li><a href="http://www.transmissionentertainment.com/archive/category/sounds/"><h3>Sounds</h3></a></li><li><a href="http://www.transmissionentertainment.com/archive/category/words/"><h3>Words</h3></a></li></ul><!-- end nav-->');
	
	//set the appropriate width of the main content td
	$('td.sidenav').next().width(720);
	
	//wrap the footer in a new div
	$('table.browse:last').wrap('<div class="fgtOrigFooter" />');
	
	//get the fgt top nav html so we can move it somewhere else
	var fgtFooter = $('.fgtOrigFooter').html();
	
	//hide the original fgt footer
	$('.fgtOrigFooter').hide();
	
	//place a title bar type thing
	//$('#wrapper #body').prepend('<!-- header type thing for ticketing --><h4 class="sectionTitle fgtTitle" style="margin:10px;">Purchase Tickets</h4>');
	
	//place new footer in the site framework
	$('#wrapper #body').append('<div id="footer">'+fgtFooter+'</div>');
	
	//place the cosmopolitan footer
	$('#footer').prepend('<h4 class="sectionTitle">Everything Else</h4><!-- @@@@ start of footer div --><div class="footer clear"><dl class="footerList"><dt>Transmission Entertainment</dt><dd><a href="http://www.transmissionentertainment.com/upcoming/" class="listLink">Calendar</a><br /><a href="http://www.transmissionentertainment.com/features/" class="listLink">Features</a><br /><a href="http://www.transmissionentertainment.com/archive/category/sights/" class="listLink">Sights</a><br /><a href="http://www.transmissionentertainment.com/archive/category/sounds/" class="listLink">Sounds</a><br /><a href="http://www.transmissionentertainment.com/archive/category/words/" class="listLink">Words</a><br /><a href="http://www.transmissionentertainment.com/photos/" class="listLink">Photos</a><br /><a href="http://www.myspace.com/transmissionentertainment" target="_blank" class="listLink">MySpace</a><br /><a href="http://www.facebook.com/group.php?gid=13604537967&ref=ts" target="_blank" class="listLink">Facebook</a><br /><br />RSS Feeds<br /><a href="http://www.transmissionentertainment.com/feeds/events/" class="listLink">All Events</a><br /><a href="http://www.transmissionentertainment.com/feeds/clubdeville/" class="listLink">Club de Ville</a><br /><a href="http://www.transmissionentertainment.com/feeds/mohawk/" class="listLink">Mohawk</a><br /><a href="http://www.transmissionentertainment.com/feeds/red7/" class="listLink">Red 7</a><br /><a href="http://www.transmissionentertainment.com/feeds/lamberts/" class="listLink">Lamberts</a><br /></dd></dl><!-- @@@@ footer list --><dl class="footerList"><dt>Information</dt><dd><a href="http://www.transmissionentertainment.com/services/" class="listLink">Services</a><br /><a href="http://www.transmissionentertainment.com/venues/" class="listLink">Venues</a><br /><a href="http://www.transmissionentertainment.com/information/#contact" class="listLink">Contact</a><br /><a href="http://www.transmissionentertainment.com/information/#submissions" class="listLink">Submissions</a><br /><a href="http://www.transmissionentertainment.com/information/#manifesto" class="listLink">Manifesto</a><br /><a href="http://www.transmissionentertainment.com/information/#friends" class="listLink">Friends &amp; Enemies</a><br /><br /><a href="http://www.transmissionentertainment.com/privacy_policy/" class="listLink">Privacy Policy</a><br /><a href="http://www.transmissionentertainment.com/terms_of_use/" class="listLink">Terms of Use</a></dd></dl><!-- @@@@ footer list tags --><dl class="footerList"><dt>Popular Tags</dt><dd><a href="http://www.transmissionentertainment.com/tag/mohawk" class="listLink">mohawk</a><br /><a href="http://www.transmissionentertainment.com/tag/red+7" class="listLink">red 7</a><br /><a href="http://www.transmissionentertainment.com/tag/from+the+mind+of+adi" class="listLink">from the mind of adi</a><br /><a href="http://www.transmissionentertainment.com/tag/adi+anand" class="listLink">adi anand</a><br /><a href="http://www.transmissionentertainment.com/tag/blog+contributor" class="listLink">blog contributor</a><br /><a href="http://www.transmissionentertainment.com/tag/fun+fun+fun+fest" class="listLink">fun fun fun fest</a><br /><a href="http://www.transmissionentertainment.com/tag/club+de+ville" class="listLink">club de ville</a><br /><a href="http://www.transmissionentertainment.com/tag/residency+series" class="listLink">residency series</a><br /><a href="http://www.transmissionentertainment.com/tag/fun+fun+fun+fest+2009" class="listLink">fun fun fun fest 2009</a><br /><a href="http://www.transmissionentertainment.com/tag/austinist" class="listLink">austinist</a><br /><a href="http://www.transmissionentertainment.com/tag/beauty+bar" class="listLink">beauty bar</a><br /><a href="http://www.transmissionentertainment.com/tag/mind+of+adi" class="listLink">mind of adi</a><br /><a href="http://www.transmissionentertainment.com/tag/waterloo+park" class="listLink">waterloo park</a><br /><a href="http://www.transmissionentertainment.com/tag/adi" class="listLink">adi</a><br /><a href="http://www.transmissionentertainment.com/tag/she+sir" class="listLink">she sir</a><br /></dd></dl><!-- @@@@ search  --><dl class="footerList"><dt>Search</dt><dd class="search"><form method="post" action="http://www.transmissionentertainment.com/"  ><div class="hiddenFields"><input type="hidden" name="ACT" value="19" /><input type="hidden" name="XID" value="" /><input type="hidden" name="RP" value="search" /><input type="hidden" name="NRP" value="noresults" /><input type="hidden" name="RES" value="" /><input type="hidden" name="status" value="" /><input type="hidden" name="weblog" value="blog|calendar" /><input type="hidden" name="search_in" value="everywhere" /><input type="hidden" name="where" value="all" /><input type="hidden" name="show_future_entries" value="yes" /><input type="hidden" name="site_id" value="1" /></div><!-- emial list join --><input type="text" name="keywords" id="terms" /><input type="submit" id="submit" value="Go" /></form></dd><dt><br />Join our Mailing List</dt><dd class="newsletter"><form id="mailinglist_form" method="post" action="http://www.transmissionentertainment.com/"  ><div class="hiddenFields"><input type="hidden" name="ACT" value="3" /><input type="hidden" name="RET" value="http://www.transmissionentertainment.com/information/" /><input type="hidden" name="list" value="transmission" /><input type="hidden" name="site_id" value="1" /></div><input type="text" name="email" value="" id="email" /><input type="submit" id="submit" value="Go" /></form></dd></dl></div><!-- @@@@ end of footer -->');
	
	//attach a class to the sidebar search form so we can target it
	$('.sidenav form').addClass('sideSearch');
	
	//add 'mainBodyTd' class to main body column 
	$('table.main tr:eq(1) > td:eq(1)').addClass('mainBodyTd');
	
	//home news module
	$('table.module').css('background-color',color3);
	
	//home events onsale list
	$('table.eventOnSale').addClass('custom');
	
		//wrap the buy links in a nice button css
	$('.eventOnSale td[align=RIGHT] a').each(function(){
		if($(this).html() == 'Buy Now &gt;&gt;'){
			 $(this).wrap('<div class="buyButton" />');
			 $(this).find('a').css('background',color2);
			 
		}
	});
	
	
	//order form stuff
	
		//buy process tabs
		$("table.orderTabs td:eq(3)").addClass('last');
		var otCount = 0;
		var otPrev = 9;
		$("table.orderTabs:eq(0) td").each(function(){
			if($(this).hasClass('selected')){
				otPrev = otCount - 1;
				//alert('has selected '+otPrev);
			}
			otCount = otCount + 1;
		});
		$("table.orderTabs td:eq("+otPrev+")").addClass('previous');
	
		//target the order clock td on the checkout form	
		$('table.orderTabs:eq(0) td.clock').addClass('firstClock').css('background','#fff !important');
	
		
		//shrink empty cells in bigform
		var emptyCell = '';
		$('.bigForm td, .bigForm th').each(function(){
			emptyCell = $(this).html();
			//alert(emptyCell);
			if(emptyCell == '&nbsp;' ){
				$(this).css({width:'0px',padding:'0px'});
			}
		});
		//style qty 
		$('.bigForm .ticketSum').wrapInner('<div class="qty" />');
	
	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" />');
	}
});

