/* COUNTRY THROWDOWN TOUR */
/* Javascript Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() { 	
	
	
	});
	
	
/* POST-LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {	
		
	
/* CHAT POPUP
----------------------------------------------------------------------------- */


	$('body.private a.prompt.chat').click(function() {
		
		window.open('/chat','flash_chat','width=806,height=496,menubar=no,scrollbars=no,resizable=no,location=no,titlebar=no,toolbar=no');		
		return false;
		
	});
	


/* COMMUNITY PAGE PAGINATION
----------------------------------------------------------------------------- */


	if (page == "community") {
	
		$('#members ul.paging a').live('click', function() {
		
			$(this).closest('div.pane').load( $(this).attr('href'), function() {
			
				Cufon.refresh();
			
			});
			return false;
			
		});

	}


/* MEMBER NAVIGATION DROPDOWN
----------------------------------------------------------------------------- */


	$('ul#navigation li:has(ul)').hover(function() {

		$(this).addClass('hover');

	}, function() {

		$(this).removeClass('hover');

	});
	

/* SITE-ONLY
----------------------------------------------------------------------------- */


	if (section != "messageboard" && section != "checkout" ) {


/* FUNCTION CALLS
----------------------------------------------------------------------------- */


	// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
	try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }

	// PLUGIN: CLIQUE FORMS (Adds text into input forms)
	$('#header #mailing_list_entry_email').cliqueForms({ placeholder: "Your E-mail Address" });

	// Move alert text into input forms
/*	$("#header label.error").each(function() {

		var message = $(this).children('strong').text();

		$(this).children('input[type=text]').val(message).attr("title", message);

		$(this).children('input[type=text]').click(function() {
		
			var label = $(this).attr("title");
			if (label == $(this).val()) {
			
				$(this).val("");
			
			}			
		
		});
		
		$(this).children('input[type=text]').blur(function() {
		
			var label = $(this).attr("title");
			if ($(this).val() == "") {
			
				$(this).val(label);
			
			}
			
		});
	
	});*/

	// PLUGIN: CLIQUE FORMS (Adds text into input forms)
	$('#countdown #mailing_list_entry_email').cliqueForms({ placeholder: "Enter your e-mail address to be the first to know!" });
	
	markup();
	eventDetails();
	killTabs();
	tabs();
	countdown();
	bandPhotos();
	$('#map').each(map);
	goingBanner();
	comments();
	twitter();
	readmore();
	

	if (page == "index") { 
		
		tasteOfCountry(8);
		//rotate('Featured Banners'); 
		sponsorList();
				
	}

	if (section !== "checkout") cufon();
	

/* iTunes PROMOTION
----------------------------------------------------------------------------- */


	if (page == "itunes-download") {
	
		$.getJSON('/itunes_code/fetch/2', function(data) {
	
			var code = data.code;

			$('strong#code var').text(code);
			$('a#download').click(function() {
				
				$.post('/itunes_code/track_click/' + code, function() {
					window.location = 'https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/freeProductCodeWizard?code=' + code;
				});			
				
				return false;
			
			});
			
		});
		
	}


/* END SITE-ONLY
----------------------------------------------------------------------------- */


	}


/* END POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */


	});
	

