﻿/* JANET JACKSON */
/* Javascript Triggers and Custom Functions
----------------------------------------------------------------------------- */


/* BEGIN READY FUNCTION
----------------------------------------------------------------------------- */	

	$(document).ready(function() {
		
		// Prep elements for animation
		$('#ticker').css('width', 0);

		if (ie6 == false) {
		
			$('#bar').css('opacity', '0');
			
		}

		// Normal				
		$('#network').find('a').each(socialSitesContract);
		$('#network').find('a').addClass('hover');

		if (page == "photos") {
		
			$('#tags ul li').removeClass('alt');
			$('#tags ul li:nth-child(2)').after('<li class="meetandgreet"><a href="/meetandgreets">2011 Tour Meet and Greets</a></li>');
			$('#tags ul li:odd').addClass('alt');		
		
			if ($('#page_number').text() == "1") {

				// First Page
				$('ul.photos > li:nth-child(1)').addClass('current');
				$('ul.photos > li:nth-child(2)').addClass('next');
				$('ul.photos > li:nth-child(3)').hide();
	
			} else {
			
				// Other Pages
				$('ul.photos > li:nth-child(1)').addClass('prev');
				$('ul.photos > li:nth-child(2)').addClass('current');
				$('ul.photos > li:nth-child(3)').addClass('next');
			
			}
			
		}
		
		
		

/* END READY FUNCTION
----------------------------------------------------------------------------- */	

	});
	
	
	
	
	//image slideshow
	
	
	$('#page-20_under_20_nominations div.widget-photo ul.photos').cycle();
	
	
	
/* BEGIN LOAD FUNCTION
----------------------------------------------------------------------------- */	
	
	$(window).load(function() {

		/* Flash Disclaimer */
/* 		$('div.flash').each(function() {

			if ($(this).children('embed').length == 0) {

				if ($('#bar #flash-disclaimer').length == 0) $('#bar').append('<div id="flash-disclaimer"><h3>You do not have the latest Flash version installed. Please click <a href="http://get.adobe.com/flashplayer/" target="_blank">here</a> to install.</h3></div>');
			
			}
		
		}); */

		if (section != "messageboard" && section != "checkout" ) {
			
			facebookLike();
			lifestyleList();
			tabs('removeEmptyTabs');
			twitter();
			socialSites();
			bar();
			markup();
			cufon();
			addThisLeads();
			signinOverlay();
			
			// AddThis
			addthis.button('.addthis_button-leads');

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

		}
		
	/* Survey Form */

		if (page == "contest") {
	
			$('#contest form').submit(function() {

				$('#contest .required').each(validateForm);
	
				if ($('#contest label.error').length > 0 || $('#contest fieldset.error').length > 0) {
	
					return false;

				}
				
				return true;

			});

		}
		
			
	/* Tour 2011 Form */	
	
		if (page == "index") {
	
			$('.survey form').submit(function() {

				$('.survey .required').each(validateForm);
	
				if ($('.survey label.error').length > 0 || $('.survey fieldset.error').length > 0) {
	
					return false;

				}
				
				return true;

			});

		}
			

	/* 20 Under 20 Nominations Form */	
	
		if (page == "20_under_20_nominations") {
	
			$('.survey textarea').maxlength({max: 1000});
			
			$('.survey form').submit(function() {

				$('.survey .required').each(validateForm);
	
				if ($('.survey label.error').length > 0 || $('.survey fieldset.error').length > 0) {
	
					return false;

				}
				
				return true;

			});

		}
		
	/* True You */
	
		if (page == "index") {
		
			$('#true-you ul.quotes').cycle({
			
				fx:			'fade', 
				speed:		400,
				timeout:	5000
				
			});

			$('#true-you ul.photos').cycle({
			
				fx:			'scrollLeft', 
				speed:		400,
				timeout:	10000
				
			});
		
		}
		

	
/* ALBUM LIST
----------------------------------------------------------------------------- */

		if (page == "videos") {
			
			// Cloning Album Tags - adding to Tag Listing
			$('#tags-albums > ul').clone().appendTo('#tags li:contains(Music Videos)');
			$('#tags li > ul').addClass('albums');
			$('#tags-albums').hide();
			
			// Hiding Sub-Categories
			$('#tags ul.albums li a:contains(Everything)').parent('li').hide();
			$('#tags ul.albums li a:contains(Janet Jackson)').parent('li').hide();
			$('#tags ul.albums li a:contains(Dream Street)').parent('li').hide();
			
		}


/* MAKE ME COOKIE
----------------------------------------------------------------------------- */

		if (page == "gift") {
		
			if ($('#gift').length > 0) {
				$.cookie('mailinglist','subscribed', { expires: 30 });
			}
			
			if ($.cookie('mailinglist') == 'subscribed' && $('#gift').length == 0) {
				window.location = '/gift?give=gift';
			}
		
		}


/* AUTO TEXT AREA HIGHLIGHT
----------------------------------------------------------------------------- */

		if (page == "webkit") {
		
			$('#webkit textarea').click(function() {
			
				this.select();
			
			});
		
		}
		

/* JANET'S LIST EXTERNAL LINKS
----------------------------------------------------------------------------- */

		$('#lists p a').click(function() {

			var link = $(this).attr('href');
			window.open(link);

			return false;

		});


/* POLLS
----------------------------------------------------------------------------- */


		$('div.widget-poll td strong:contains("CORRECT")').parents('tr').addClass('correct');

		if (page == "index") {
		
			// Remove empty open poll container
			if ($('#featured #open').find('form').length == 0) {
			
				$('#featured #open').remove();
				
			}

			$('#featured div.widget-poll h3').wrapInner('<a href="#"></a>');

			// Add hover to heading
			$('#featured div.widget-poll h3 a').hover(function() {
			
				$(this).parent().parent().addClass('hover');
			
			}, function() {
			
				$(this).parent().parent().removeClass('hover');
			
			});
			
			$('#featured div div.widget-poll:first-child').addClass('selected');
			
			// Toggle
			$('#featured div.widget-poll h3 a').click(function() {
			
				$('#featured div.widget-poll').removeClass('selected');
				$(this).parent().parent().addClass('selected');
				Cufon.refresh();
								
				return false;
			
			});
			
			// Add placeholder if empty
			if ($('#featured #polls').children().length == 0) {
			
				$('#featured #polls').addClass('placeholder');
				$('#featured #polls').append('<h3>Thank you for your vote.</h3><p>Results will be announced later, please check back regularly.</p>');
				
			}
			
		}
		
		if (page == "question") {
		
			// Work around for Browse Link bug
			$('div.widget-poll.browse a.browse').attr('href', '/trivia');
		
		}

		
/* END LOAD FUNCTION
----------------------------------------------------------------------------- */

	});


