﻿$(document).ready(function()
{
	// **** resize master container ****
	var winW = 630, winH = 460;
		if (document.body && document.body.offsetWidth) {
		winW = document.body.offsetWidth;
		winH = document.body.offsetHeight;
		}
		if (document.compatMode=='CSS1Compat' &&
		document.documentElement &&
		document.documentElement.offsetWidth ) {
		winW = document.documentElement.offsetWidth;
		winH = document.documentElement.offsetHeight;
		}
		if (window.innerWidth && window.innerHeight) {
		winW = window.innerWidth;
		winH = window.innerHeight;
		}
		if (winW > 800)
		{

	// fgt bar
	if ($('table.topnav').length)
	{	
		$('body').css("display","block");
		$('td.topnav table').css("display","none");
		// 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>');
	}
	// fgt 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>');
	}

		}
		if (winW < 800)
		{
		
			// **** remove basic styling ****
	if($('link[href]').length)
	{
		$('link[href$="/styles.css"]').remove();
	}
	$('body').css("display","block");
	$('*[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" class="masterresize"></div>');
		// DRY principle: add class instead of straight CSS -- ######## FIX ME ########
		$('body').css("background","transparent");
		$('html').css("background","#fff");
	}
	// **** 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()
		{	
			// here we lowercase and replace space because this is rhyme time on a single comment line
			var lowercase = $("th", this).text().toLowerCase();
			var lowercase = lowercase .replace(/ /g,"-");
			// add div section container and attributes
			$('#sidebar').append('<div class="section" id="' + lowercase + '">' + $(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://#/"></a></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");
		// DRY principle: add class instead of straight CSS -- ######## FIX ME ########
		$('body').css("background","transparent");
		$('html').css("background","#fff");
	}
	// **** 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>');
	}
		
		
		// style nuke the following containers for the smaller layout
		$("body").css("display","block");
		$("div.inner img").css("display","none");
		$("#nav").css("float","left");
		$("div#footer").css("width","100%");
		$("th").css("font-size","12px");
		$("#sell").css("padding-right","2px");
		$("#verisign").css("display","none");
		$("div#about-us").css("display","none");
		$("#my-account h2").css("display","none");
		$("#sidebar").css("float","none");
		$("#sidebar").css("width","100%");  
		$("#sidebar .section").css("text-align","center");
		$("#sidebar a").css("margin","0px 6px"); 
		$("#sidebar a").css("display","inline-block"); 
		$("#content").css("padding","0px 0px");
		$("#awesomebox").css("display","none");
		$("#master").css("margin","32px auto");
		$("#master").css("border","0px");
		$("#calendar").css("display","none");
				$("#search").css("display","none");
				
		$('#sidebar').append('<div id="button"><a href="#">Security Verification</a></div><div id="popupContact"><a id="popupContactClose">x</a><h1>How to Verify a Secure Connection</h1><p id="contactArea">Safe “Key” or “Lock”: We use frames for easier navigation, and to integrate with Facebook and other Social Media sites. We place SSL encryption on only those frames that send credit card numbers. Since our home page and menus are not involved in this process, we do not use SSL encryption on these frames. Browsers don’t show the safe “key” or “lock” for the entire browser screen unless all frames in the window are SSL protected. Therefore, on our screens where credit card numbers are gathered, the “key” or “lock” do not appear.</p><p id="contactArea">SSL Verification: To verify that a frame is SSL-encrypted, please do the following: Internet Explorer: Right-click the mouse within the frame and select Properties. In the Properties window, the Connection line willlist what type of encryption is being used. Frames that are not encrypted will read “Not Encrypted”, while encrypted pages will show the type of encryption, such as : secure.independenttickets.com The identity of this website has been verified by VeriSign Trust Network.</p><p id="contactArea">Your connection to secure.independenttickets.com is encrypted with 256-bit encryption. The connection uses TLS 1.0. The connection is encrypted using CAMELLIA_256_CBC, with SHA1 for message authentication and DHE_RSA as the key exchange mechanism.</p><p id="contactArea">Firefox and Google Chrome: Right-click the mouse within the frame and select View Frame Info. In the Page Info window, the Security linewill list what type of encryption is being used. Frames that are not encrypted will read “This is an insecure document that is not encrypted and offers no security protection”, while encrypted pages will show the type of encryption, such as secure.independenttickets.com The identity of this website has been verified by VeriSign Trust Network.</p><p id="contactArea">Your connection to secure.independenttickets.com is encrypted with 256-bit encryption. The connection uses TLS 1.0. The connection is encrypted using CAMELLIA_256_CBC, with SHA1 for message authentication and DHE_RSA as the key exchange mechanism.</p><p id="contactArea">If you have a question specific to security, please contact us at security@frontgatesolutions.com.<p style="font-weight:bold;">Press ESCAPE, Click on X (right-top) or Click anywhere within the popup to close the popup</p></div>');
		}


	// **** 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');	
});


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupContact").click(function(){
			disablePopup();
	});
	//Press Escape event!
	$(document).keyup(function(e){
		if(e.keyCode == 27){
			disablePopup();
			}
	});

});