/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */


	function markup() {
	
		//$('#page-index #gentry a.browse').text('See Profile').attr('href', '/profile/member/montgomery_gentry').show();
		//$('#page-index #johnson a.browse').text('See Profile').attr('href', '/profile/member/jamey_johnson').show();

		$('#header .widget-subscribe a.submit').text('GET E-MAIL ALERTS >');
		$('.widget-event a.browse').text('SEE ALL DATES >');
		$('#twitter-container #next_stop a.browse').text('SEE ALL DATES >');
		$('.widget-event a.tally.going span').text('RSVPS');
		$('#recent_news a.browse').text("SEE ALL NEWS >");
		$('#recent_posts a.browse').text("SEE ALL POSTS >");
		$('#page-index div.headlines a.browse').text('READ THE FULL ARCHIVE >');
		$('#countdown .widget-subscribe a.submit').text('> SIGN UP FOR THE MAILING LIST');
		$('.widget-event li.public a').text('Buy Tickets');
		$('.widget-event li.presale a').text('Buy Pre-sale Tickets');
		$('#profile.bands a.befriend, #profile.bluebird_cafe a.befriend, #profile.charities a.befriend').text('Become a Fan');
		$('div.widget-account.setup a.submit').text("Enter the Country Throwdown Tour Site >");
		$('div.widget-account.modify ul.actions a.submit').text('Save Changes');
		$('div.widget-profile.modify ul.actions a.submit').text('Save Changes >');
		$('.main div.widget-profile.modify ul.actions a.submit').text('Save Changes');
		$('div.widget-profile.modify.status ul.actions a.submit').text('Save Status Message >');
		$('#about ul.actions a.change').text('Save Changes >');
		$('div.widget-member ul.actions a.browse').text('Browse All >');
		$('div.widget-friends ul.actions a.browse').text('Browse All >');
		$('#page-photo .sidebar ul.actions a.browse').text('Browse All >');
		$('ul.actions a.flag').text('Flag for Review >');
		$('div.widget-friend.confirmation a.confirm').text('Confirm >');
		$('div.widget-friend.confirmation a.reject').text('Reject >');
		$('a.change').text('Change >');
		$('a.remove').text('Remove >');
		$('a.delete').text('Delete >');
		$('a.back').text('< Back');
		$('a.next').text('Next >');
		$('#page-upload-photo div.widget-photo a.submit').text('Upload Photo >');
		$('#page-upload-photo div.widget-photo a.cancel').text('Cancel >');
		$('a.next').text('Next >');
		$('.sidebar #news ul.actions a.browse').text('See All News >');
		$('ul.actions.friend a.action.details').text('More Info >');
		$('#friends a.details.change').text('Change Relationship >');
		$('a.unfriend').text('End Friendship >');
		$('#search a.submit').text('Search Now >');
		$('#page-index div.widget-member.browse ul.actions').prepend('<h3><a href="/community">Who&rsquo;s Going?</a></h3>');
		$('#page-index div.widget-member.browse a.browse').text('See Who Else is Going >');
		
		
		// BECOMING A FAN
		$('body.tour_participants div#alert h3:contains("your request for friendship")').text('Your Fan Request Has Been Submitted');
		
		// ADDING UPDATE BUTTON
		if (page == "profile" && author == "true") {
			
			$('#profile ul.actions.author').append('<li class="emphasis"><a class="action update" href="/update/member/' + alias + '">Change profile picture ></a></li>');
		
		}
		
		// REMOVING HEADSHOT
		if (page == "update") {
			
			$('div.widget-profile.pictures h3').text('Change Your Profile Picture');
			$('div.widget-profile.pictures p').text('Your profile picture can be anything: artwork, a photo, or any other cool image. Picture must be in JPEG (.jpg) format.');
			$('div.widget-profile.pictures ul.actions a.submit').text('Save Profile Picture >');
			$('div.widget-profile.pictures h4').text('Your Picture');
			$('div.widget-profile.pictures fieldset em').text('Delete This Picture');
			
		}
		
		// BLUEBIRD CAFE BOX ON THE HOME PAGE
		$('#page-index #bluebird_featured h4').each(function() {
		
			var link = $(this).find('a').attr('href');
			$(this).parent('li').find('img').wrap('<em class="thumbnail"></em>');
			$(this).parent('li').append('<a class="mask" href="' + link + '"></a>');
			
		});
				
		// DATE HEADING
		$('#date_heading div.venue dl dt:contains(City)').next().addClass('city');
		$('#date_heading div.details > dl').addClass('event');
		$('#date_heading dl.event dt:contains(Kind)').next().remove();
		$('#date_heading dl.event dt:contains(Kind)').remove();
		$('#date_heading dl.event dt:contains(Ages)').remove();
		$('#date_heading dl.event dt:contains(Doors Open)').text('Doors Open At');
		$('#date_heading dl.event dd:last-child').remove();
		
		// VIP to MEGATICKET
		/* $('div.widget-event li.vip a').text('Megaticket').attr('href', 'http://www.megaticket.com/');
		$('div.widget-event a.vip').text('Megaticket').attr('href', 'http://www.megaticket.com/');
		$('div.widget-event li.vip span').text('Megaticket:');
		$('div.widget-event td.sales ul.start li span:contains("VIP Tickets")').text('Megaticket');
		$('div.widget-event td.sales li span:contains("VIP Ticket Sales Start")').text('Megaticket Sales Start');
		$('div.widget-event td.sales li span:contains("VIP Ticket Sales End")').text('Megaticket Sales End');
		$('#date_tickets dt:contains("VIP Tickets")').text("Megaticket"); */
		
		// VIP TICKET STATIC
		/*$('#page-dates div.widget-event.browse tr').each(function() {
			
			$(this).children('td.tickets').children('ul').append('<li class="vip available"><a href="http://countrythrowdown.artistarena.com/eventperformances.asp?evt=1">Buy VIP Tickets</a></li>')
			
		});*/
		
		// PRE-SALE TICKET URL
		$('div.widget-event li.presale a').attr('href', 'http://www.countrythrowdown.tickets.musictoday.com/CountryThrowdown/calendar.aspx');
		$('div.widget-event a.presale').attr('href', 'http://www.countrythrowdown.tickets.musictoday.com/CountryThrowdown/calendar.aspx');

		// ADD CLASSES TO BLUEBIRD CAFE FEATURED BAND LINKS
		$('#bluebird_featured div.story li:contains("Listen")').addClass('audio');
		$('#bluebird_featured div.story li:contains("Watch")').addClass('video');

		// ADD CLASSES TO BLUEBIRD CAFE FEATURED BAND LINKS
		$('#date_heading dl dd:nth-child(7)').addClass('last');
		
		// MEMBER LISTINGS
		$('#main ul.members > li:nth-child(3n+3)').addClass('third');
		$("#comments div.post span a").attr("href", "#");
		$("#comments ul.comments li div.member a").attr("href", "#")
		$("#rsvp_everyone a.picture").attr("href", "#");
		$("#rsvp_everyone a.alias").attr("href", "#");

		
		// PROFILE INFO FOR BANDS & CHARITIES
		$('#page-profile #profile dt.alias').each(function() {
			
			var text = $(this).text().replace(/_/g, ' ');
			$(this).text(text);
			
		});
		
		$("#page-profile div.widget-photo.slideshow ul.photos a").attr("href", "#");
		
		if (page == "banners") {
			
			
			$('div.banners textarea').focus(function() { $(this).select(); });
			$('div.banners textarea').click(function() { $(this).select(); });
			
			
		}
		
		// FAN PHOTO UPLOAD
		$('body.public #fan_photos p').append('<a class="prompt signin" href="/login?redirect_to=/upload-photo">Sign In to Upload Photos</a>');
		//$('#fan_photos ul.photos li h4').append('<em class="uploaded_by">Uploaded by ' + alias + '</em>');
		$('#page-date #fan_photos ul.actions a.action.share').removeClass('share').addClass('upload');
		$('#page-date #fan_photos ul.actions a.action.upload').text('Upload a Photo');
		
		// FAN PHOTO UPLOAD FOR PHOTOS PAGE
		$('<a class="prompt upload" href="/login?redirect_to=/upload-photo">Sign In to Upload a Photo</a>').prependTo('#page-photos.public #photos_fans');
		
		
		// DATE
		$('#date_heading div.details div.venue dl dd.city').prependTo('#date_heading div.details div.venue dl');
		$('#date_heading div.details dl.event').appendTo('#date_heading div.details');
		


	}
	
	