/* FUNCTION: FACEBOOK LIKE
----------------------------------------------------------------------------- */

	function facebookLike() {
		
		$('#news div.widget-editorial.leads ul.leads > li').each(function() {
			
			var storyURL = $(this).children('h4').children('a').attr('href');
			var likeURL = site_host + storyURL;
						
		});
						
	}
	
	/* 	Notes for Finishing:
		
		Inject generic "like" iframe HTML and replace shared URL with 
		constructed story URL so the Like button refers back to the 
		specific story that was "liked".
		
	/*
	

/* FUNCTION: LIFE & STYLE LIST
----------------------------------------------------------------------------- */

	function lifestyleList() {
		
		if ($('div.widget-editorial.list').length > 0) {
	
			var marker = "----------";  // Horizontal rule for splitting lists
	
			// Fill each tab with a list
			var tabs = $('div.widget-editorial.list div.story').html().replace(/<hr>/ig, marker).split(marker);

			// Prepare container for tabs
			$('div.widget-editorial.list').addClass('tabbed');
			$('div.widget-editorial.list').empty().prepend('<ul class="tabs"></ul>');
	
			for (var i = 0; i < tabs.length; i++) {
	
				// Add panel to tabbed container
				$('div.widget-editorial.list').append('<div>' + tabs[i] + '</div>');
	
				// Check for heading in newly added panel
				if ($('div.widget-editorial.list div:last h4').length > 0) {
	
					var tabName = $('div.widget-editorial.list div:last h4').text();
					var panelID = $('div.widget-editorial.list div:last h4').text().replace(/ /g, '').toLowerCase();
	
					// Append tab
					$('div.widget-editorial.list ul.tabs').append('<li><a class="tab ' + panelID + '" href="#' + panelID + '">' + tabName + '</a></li>');
	
					// Add ID + Markup class to panel
					$('div.widget-editorial.list > div:last-child').attr('id', panelID).attr('class', 'pane');
					//$('div.widget-editorial.list > div:last-child').attr('id', panelID).attr('class', 'markup');
	
				}
	
			}
			
			// Setting Alt Class
			$('div.widget-editorial.list div.pane').each(function() {
				
				$(this).find('p:odd').addClass('alt');
				
			});
	
		}
		
		
	}


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

	function tabs() {

		$('div.tabbed').tabs({

			fxSlide: false, 
			show: function() {

				$panel = $(this);

				$panel.find('div.player div.flash div').empty();

				if ($panel.find('div.player:visible').length > 0) {
				
					var player = $panel.find('div.player:visible div.flash div').attr('id');
					eval(player)();
				
				}
				
				// Making Poster Cyle Wait Until Tab is Loaded
				if ($('#page-index li.married').hasClass('ui-tabs-selected')) {
												
					// Colored Girl Posters
					$('.posters ul').cycle({ 
						fx:     'scrollHorz', 
						speed:  1000, 
						timeout: 5000, 
						next:   'a.nav.next', 
						prev:   'a.nav.back' 
					});
				
				}
				
				
			}
			
		});

		$('#featured #number-ones #us a.watch').click(function() {
		
			$('#featured > .tabs .makeme a').click();
			return false;
   			
		});

	}


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

	function twitter() {
	
		$('div.tweets').tweet({
		
        	username: "janetjackson",
          	count: 5,
          	loading_text: "Loading tweets..."

     	 });
     	 
     	 // Using setTimeout since tweet plugin doesn't have callback
     	 setTimeout(cufon, 1000);
     	 setTimeout(function() {
     	 
			$('#ticker ul.tweet_list').cycle({
	
				speed: 300,
				timeout: 7000
	
			});
     	 
     	 }, 1000);
   	 
	}


