function requestPermissions() {
    FB.Connect.showPermissionDialog("publish_stream");	
}
function update_user_box(){
    var user_box = document.getElementById("fb_login");
    user_box.innerHTML = '<div style="float:left;margin:5px;"><fb:profile-pic uid="loggedinuser" size="square"></fb:profile-pic></div>' +
        '<p>You are connected using<br><fb:name uid="loggedinuser" useyou="false" linked="true"></fb:name></p>';
    var decision_box = document.getElementById("fb_decision");
    if ( gigDatePassed ) {
        decision_box.innerHTML = '<p style="clear:both;"><strong>Did you go?</strong></p><div id="fb_attend"><a href="/gig/attendingEvent.php?id='+gigID+'">YES, I Did<br>Attend</a></div>' +
        	'<div id="fb_notattend"><a href="/gig/notattendingEvent.php?id='+gigID+'">NO, I Did<br>Not Attend</a></div>';
    } else {
        decision_box.innerHTML = '<p style="clear:both;"><strong>Are you going?</strong></p><div id="fb_attend"><a href="/gig/attendingEvent.php?id='+gigID+'">YES, I Am<br>Attending</a></div>' +
        	'<div id="fb_notattend"><a href="/gig/notattendingEvent.php?id='+gigID+'">NO, I Am<br>Not Attending</a></div>';
    }
    FB.Facebook.apiClient.users_hasAppPermission("publish_stream", function(perms) {
        if ( ! perms ) {
        	requestPermissions();
        };
    });
    FB.XFBML.Host.parseDomTree();
}

$(function(){
	// Document is ready
	$('#featuretext a').each(function() {
		$(this).Tooltip({track:true,delay:0,showURL:false});
	});
	$("#gigtickets").each(function() {
		var container = jQuery(this);
		var output = '';
		jQuery.ajax({
			type: "GET",
			url: "/proxy/gigtickets.php",
			data: { date: date, venue: venue },
			dataType: "xml",
			timeout: 4000,
			success: function(xmlResponse){
			jQuery("gig", xmlResponse).each( function() {
				var price = jQuery("price", this).text();
				output = '<p>Tickets for this gig are currently on sale at the following shops, priced at <strong>&pound;'+price+'</strong>.</p>';
				output += '<ul class="list">';
				var see = jQuery("seetickets", this).text();
				var ticketmaster = jQuery("ticketmaster", this).text();
				var crash = jQuery("crash", this).text();
				var ticketline = jQuery("ticketline", this).text();
				var jumbo = jQuery("jumbo", this).text();
				var wgt = jQuery("wgt", this).text();
				var luna = jQuery("luna", this).text();
				var leedstickets = jQuery("leedstickets", this).text();
				var ticketweb = jQuery("ticketweb", this).text();
				var getmein = jQuery("getmein", this).text();
				var viagogo = jQuery("viagogo", this).text();
				var seatwave = jQuery("seatwave", this).text();
				var gigantic = jQuery("gigantic", this).text();
				if ( see > ' ' ) {
					output += '<li><a href="http://www.seetickets.com/see/event.asp?code='+see+'&filler1=see&filler3=id1leedsmusicscene">See Tickets</a></li>';
				}
				if ( ticketmaster > ' ' ) {
					output += '<li><a href="http://ticketsuk.at/davesugden/'+ticketmaster+'.html">Ticketmaster</a></li>';
				}
				if ( ticketweb  > ' ' ) {
					output += '<li><a href="http://ticketsuk.at/davesugden/'+ticketweb+'.html">TicketWeb</a></li>';
				}
				if ( gigantic  > ' ' ) {
					output += '<li><a href="http://www.gigantic.com/g~affiliate=leedsgigtickets~g/gigantic/event_'+gigantic+'.html">Gigantic</a></li>';
				}
				if ( ticketline > ' ' ) {
					output += '<li><a href="http://www.ticketline.co.uk/tickets/'+ticketline+'">Ticketline</a></li>';
				}
				if ( wgt > ' ' ) {
					output += '<li><a href="http://www.wegottickets.com/af/75/event/'+wgt+'">We Got Tickets</a></li>';
				}
				if ( getmein  > ' ' ) {
					output += '<li><a href="http://ticketsales.at/davesugden/'+getmein+'.html">Get Me In!</a></li>';
				}
				if ( crash > ' ' ) {
					output += '<li><a href="http://www.crashrecords.co.uk/online/product.php?xProd='+crash+'">Crash Records</a></li>';
				}
				if ( jumbo > ' ' ) {
					output += '<li><a href="http://www.jumborecords.co.uk/tickets.asp?event_id='+jumbo+'">Jumbo Records</a></li>';
				}
				if ( luna > ' ' ) {
					output += '<li><a href="http://www.lunatickets.co.uk/event_page.php?eventID='+luna+'">Luna Tickets</a></li>';
				}
				if ( leedstickets > ' ' ) {
					output += '<li><a href="http://www.leedstickets.com/eventinfo/'+leedstickets+'/">Leeds Tickets</a></li>';
				}
				if ( viagogo  > ' ' ) {
					output += '<li><a href="'+viagogo+'?affiliateID=520&PCID=AFFIAFFUKLeeds78867">Viagogo</a></li>';
				}
				if ( seatwave  > ' ' ) {
					output += '<li><a href="http://buy-tickets.at/davesugden/'+seatwave+'.html">Seatwave</a></li>';
				}
				output += '</ul>';
				output += '<p>Price excludes P&amp;P and fees.</p>';
			});
			jQuery(container).html(output);
			},
			error: function(x,y,z){	}
		});   
	});
});