/* FUNCTION: CUFON REPLACEMENTS
----------------------------------------------------------------------------- */


	function cufon() {
	
		var interstate_black = [
		
		'h3:not(#itunes-download h3)',
		'ul.tabs a',
		'#navigation a',
		'a.action:not(.widget-event td.actions a.action, .widget-account.signin a.action)',
		'a.readmore',
		'#twitter a.twittername',
		'#twitter a.follow',
		'a.prompt',
		'#featured ul.tabs li a',
		'.quicklinks li h4',
		'#bluebird_cafe #bluebird_featured h4 a',
		'p.sponsors',
		'#artists li em',
		'#artists li span',
		'.widget-event td.tickets li span',
		'.widget-event td.tickets li em',
		'.widget-event td.tickets li a',
		'.widget-event td.tickets li.soldout',
		'.widget-event div.tickets dl',
		'.widget-event dl.event',
		'.countdown_amount',
		'#bluebird_bands li a',
		'#bluebird_featured li.audio',
		'#bluebird_featured li.video',
		'#countdown div.count var.days',
		'#rsvp #sidebar h3 + a',
		'#header p.welcome',
		'#more_artists ul.headlines a',
		'#more_artists #also_appearing > ul > li > a',
		'#more_artists #bluebird > ul > li > a',
		'.compact td.date strong abbr',
		'.sales td.date strong abbr',
		'#date_heading h4:visible abbr',
		'#date_heading div.venue dd:visible',
		'.sidebar div.widget-editorial.headlines ul.headlines li > strong abbr',
		'#page-charity div.widget-editorial h4'
		
		];
		
		var interstate_light_compressed = [
		
		//'.sidebar .compact td.date a',
		//'.sidebar .sales td.date a',
		'#on_the_road > h3'
		
		];
		
		var interstate_bold_compressed = [
		
		'.compact td.date strong span',
		'.sales td.date strong span',
		'#date_heading h4:visible span',
		'.sidebar div.widget-editorial.headlines ul.headlines li > strong span'
		
		];
		
		var rockwell_extra_bold = [
		
		// 'h2:not(.markdown h2)',
		// 'h3:not(.markdown.browse.leads ul.leads h3, .markdown.browse.stories ul.stories h3, .markdown.display h3)',
		'div.markdown h1',
		'h2',
		//'h3:not(.headlines.markdown > h3)',		
		'div.markdown li:not(.charity) div.story h4',
		'div.markdown h5',
		'.widget-event li a.date',
		'#countdown h4',
		'div.details #lineup tr td:first-child',
		'div.details #bluebird tr td:first-child',
		'#links p',
		'#bluebird_cafe > h4',
		'#bluebird_about p:first-child'
		
		];


		Cufon.replace(interstate_black, { fontFamily: 'Interstate-Black', hover: true });
		Cufon.replace(interstate_light_compressed, { fontFamily: 'Interstate-Light-Compressed', hover: true });
		Cufon.replace(interstate_bold_compressed, { fontFamily: 'Interstate-Bold-Compressed', hover: true });
		Cufon.replace(rockwell_extra_bold, { fontFamily: 'Rockwell', hover: true });

		$(interstate_black.toString()).css('visibility', 'visible');
		$(interstate_light_compressed.toString()).css('visibility', 'visible');
		$(interstate_bold_compressed.toString()).css('visibility', 'visible');
		$(rockwell_extra_bold.toString()).css('visibility', 'visible');
				
	}