/* FUNCTIONS: SOCIAL SITES LINKS
----------------------------------------------------------------------------- */

	function socialSites() {
	
		// Hover
		$('#network').find('a').hover(socialSitesExpand,socialSitesContract);
		
	}
			
	function socialSitesExpand() {
		
		// Stop current animation
		$(this).stop();
		
		// Get enlarged logo size
		$(this).addClass('hover');
		var largeWidth = $(this).width();
		$(this).removeClass('hover');
	
		// Animate			
		$(this).animate({
		
			width: largeWidth,
			backgroundPosition: '-42px 0px'
		
		});
		
	}
	
	function socialSitesContract() {
		
		// Stop current animation
		$(this).stop();

		// Animate
		$(this).animate({
		
			width: '42px',
			backgroundPosition: '0px 0px'
		
		}, 400, function() {
		
			// Reset Styles
			$(this).removeAttr('style');
			$(this).removeClass('hover');
		
		});	
	
	}


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

	function cufon() {

		var avenir = [
		
			'body.section-tour h3:not(#meetandgreet h3, #photo h3)',
			'body.section-tour h4:not(div#vip h4, ul.tags h4)',
			'td.date',
			'a.action',
			'a.tab',
			'td.tickets li a', 
			'div.widget-item em'

		];

		var futura_book = [
		
			'h2', 
			'h4:not(body._janet_picks_the_song_for_hong_kong #story h4, body.janet_jackson_ #story h4, body.section-tour h4)',
			'ul.leads strong',
			'div.widget-editorial.display strong',
			'#news ul.headlines strong',
			'#news ul.headlines li a:not(a:contains("有關珍納積遜"), a:contains("珍納嚴選香港之歌"))',
			'#twitter ul.headlines strong',
			'#twitter ul.headlines li a',
			'#twitter #info a.follow',
			'ul.tweet_list > li',
			'#page-photos ul.photos strong',
			'#page-janet #highlights p',
			'#player div.widget-media div.details a',
			'#page-causes h3',
			'#page-orders div.widget-order.browse h3',
			'#page-causes ul.profile li strong',
			'#page-janet a.readmore',
			'#page-janet a.learnmore',
			'#page-janet #life_and_style h3',
			'#page-janet #causes h3',
			'#page-list #list h3',
			'#page-janet #life_and_style div.pane p strong',
			'#page-janet #causes strong',
			'#page-archive #archive h3',
			'#page-archive #archive ul.headlines li a',
			'#page-archive #archive ul.headlines strong',
			'body.section-janet div.widget-editorial.list ul.tabs li a.tab',
			'#page-news h3',
			'#page-trivia h3', 
			'#page-question h3', 
			'#page-biography div.story h3',
			'#legals h3',
			'div.widget-alert h3',
			'div.widget-alert p',
			'#page-gift h3.gift',
			'#page-gift p.preface', 
			'#page-webkit #webkit ul.tabs a',
			'#page-webkit #webkit dt',
			'#contest h3',
			'#tour2011 h3:not(#confirmation h3)',
			'#tour2011 div.info p',
			'#tour2011 div.info p a',
			'#page-20_under_20_nominations #confirmation h3',
			'#membership h3',
			'#page-account h3',
			'body.section-help h3', 
			'body.section-store ul.tabs a', 
			'body.section-store h3', 
			'div#flash-disclaimer h3',
			'#true-you h4'
			
			
		];
		
		var futura_bold = [
		
			'div#vip div.package h4',
			'div#vip h5',
			'div#vip div.merch h4',
			'div#vip div.experience h4',
			'div#vip div.merch li:not(div#vip div.merch li ul li)',
			'div#vip div.disclaimer h4',
			'div.choices li',
			'div#nominations h3 a',
			'div#nominations h3', 
			'#meetandgreet h3',
			'#page-meetandgreet-photo #photo h3',
			'#true-you h3',
			'#page-comingsoon h3.disclaimer'
		
		];
		
		var bin_regular = [
		
			'ul.filters li a', 
			'#trivia h3', 
			'#featured ul.tabs a'
			
		];

		Cufon.replace(futura_book, { fontFamily: 'Futura Book', hover: true });
		$(futura_book.toString()).css('visibility', 'visible');

		Cufon.replace(futura_bold, { fontFamily: 'Futura Bold', hover: true });
		$(futura_bold.toString()).css('visibility', 'visible');

		Cufon.replace(bin_regular, { fontFamily: 'BIN Regular', hover: true });
		$(bin_regular.toString()).css('visibility', 'visible');

		Cufon.replace(avenir, { fontFamily: 'Avenir', hover: true });
		$(futura_book.toString()).css('visibility', 'visible');
				
	}