/* FUNCTION: KILL TABS
----------------------------------------------------------------------------- */ 


	function killTabs() {
		
		if (page == "profile" || page == "dates" || page == "photos" || page == "date" || page == "friends") {

			// REMOVE EMPTY JAVASCRIPT TAB AND PANE
			$('div.tabbed').not(".static, .ajax").children('ul.tabs').children('li').each(function() {
	
				var pane = $(this).children('a').attr('href');
	
				if ( $(this).parent().parent().find(pane).children('*').length == 0 ) {
	
					$(this).remove();
					$(this).parent().parent().find(pane).remove();
	
				}
	
			});
	
			// REMOVE TABBED PANEL
			$('div.tabbed').not(".static, .ajax").children('ul.tabs').each(function() {
	
				if ($(this).children('li').length == 0) {
	
					$(this).parent().remove();
	
				}
	
			});
		
		}

	}
	
	
/* FUNCTION: INITIALIZE TABS
----------------------------------------------------------------------------- */


	function tabs() {
	
		// FIRST TAB IS A SLIDESHOW
		if (page == 'index' || page == 'profile' || page == 'community' || page == 'date') {
		
			$('.tabbed:not(.static) div.widget-photo.slideshow:visible').each(function() {
				
				var slideshowID = '#' + $(this).attr('id');

				if ( $(slideshowID).length > 0 && $(slideshowID).siblings('ul').children('li:first-child').children('a').attr('href') == slideshowID ) {
	
					$('.tabbed:not(.static) > ul').tabs();
	
					photoSlideshow();
					
					if ($(slideshowID + ' ul.photos').children('li').length > 1) {
	
						$(slideshowID + ' div a, a' + slideshowID + '_back, a' + slideshowID + '_next').hover(
	
							function() {
	
								$('a' + slideshowID + '_back').show();
								$('a' + slideshowID + '_next').show();
	
							}, function() {
	
								$('a' + slideshowID + '_back').hide();
								$('a' + slideshowID + '_next').hide();
	
							}
	
						);
					
					} 				
					
				}
			
			});
			
		}
		
		
		// JAVASCRIPT TABS
		$('.tabbed:not(.static) > ul').tabs({

			click: function(target) {
			
				$('div.loading').fadeIn();
				Cufon.refresh();

			}, load: function(event, ui) {

				$('div.loading').fadeOut();
				Cufon.refresh();
				twitter();
			
			}, show: function(event, ui) {

				$('div.loading').fadeOut();
				Cufon.refresh();

				// SLIDESHOW TAB
				$('.tabbed:not(.static) div.widget-photo.slideshow:visible').each(function() {
					
					var slideshowID = '#' + $(this).attr('id');
					
					if ( $(slideshowID).length > 0 ) {
					
						photoSlideshow();
	
						if ($(slideshowID + ' ul.photos').children('li').length > 1) {
	
							$(slideshowID + ' div a, a' + slideshowID + '_back, a' + slideshowID + '_next').hover(
			
								function() {
										
									$('a' + slideshowID + '_back').show();
									$('a' + slideshowID + '_next').show();
		
								},
								function() {
		
									$('a' + slideshowID + '_back').hide();
									$('a' + slideshowID + '_next').hide();
		
								}
		
							);
	
						}
					
					}
					
				});
			
			}

		});
		
		/* CENTER TABS */
		$('.tabbed.wide > ul.tabs').each(function() {
		
			var containerWidth = $(this).width();
			var tabsWidth = 0;
		
			$(this).children().each(function() {
			
				tabsWidth += $(this).width();
			
			});
			
			var paddingLeft = (containerWidth - tabsWidth) / 2;
			
			$(this).css('padding-left', paddingLeft + 'px');
			$(this).css('width', containerWidth - paddingLeft + 'px');
		
		});

	}
	
	
/* FUNCTION: FEATURED BANNERS
----------------------------------------------------------------------------- */

	
	function rotate(object) {

		switch(object) {

			// Rotate Featured Banners
			case "Featured Banners":
	
				$.get('/feeds/banners', function(data) {
	
					// Load banners
					$(data).find('unit').each(function() {
	
						if ($(this).find('name').text() == "featured_banners") {
	
							var slideshow = '<div id="slideshow">';
							var tabs = '<ul class="tabs">';
							var bannerNumber = 1;
	
							$(this).find('banner').each(function() {
	
								var url = $(this).children('url').text();
								var image = $(this).children('image').text();
								var caption = $(this).children('description').text();
	
								tabs += '<li><a href="#banner' + bannerNumber + '">' + caption + '</a></li>';
	
								// Add corners mask
								slideshow += '<a id="banner' + bannerNumber + '" href="' + url + '"><img src="' + image + '" alt="' + caption + '" /></a>';
	
								bannerNumber++;
	
							});
	
							slideshow += '</div>';
							tabs += '</ul>';
	
							$(slideshow).appendTo('#featured');
							$(tabs).appendTo('#featured');
	
						}
	
					});
					
					$('#featured ul.tabs > li:last-child').addClass('last');
					$('#featured ul.tabs').tabs({ fx: { opacity: 'toggle', duration: 'slow' } });
					$('#featured ul.tabs').tabs('rotate', 5000);
					Cufon.refresh();
	
				});
				
				break;
					
			default:
				
		}
		
	}
	

/* FUNCTION: TWITTER FEED
----------------------------------------------------------------------------- */

	function twitter() {
			
		$('#twitter:not(.expanded) div.tweets').each(function() {
			  
			if ($(this).find('.tweet_list > li').length == 0) {
				   
				$(this).tweet({
  
				username: "thrwdowntour",
				count: 5,
				loading_text: "Loading tweets..."
  
				});
     
			}
  
		});

		$('#twitter.expanded div.tweets').each(function() {
  
			if ($(this).find('#twitter.expanded .tweet_list > li').length == 0) {
				   
				$(this).tweet({
  
				username: "thrwdowntour",
				count: 7,
				loading_text: "Loading tweets..."
  
				});
     
			}
  
		});
     	 
	}
	
	
/* FUNCTION: MOVE "READ MORE" LINK
----------------------------------------------------------------------------- */ 


	function readmore() {

		$('div.widget-editorial.browse ul.leads > li:not(#page-index #bluebird_featured li)').each(function() {

			var link = $(this).find('a.display').attr('href');
			$(this).find('ul.actions').remove();

			// IF LAST CHILD IS P.LEAD
			if ( $(this).find('div.story > *:last-child').hasClass('lead') ) {

				$(this).find('div.story p.lead:last').append('&nbsp;&nbsp;<a class="readmore" href="' + link + '">Read More ></a>');
				Cufon.refresh();

			}
			
			// IF LAST CHILD IS ANOTHER ELEMENT
			else {

				$(this).find('div.story > *:last-child').after('<br /><a class="readmore" href="' + link + '">Read More ></a>');
				Cufon.refresh();

			}

		});

	}
	