/* FUNCTION: BAR 
----------------------------------------------------------------------------- */

	function bar() {

		setTimeout(function() {

			$('#bar').css('visibility', 'visible');
	
			// Twitter Ticker
			$('#ticker').animate({ width: '100%' }, 300);
			
			if (ie6 == false) {
			
				$('#bar').animate({ opacity: '1' }, 300);
				
			}
			
		}, 300);
	
	}


/* FUNCTION: PHOTO BROWSER
----------------------------------------------------------------------------- */
	
	function photoBrowser() {

		// Enlarged Image
		$('ul.photos li.current a').attr('href', '#').click(function() { return false; })
		var image = $('ul.photos li.current img').attr('src').replace('thumb.', '');
		$('ul.photos li.current img').attr('src', image).load(function() { $(this).fadeIn(); });
		

		// Navigation
		var current = $('#page_number').text() * 1;
		var next = "?page_number=" + (current + 1);
		var prev = "?page_number=" + (current - 1);

		if ($('ul.photos li.next a.comments').length > 0) $('ul.photos li.next a.comments').attr('href', next).attr('title', 'Next Photo');
		if ($('ul.photos li.prev a.comments').length > 0) $('ul.photos li.prev a.comments').attr('href', prev).attr('title', 'Previous Photo');
		
		// Hover Effects
		$('ul.photos > li.prev, ul.photos > li.next').hover(function() {
		
			$(this).addClass('hover');
		
		}, function() {
		
			$(this).removeClass('hover');
		
		});
		
	}
	
	
/* FUNCTION: ADDTHIS
----------------------------------------------------------------------------- */

	function addThisLeads() {
		
		var addthis_config = {
			
		    data_track_clickback: true
		
		}
						
		$('ul.leads > li').each(function() {
		
			var editorialURL = $(this).children('h4').children('a').attr('href');
			var editorialTitle = $(this).children('h4').text();

			$(this).children('ul.actions').each(function() {
				
				$(this).append('<li><a class="addthis_button-leads" addthis:url="' + site_host + editorialURL + '" addthis:title="Janet &middot; ' + editorialTitle + '">Share This</a></li>');
					
			});

		});
		
	}

	