/* FUNCTION: CYCLE BAND PHOTOS
----------------------------------------------------------------------------- */


	function bandPhotos() {
		
		// CYCLE VIDEO THUMBNAILS
		$('#artists ul.one ul:not(ul.actions)').cycle({

			fx: 'scrollLeft',
			speed: 1000,
			timeout: 8000
			
		});
		
		// CYCLE VIDEO THUMBNAILS
		$('#artists ul.two ul:not(ul.actions)').cycle({

			fx: 'scrollLeft',
			speed: 1000,
			timeout: 12000
			
		});
		
		// CYCLE VIDEO THUMBNAILS
		$('#artists ul.three ul:not(ul.actions)').cycle({

			fx: 'scrollLeft',
			speed: 1000,
			timeout: 20000
			
		});
		
	}
	
	
/* COUNTDOWN
----------------------------------------------------------------------------- */


	function countdown() {

		var started = '';
		var presales = new Date(2010, 2 - 1, 1);

		function tickTock() {
		
			if (started.length == 0) {

				$('div.count var.days').text(periods[3] + ' Days');
				$('div.count var.hours').text(periods[4] + ' Hours');
				$('div.count var.minutes').text(periods[5] + ' Minutes');
				$('div.count var.seconds').text(':' + periods[6]);
				Cufon.replace($('div.count var.days'), { fontFamily: 'Interstate-Black', hover: true });
				Cufon.replace($('div.count div var'), { fontFamily: 'Rockwell-Extra-Bold', hover: true });

			} else {

				started = periods[5];
				$('div.count var.minutes').text(periods[5] + ' Minutes');
				$('div.count var.seconds').text(':' + periods[6]);
				Cufon.replace($('div.count div var.minutes'), { fontFamily: 'Rockwell-Extra-Bold', hover: true });

			}
		
		}

		$('div.count span').countdown({ until: presales, onTick: tickTock });

	}
	

/* SPLIT EVENT DETAILS INTO TABS
----------------------------------------------------------------------------- */


	function eventDetails() {
	
		// HIDING TICKET BOX WHEN THERE ARE NO TICKETS
		if ($('#date_tickets > ul.actions, #date_tickets div.tickets').length == 0) {
			
			$('#date_tickets').hide();
			
		}
	
		$('#date_details h4.info').remove();
		$('#date_details h4.date').remove();
		$('#date_details h4.venue').remove();
		$('#date_details div.venue').remove();
		$('#date_details ul.actions').remove();
		$('#date_details div.tickets').remove();
		$('#date_details div.tags').remove();
	
		if ($('#date_details div.details').length > 0) {
	
			var marker = "----------";  // Horizontal rule for splitting event details
	
			// Fill each tab with event details
			var tabs = $('#date_details div.details').html().replace(/<hr>/ig, marker).split(marker);

			// Prepare container for tabs
			$('#date_details div.details').addClass('tabbed float');
			$('#date_details div.details').empty().prepend('<ul class="tabs"></ul>');
	
			for (var i = 0; i < tabs.length; i++) {
	
				// Add panel to tabbed container
				$('#date_details div.details').append('<div>' + tabs[i] + '</div>');
	
				// Check for heading in newly added panel
				if ($('#date_details div.details div:last h4').length > 0) {
	
					var tabName = $('#date_details div:last h4').text();
					var panelID = $('#date_details div:last h4').text().replace(/ /g, '').toLowerCase();
	
					// Append tab
					if (i == 0) {
					
						$('#date_details ul.tabs').append('<li class="first"><a class="tab ' + panelID + '" href="#' + panelID + '">' + tabName + '</a></li>');
	
					} else {
					
						$('#date_details ul.tabs').append('<li><a class="tab ' + panelID + '" href="#' + panelID + '">' + tabName + '</a></li>');

					}
	
					// Add ID + Markup class to panel
					$('#date_details div.details > div:last-child').attr('id', panelID).attr('class', 'markup');
					
					// Add downloadable  set list pdf to all dates
					/* $('<a class="action set_list all" href="' + asset_host + '/images/pdfs/countrythrowdown_tour_set_times_all.pdf" target="_blank">Looking for set list times?  Find them here!</a>').insertAfter('#page-date #description #date_details #lineup > ul');
					$('#page-date #description #date_details #lineup > a.set_list:eq(1)').remove();
					$('#page-date #description #date_details #lineup > a.set_list:eq(2)').remove();	

					// Add downloadable  set list pdf to specific dates
					if (topic == "may_14_2010-2" || topic == "may_15_2010-4") {					
					
						$('<a class="action set_list" href="' + asset_host + '/images/pdfs/countrythrowdown_tour_set_times.pdf" target="_blank">Looking for set list times?  Find them here!</a>').insertAfter('#page-date #description #date_details #lineup > ul');
						$('#page-date #description #date_details #lineup > a.set_list:eq(1)').remove();
						$('#page-date #description #date_details #lineup > a.set_list:eq(2)').remove();						
					
					} else if (topic == "june_12_2010-2") {
						
						$('<a class="action set_list" href="' + asset_host + '/images/pdfs/countrythrowdown_tour_set_times_slc.pdf" target="_blank">Looking for set list times?  Find them here!</a>').insertAfter('#page-date #description #date_details #lineup > ul');
						$('#page-date #description #date_details #lineup > a.set_list:eq(1)').remove();
						$('#page-date #description #date_details #lineup > a.set_list:eq(2)').remove();						
						
					} else if (topic == "june_13_2010-3") {
						
						$('<a class="action set_list" href="' + asset_host + '/images/pdfs/countrythrowdown_tour_set_times_co.pdf" target="_blank">Looking for set list times?  Find them here!</a>').insertAfter('#page-date #description #date_details #lineup > ul');
						$('#page-date #description #date_details #lineup > a.set_list:eq(1)').remove();
						$('#page-date #description #date_details #lineup > a.set_list:eq(2)').remove();	
						
					} else if (topic == "june_18_2010-7" || topic == "june_19_2010-2" || topic == "june_20_2010-1") {					
					
						$('<a class="action set_list" href="' + asset_host + '/images/pdfs/countrythrowdown_tour_set_times_ca.pdf" target="_blank">Looking for set list times?  Find them here!</a>').insertAfter('#page-date #description #date_details #lineup > ul');
						$('#page-date #description #date_details #lineup > a.set_list:eq(1)').remove();
						$('#page-date #description #date_details #lineup > a.set_list:eq(2)').remove();	
						
					} */
	
				}
	
			}
	
		}
	
	}
	