/* CONTEST FORM VALIDATION
----------------------------------------------------------------------------- */

	function validateForm() {

		// Input field
		if ($(this).is('input') && ($(this).val().length == 0 || $(this).val() == "Required")) {

			$(this).parent().addClass('error');

			$(this).val('Required');
			
			function noteRequired() {

				if ($(this).val() == "Required") {
					$(this).val('');
				} else if ($(this).val().length == 0) {
					$(this).val('Required');
				}
			
			}
			
			$(this).blur(noteRequired);
			$(this).focus(noteRequired);
			
		// Textarea
		} else if ($(this).is('textarea') && ($(this).val().length == 0)) {	
		
			$(this).parent().addClass('error');

			$(this).val('Required');
			
			function noteRequired() {

				if ($(this).val() == "Required") {
					$(this).val('');
				} else if ($(this).val().length == 0) {
					$(this).val('Required');
				}
			
			}
			
			$(this).blur(noteRequired);
			$(this).focus(noteRequired);		
		
		// Dropdown option in label
		} else if ($(this).find("option:selected").val() == "Select an option") {

			$(this).parent().addClass('error');	
			
		} else if ($(this).find("option:selected").val() == "City") {

			$(this).parent().addClass('error');				
			
		} else if ($(this).find("option:selected").val() == "Month") {

			$(this).parent().addClass('error');	
			
		} else if ($(this).find("option:selected").val() == "Day") {

			$(this).parent().addClass('error');	
			
		} else if ($(this).find("option:selected").val() == "Year") {

			$(this).parent().addClass('error');				

		// Clear error
		} else {
		
			$(this).parent().removeClass('error');
		
		}
    	
	}
	

/* MARK UP CHANGES
----------------------------------------------------------------------------- */

	function markup() {

		// Add 'Nothing' links to success alert on Contest page
		$('#page-contest div.widget-alert.success h3').text('<h3>Thank you for entering the contest</h3>');
		$('#page-contest div.widget-alert.success p').append('<h4>Download the single "Nothing" from: </h4><ul><li><a href="http://click.linksynergy.com/fs-bin/stat?id=l0re4NcuOlA&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fitunes.apple.com%252Fus%252Falbum%252Fnothing%252Fid366652790%253Fi%253D366652800%2526uo%253D4%2526partnerId%253D30">iTunes</a></li><li><a href="http://www.amazon.com/gp/product/B003EJJIKC?ie=UTF8&tag=sparkart-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=B003EJJIKC">Amazon</a></li></ul>');


		if (section == "tour") {

			$('td.tickets li.vip.available a').text('Buy VIP Packages');
			$('td.tickets li.vip span').text('VIP Packages:');
			$('td.sales ul.start li span:contains("VIP Ticket Sales Start")').text('VIP Packages Sales Start');
			$('td.sales ul.start li span:contains("VIP Tickets")').text('VIP Packages');
			$('td.sales ul.end li span:contains("VIP Ticket Sales End")').text('VIP Packages Sales End');

			// Change VIP links to third party links in tour listing and event details pages
			addThirdPartyVIPLink("June 26, 2011", "http://www.ticketnet.fr/pack/idPack/144;jsessionid=65651545902AD81B1603236BF5BDB861.6F15317D7511752468");
			addThirdPartyVIPLink("June 27, 2011", "http://www.ticketnet.fr/pack/idPack/145;jsessionid=65651545902AD81B1603236BF5BDB861.6F15317D7511752468");
			addThirdPartyVIPLink("June 30, 2011", "http://www.ticketmaster.co.uk/event/1F004663B19767ED?artistid=972908&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("July 2, 2011", "http://www.ticketmaster.co.uk/event/1F004663B17567DB?artistid=972908&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("July 3, 2011", "http://www.ticketmaster.co.uk/event/1F004663B16D67CE?artistid=972908&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("July 5, 2011", "http://www.ticketmaster.co.uk/search?tm_link=tm_homeA_header_search&q=Janet+Jackson&search.x=0&search.y=0");
			addThirdPartyVIPLink("August 3, 2011", "http://www.ticketmaster.com/event/100046A4CD0898D6?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 4, 2011", "http://www.ticketmaster.com/event/000046A9E7FCD01C?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 6, 2011", "http://www.livenation.com/event/0200469BD8C47975?crosssite=TM_US:735353:16839");
			addThirdPartyVIPLink("August 8, 2011", "http://www.livenation.com/event/02004695F1268234?crosssite=TM_US:735353:16389");
			addThirdPartyVIPLink("August 9, 2011", "http://www.ticketmaster.com/event/010046DBAF8AA7B8?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 11, 2011", "http://www.ticketmaster.com/event/1600468EF7C68B18?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 12, 2011", "http://www.livenation.com/event/050046A9C660A3D0?crosssite=TM_US:735353:40979");
			addThirdPartyVIPLink("August 14, 2011", "http://www.ticketmaster.com/event/070046ABA9E29366?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 16, 2011", "http://www.ticketmaster.com/event/080046AAF8105E45?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 19, 2011", "http://www.ticketmaster.com/event/060046A5A71AB847?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 26, 2011", "http://www.ticketmaster.com/event/110046ACE842E08B?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 29, 2011", "http://www.ticketmaster.com/event/0F0046A9A13158CF?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("August 30, 2011", "http://www.ticketmaster.com/event/0F0046D0E19A6941?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("September 1, 2011", "http://www.ticketmaster.com/event/090046ACFD71B061?artistid=735353&majorcatid=10001&minorcatid=1");
			addThirdPartyVIPLink("October 18, 2011", "http://preferredseating.com.au/vip/tour/49/2484/janet-jackson-exclusive-vip-package/");

			if (page == "tour") {
				
				// Add VIP upgrade package buttons
				$('#vip-events tr.upgrade-vip, #vip-events tr.upgrade_vip').each(function() {
				
					if (signed_in) {				
						$(this).children('td.tickets').children('ul').append('<li class="upgrade"><a href="' + $(this).children('td.date').children('a').attr('href').replace(/show/, 'vip-details') + '">Buy VIP Upgrade Package</a></li>');
					} else {
						$(this).children('td.tickets').children('ul').append('<li class="upgrade"><a href="/login?alert=public-vip">Buy VIP Upgrade Package</a></li>');
					}
				
				});
			
			}

            // sortVIP();
			
		}

		if (page == "show") {
		
			var city = $('#show div.venue dt:contains("City")').next('dd').text();
			$('#show h4.date').after('<h4 class="city">' + city + '</h4>');

			// Replace old VIP sales link with static VIP sales link
			if ($('a.vip').length == "2") {
			
				$('a.vip:eq(0)').remove();
			
			}

		}

		if (page == "vip-details") {

			$('#page-vip-details div.widget-item div.exclusive h4:contains("This item is for members only")').html('Please sign in to access').after('<p>If you do not have a fan club membership, please sign up for one by clicking the "Sign In" button on the upper-righthand corner.</p>');	

			// Replace old VIP sales link with static VIP sales link
			if ($('a.vip').length == "2") {
			
				$('a.vip:eq(0)').remove();
			
			}

			var city = $('#show div.venue dt:contains("City")').next('dd').text();
			$('#show h4.date').after('<h4 class="city">' + city + '</h4>');
							
			$('#show div.widget-event dt:contains("City")').next('dd').show();
			$('#sales div.widget-item label.tier').each(selectPackage);
			$('#sales div.widget-item label.tier').change(selectPackage);
			
			$("<small class='all'><strong>All prices are in USD.</strong> Specific seat assignments are not given at time of purchase, but are given at VIP check-in. When purchasing four (4) VIP packages, there is no guarantee that the seats will be next to each other. Janet Jackson VIP merchandise packages and tickets are in the member's name and are non-transferable; thus please make sure you (the member) are able to attend.</small>").appendTo('#sales div.widget-item label.tier');
			
			$('#sales div.limited p').text('Sales will begin soon');
			$('#sales div.discontinued h4').empty().append('VIP Packages are sold out for this show!');		
			$('#sales div.widget-item div.purchase label.tier em').text('Choose Your Package');
			$('#sales div.widget-item div.purchase label.quantity em').text('How Many Packages?');
			$('#sales div.widget-item div.purchase ul.actions input').val('Buy Packages');
			$('#sales div.widget-item div.purchase ul.actions a').text('Buy Packages');
			
			Cufon.refresh();
			
			$('#sales div.topic em').text('Choose Your Package').show();
			$('#sales label.tier select option').removeAttr('title');
			
			if ($('#sales label.tier select option:last-child').text().match('Front')) {
				$('#sales label.tier select option:last-child').prependTo('#sales label.tier select');
			}

			if ($('#sales label.tier select').children('option').length > 1) {

				$('#sales label.tier select')[0].selectedIndex = 2;
			}

		}
	
	}
	

/* SELECT VIP PACKAGE
----------------------------------------------------------------------------- */

	function selectPackage() {

		if ($('label.quantity small').length == 0) {

			$('<small>Maximum of 4 Per Member</small>').appendTo('label.quantity');	
		
		}
	
	}


/* ADD THIRD PARTY VIP LINKS	
----------------------------------------------------------------------------- */

	function addThirdPartyVIPLink(date, link) {
	
		var month = getMonthShorthand(date.split(' ')[0]);
		var day = date.split(' ')[1].replace(/,/, '');
		var year = date.split(' ')[2];

		if (page == "tour") {

			var $date = $('#vip-events td.date a strong').children('abbr:contains("' + month + '")').siblings('span:contains("' + day + '")').siblings('em:contains("' + year + '")');
			$date.parents('td.date').siblings('td.tickets').children('ul').children('li.vip').children('a').attr('href', link).attr('target', '_blank');

		}
		
		if (page == "show") {
		
			$('#show h3:contains("' + date + '")').siblings('ul.actions').children('li').children('a.vip').attr('href', link).attr('target', '_blank');
		
		}

	}

	function getMonthShorthand(month) {
	
		switch(month) {
		
			case 'January':
				return 'Jan';
			case 'February':
				return 'Feb';			
			case 'March':
				return 'Mar';			
			case 'April':
				return 'Apr';			
			case 'May':
				return 'May';
			case 'June':
				return 'Jun';
			case 'July':
				return 'Jul';
			case 'August':
				return 'Aug';
			case 'September':
				return 'Sep';
			case 'October':
				return 'Oct';
			case 'November':
				return 'Nov';
			case 'December':
				return 'Dec';			
			default: 
				return true;
	
		}
	
	}	


/* SORT SPARKART'S VIP PACKAGES AND STATIC THIRD-PARTY VIP PACKAGES
----------------------------------------------------------------------------- */

	function sortVIP() {

		var $table = $('#vip-events table');
		var $source = $('#source');
		var $listing = $('<tbody></tbody>');
		var array = [];
		
		// Push static listing into array for sorting
		$source.find('#static-vip-events tbody tr').each(function() {

			var year = $(this).children('td.date').children('a').children('strong').children('em').text();
			var month = getMonthNumber($(this).children('td.date').children('a').children('strong').children('abbr').text());
			var day = $(this).children('td.date').children('a').children('strong').children('span').text();
			if (day.length == '1') day = '0' + day;
			var token = year + month + day;
		
			var event = [token, 'static', $(this).html()]; // [sort token, content type, markup]  
			array.push(event);
		
		});
		
		// Push Sparkart listing into array for sorting
		$source.find('#sparkart-vip-events tbody tr').each(function() {

			var year = $(this).children('td.date').children('a').children('strong').children('em').text();
			var month = getMonthNumber($(this).children('td.date').children('a').children('strong').children('abbr').text());
			var day = $(this).children('td.date').children('a').children('strong').children('span').text();
			if (day.length == '1') day = '0' + day;
			var token = year + month + day;
		
			var event = [token, 'sparkart_vip', $(this).html()];  // [sort token, content type, markup]
			array.push(event);
		
		});
	
		// Sort array
		array.sort();

		// Populate VIP listing
		for (var i = 0; i < array.length; i++) {

			var parity = '';
		
			if (i % 2 == 1) {

				parity += 'alt';

			}
			
			if (i == array.length - 1) {
			
				parity += ' last';
				
			}
			
			$listing.append('<tr class="performance ' + parity + ' ' + array[i][0] + ' ' + array[i][1] + '">' + array[i][2] + '</tr>');
		
		};
		$table.append($listing);

		// Remove source
		$source.remove();

	}
	
	function getMonthNumber(abbr) {
	
		switch(abbr) {
		
			case 'Jan':
				return '01';
			case 'Feb':
				return '02';			
			case 'Mar':
				return '03';			
			case 'Apr':
				return '04';			
			case 'May':
				return '05';
			case 'Jun':
				return '06';
			case 'Jul':
				return '07';
			case 'Aug':
				return '08';
			case 'Sep':
				return '09';
			case 'Oct':
				return '10';
			case 'Nov':
				return '11';
			case 'Dec':
				return '12';			
			default: 
				return true;
	
		}
	
	}
	

/* SIGN IN OVERLAY
----------------------------------------------------------------------------- */

	function shrinkFlash() {
		
		$('div.widget-media div.flash').addClass("shrink");
		
		}
	
	function expandFlash() {
		
		$('div.widget-media div.flash').removeClass("shrink");
		
		}

	function signinOverlay() {
		
		// ADDING WMODE = TRANSPARENT TO FLASH ELEMENTS SO IE7 LAYERS HTML OVER FLASH
		
		// SET HEIGHT OF OVERLAY
		$('#signin-overlay').css('height', $(document).height());
		
		// SET REDIRECT PAGE INPUT
		if (page != "login" && page != "join") {

			var pageURL = window.location.pathname;
			$('#signin-overlay #signin input[name="redirect_to"]').attr('value', pageURL);
		
		// Only set the redirect page if the redirect_to parameter doesn't exist (for restricted legacy pages)
		} else if ((page == "login" || page == "join") && (redirect == "false")) {
			
			$('#signin-overlay #signin input[name="redirect_to"]').attr('value', '/redirect');
						
		}
						
		// SETTING UP HELP LINKS & FORGOT PASSWORD TOGGLE
		$('#signin-overlay #signin div.signin a.help').insertAfter('div.signin input[type=password]');
		$('#signin-overlay #signin div.signin a.reset').insertAfter('div.signin input[type=password]');
		$('#signin-overlay #signin div.signin a.help, div.signin a.reset').wrap('<small></small>').show();
		$('#signin-overlay #signin div.signin a.reset').click(function() {

			$('#signin-overlay #signin div.signin').hide();
			$('#signin-overlay #signin div.password').show();
			return false;
		
		});
		
		$('#signin-overlay #signin div.password ul.actions').append('<li class="cancel"><a class="action cancel" href="#">Cancel</a></li>');
		$('#signin-overlay #signin div.password a.cancel').click(function() {

			$('#signin-overlay #signin div.password').hide();
			$('#signin-overlay #signin div.signin').show();
			return false;
		
		});
		
		
		// CHANGE TO FORGOT PASSWORD PANE ON LINK CLICK
		$('#signin-overlay #signin div.widget-alert a[href=login]').click(function() {
			
			$('#signin-overlay #signin div.password').show();
			$('#signin-overlay #signin div.signin').hide();
			$(this).parent('p').parent('div.widget-alert').hide();
			return false;
			
		});
		
		// OPEN OVERLAY
		$('#id a.signin, li.presale a[href="/login?alert=public-presale"], li.vip a[href="/login?alert=public-vip"], li.upgrade a[href="/login?alert=public-vip"], body:not(body.signed_in)#page-photos li.meetandgreet a, body.section-tour:not(body.signed_in) div.choices a[href="/meetandgreets"]').click(function() {
										
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			
			if ((navigator.userAgent.match('MSIE 7')) || (navigator.userAgent.match('MSIE 8'))) {
				
			shrinkFlash();
			
			}
			
			return false;
			
		});
		
		// OPEN OVERLAY ON LOGIN AND JOIN PAGES
		if (page == "login" || page == "join") {
			
			$('div.section > a.signin').click(function() {
				
				$('body').addClass('overlay');
				$('#signin-overlay').fadeIn('fast');
				
				return false;
				
			});
			
		}
		
		// OPEN OVERLAY ON LOGIN PAGE
		if (page == "login") {
			
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			
		}
		
		// OPEN OVERLAY ON PROMPT LINKS
		$('div.prompt a.signin').click(function() {
									
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			
			if ((navigator.userAgent.match('MSIE 7')) || (navigator.userAgent.match('MSIE 8'))) {
				
			shrinkFlash();
			
			}
			
			return false;
			
		});
		
		// CLOSE OVERLAY
		$('#signin-overlay #signin a.close').click(function() {
			
			$('body').removeClass('overlay');
			$('#signin-overlay').fadeOut('fast');
			
			if ((navigator.userAgent.match('MSIE 7')) || (navigator.userAgent.match('MSIE 8'))) {
				
			expandFlash();
			
			}
			
			return false;
				
		});
						
		// ALERT: INVALID USERNAME & PASSWORD
		$('#signin-overlay #signin div.widget-alert h3:contains("Invalid")').each(function() {
			
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			$('#title div.widget-alert').hide();
			
		});
		
		// ALERT: CLIQUE ID NOT FOUND
		$('#signin-overlay #signin div.widget-alert h3:contains("Not Found")').each(function() {
			
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			$('#title div.widget-alert').hide();
			$('#signin-overlay #signin div.password').show();
			$('#signin-overlay #signin div.signin').hide();
			
		});
				
		// ALERT: PASSWORD RESET
		$('#signin-overlay #signin div.widget-alert h3:contains("Password")').each(function() {
			
			$('body').addClass('overlay');
			$('#signin-overlay').fadeIn('fast');
			$('#title div.widget-alert').hide();
			$('#signin-overlay #signin div.password').hide();
			$('#signin-overlay #signin div.signin').show();
			
		});		
		
	}
	

/* FUNCTION: SCROLLPAGE
--------------------------------------------------------------------------- */

	
	function scrollPage() {			
			
			//Taken from http://oncemade.com/animated-page-scroll-with-jquery
			$('a.scrollpage').click(function() {
  			var elementClicked = $(this).attr("href");
  			
  			if (elementClicked == "#presales") {

  				$('#tour').tabs('select', 0);
  			
  			} else if (elementClicked == "#public") {

  				$('#tour').tabs('select', 1);
  			
  			}
  			
   			var destination = $(elementClicked).offset().top;
   			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
  			return false;
			});

		}	