/* EVENT DETAILS ACCORDION
----------------------------------------------------------------------------- */


	function eventAccordion() {
	
		$('#date_details h4.info').remove();
		$('#date_details h4.date').remove();
		$('#date_details h4.venue').remove();
		$('#date_details div.venue').remove();
		$('#date_details ul.actions').remove();
		$('#date_details div.tickets').remove();
		$('#date_details div.tags').remove();

		$('#date_details div.details').accordion();
		
	}	

/* GOOGLE MAP
----------------------------------------------------------------------------- */


	function map() {
	
		var mapOptions = {

			zoom: 16,
			center: new google.maps.LatLng(-33, 151),
			navigationControl: true,
			navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
			mapTypeControl: false,
			mapTypeId: google.maps.MapTypeId.ROADMAP      

		};

		var map = new google.maps.Map(document.getElementById('map'), mapOptions);                          
		var geocoder = new google.maps.Geocoder();

		var venue = $('#date_venue div.venue dt:contains(Venue)').next().text(); 
		var street = $('#date_venue div.venue dt:contains(Street)').next().text(); 
		var city = $('#date_venue div.venue dt:contains(City)').next().text(); 
		var country = $('#date_venue div.venue dt:contains(Country)').next().text(); 
		var address = street + ',' + city + ',' + country;

		geocoder.geocode( { 'address': address }, function(point, status) {

			map.setCenter(point[0].geometry.location);
			
			var marker = new google.maps.Marker({
			
				position: point[0].geometry.location,
				map: map
			
			});
			
			var infowindow = new google.maps.InfoWindow({ content: '<strong>' + venue + '</strong>' });

			google.maps.event.addListener(marker, 'click', function() {
			
			  infowindow.open(map,marker);
			  
			});

		});
	
	}
	
	
/* I'M GOING BANNER CODE
----------------------------------------------------------------------------- */


	function goingBanner() {
	
		$('#going_banner select').each(chooseBanner);
		$('#going_banner select').change(chooseBanner);
		$('#going_banner input[type=text]').focus(function() { $(this).select(); });
		$('#going_banner input[type=text]').click(function() { $(this).select(); });

	}
	
	function chooseBanner() {
	
		var value = $(this).val();
		
		switch(value) {
		
			case "300x100": var code = '<a href="http://countrythrowdown.com/" target="_blank" title="Country Throwdown Tour"><img src="' + asset_host + '/images/banners/throwdown_going_300x100.png" width="300" height="100" alt="I&#8217;m Going to the Country Throwdown Tour" border="0" /></a>'; break;
			case "300x250": var code = '<a href="http://countrythrowdown.com/" target="_blank" title="Country Throwdown Tour"><img src="' + asset_host + '/images/banners/throwdown_going_300x250.png" width="300" height="250" alt="I&#8217;m Going to the Country Throwdown Tour" border="0" /></a>'; break;
			case "728x90": var code = '<a href="http://countrythrowdown.com/" target="_blank" title="Country Throwdown Tour"><img src="' + asset_host + '/images/banners/throwdown_going_728x90.png" width="728" height="90" alt="I&#8217;m Going to the Country Throwdown Tour" border="0" /></a>'; break;
			default: var code = ''; break;

		}
				
		$(this).closest('div').find('input[type=text]').val(code);
	
	}
	
	
/* COMMENTS
----------------------------------------------------------------------------- */


	function comments() {
	
		$('#comments a.prompt.post').click(function() {
		
			$('#post').show().find('textarea').focus();
			$(this).hide();
		
			return false;
		
		});
	
	}
	
	
/* FUNCTION: ROTATIONS
----------------------------------------------------------------------------- */


	function rotate(object) {
	
		switch(object) {
		
			// Rotate Featured Banners
			case "Featured Banners":
								
				$.get('/feeds/banners', function(data) {
		
					// Load banners
					$(data).find('unit').each(function() {
	
						if ($(this).find('name').text() == "featured_banners") {
		
							var slideshow = '<div id="slideshow">';
	
							$(this).find('banner').each(function() {
	
								if ($(this).children('status').text() != "Retract Temporarily") {
	
									var url = $(this).children('url').text();
									var image = $(this).children('image').text();
									var caption = $(this).children('description').text();
									var number = $(this).children('id').text();
									var target = $(this).children('target').text();
									var seconds = $(this).children('seconds').text();

									if (target == "_blank") {
										slideshow += '<a id="banner' + number + '" class="' + seconds + '" href="' + url + '" target="_blank"><img src="' + image + '" alt="' + caption + '" /><strong>' + caption + '</strong></a>';
									} else {
										slideshow += '<a id="banner' + number + '" class="' + seconds + '" href="' + url + '"><img src="' + image + '" alt="' + caption + '" /><strong>' + caption + '</strong></a>';
									}
							
								}
	
							});
	
							slideshow += '</div>';
							$('#featured').append(slideshow);

						}
	
					});

					$('#slideshow').cycle({
		
						fx:      'fade',
						speed:    'slow',
						timeout:  7000
						/* after: nextBanner */
		
					});
					
				/*

					function nextBanner() {
					
						var seconds = parseInt($('#slideshow a:visible').attr('class') + '000');
		
						setTimeout(function() {
						
							$('#slideshow').cycle('next');

						}, seconds);
	
					}

				*/

					$('#featured #slideshow a').click(function() {

						var $banner = $(this);
						var link = $banner.attr('href');
						var popup = window.open(link);
						var target = $banner.attr('target');
						var number = $banner.attr('id').replace('banner','');

						$.post('/process/banner_count/' + number, function() {

							if (target == "_blank") {
								window.open(link);
							} else {
								window.location = link;
							}
						
						});

						return false;
					
					});
	
				});
				
				break;
				
			case "asfd":
					
			default:
			
				
				
		}
		
	}
	
	
/* FUNCTION: SPONSOR LIST SCROLLING
----------------------------------------------------------------------------- */

	function sponsorList() {
				
		$('#sponsors div.story > ul').jcarousel({
			
			scroll: 3,
			auto: 3,
			visible: 4,
			wrap: "last"
						
		});

	}


/* FUNCTION: TASTE OF COUNTRY
----------------------------------------------------------------------------- */

	function tasteOfCountry(numberOfItems) {

		var numberOfItems = numberOfItems ? numberOfItems : 5;

		$.get('/feeds/external/tasteofcountry', function(data) {

			var headlines = '<ul class="headlines">';

			// Load item
			$(data).find('item').each(function(index) {

				if (index < numberOfItems) {

					var link = $(this).children('link').text();
					var title = $(this).children('title').text();
					var headline = '<li><a target="_blank" href="' + link + '">' + title + '</a></li>';					
					headlines += headline;
				
				}
			
			});
			
			headlines += '</ul>';
			$('#taste_of_country h3').after(headlines);

		});	
	
	}
