﻿parseInt($('#navigation li.network').width());

/* BON JOVI */
/* Javascript Functions
--------------------------------------------------------------------------- */


	var geoLocation = new Array();

	$(document).ready(function() {

		hideCufon();
		$('ul.actions input[type=submit]').cliqueActions();
		markup();
		browser();
		
		$('#footer div.widget-alert').appendTo('#title');
				
		// DISABLE RIGHT CLICK
		$('#clip a.listen').bind('contextmenu', function() { return false; });

		if (page == 'croatia') croatia();
		if (page == 'ticketdesigns') ticketdesigns();
		
	});

	$(window).load(function() {

		$('#header-optin #mailing_list_entry_email').cliqueForms({ placeholder: 'Enter your e-mail address' });

		if (page == "qas") qas();

		geoLocate();
		
		title();

		truncate("div.categories ul.tabs li a strong", 30);
		truncate("div.accordion div.widget-editorial ul.headlines li > a", 75);
		truncate("div.sidebar div.featured div.widget-editorial ul.leads li h4 a", 42);
		
		addThisLeads();
		signinOverlay();
		if (page == "contest") contestLegals();

		if (page == "2011") {

			if ($('div.widget-alert h3:contains(You are already registered)').length > 0) {
			
				$('div.widget-alert h3').after('<p>Click <a href="/2011?alert=success">here</a> to get your merch discount offer.</p>');
				// window.location.href = "/2011?alert=success";
			
			}
			
		}

		cufon();

		if ($('#comments div.sidebar div.widget-comment.modify').length > 0) { commentBox(); }
		if ($('#comments div.widget-comment.modify').length > 0) { commentCounter(); }

		actions();
		cycle();
		header();
		// twitter();
		memberPlaceholders();
		merchandise();
		chat();
		externalLinks();

		if (page == "prayer") {
		
			$('#steps div.steps').each(function() {		
				
				// START SLIDESHOW
				$(this).before('<div id="tabs">').cycle({
					fx: 'fade',
					speed: 2000,
					timeout: 15000,
					pager: '#tabs',
					
				before: function() { if (window.console) console.log(this.src); }
				});
			
				// CUSTOMIZE PAGING LINKS
				$('#tabs a:nth-child(1)').livequery(function() { $(this).html('<em>Step</em><var>1</var><strong>Record<br />Yourself</strong></a>').addClass('one'); });
				$('#tabs a:nth-child(2)').livequery(function() { $(this).html('<em>Step</em><var>2</var><strong>Upload<br />Performance</strong>').addClass('two'); });
				$('#tabs a:nth-child(3)').livequery(function() { $(this).html('<em>Step</em><var>3</var><strong>Share<br />Video</strong></a>').addClass('three'); });
				$('#tabs a:nth-child(4)').livequery(function() { $(this).html('<em>Step</em><var>4</var><strong>Win<br />Tickets</strong>').addClass('four'); });
				
			});
		
/*			$('#steps #four ul.benefits').cycle({
			
					fx: 'fade',
					speed: 1500,
					timeout: 2000			
			});*/
		
		}
		
		vevoPlayer();
		greatestHits();
		if (page == "signup_de" || "bj-videos_de" ) signUp();
		if (page == "home" || page == "index") bonJoviYourself();
		if (page == "preshow") preShow();
		if (page == "live2011_contest") live2011Contest();
				
		// PLUGIN: PHOTO DOWNLOAD BLOCKER (Prevents photo downloads with overlayed gif)
		try {
			
			$('div.widget-photo.display img').photoDownloadBlocker();
			$('div.widget-photo.browse.gallery img').photoDownloadBlocker();
			$('div.widget-photo.slideshow img').photoDownloadBlocker();
			
			
		} catch (error) { alert('Error: Missing Photo Download Blocker Plugin'); }
		
		// AddThis
		addthis.button('.addthis_button-leads');

		// Open Facebook share pop-up
		if (page == "facebook-connect" && signed_in) {
		
			$('a.share').click(function() {

		      window.open("http://www.facebook.com/share.php?u=" + site_host + "/facebook-connect", "bonjovi","status=1,toolbar=0,scrollbars=1,width=630,height=325");

		      return false;
		
			});

		    $('a.share').trigger('click');
					
		}

		// It's Snowing OMG!
		//if (page == "holidays") snowing()

		// Facebook Javascript SDK
		/* if (window.FB) {

			FB.init({
			
				xfbml: true
			
			});
		} */

	});
	

/* FUNCTION: OPEN WINDOW
---------------------------------------------------------------------------- */

	function openWindow() {

		window.open("http://www.facebook.com/share.php?u=" + site_host + "/facebook-connect", "bonjovi","status=1,toolbar=0,scrollbars=1,width=630,height=325");

	}

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

	function hideCufon() {
	
		if (page == "tour") {		// Fixes odd error in IE
	
			tradeGothicCondensed = [
			'h3:not(.twitter h3, .section > div > h3, .pane.small h3, .widget-event.program h3, .story h3, div.prompt h3, .section-help div.main div.widget-editorial h3, #latest_news #poll > h3, #signin-overlay #signin h3, #cart h3, #clique h3)',
			'ul.tabs a',
			'.content h4:not(.program h4, .story h4, .sidebar .tags h4, ul.tags h4, #featured_news h4, div.sidebar div.featured div.widget-editorial h4, .section-help .sidebar h4, #inquiry h4, #featured div.tabbed > div h4)',
			'div > ul.actions a:not(.download a, #signin a)',
			'ul.pages li > *',
			'div.social a',
			'div.prompt.overlay h3',
			'div.prompt.text h3',
			'div.tabbed ul.tabs li strong',
			'td a.action',
			'#tickets > p',
			'div.layout a.tour',
			'#vip-bar a',
			'ul.actions li.soldout'
			];	
		
		} else if (section == "livinonaprayer") {		// Fixes odd error in IE
	
			tradeGothicCondensed = [
			'h3:not(.section > div > h3, div.prompt h3,  #signin-overlay #signin h3, #clique h3)',
			'h4 + strong', 
			'.content h4',
			'h5',
			'#four ul.benefits strong', 
			'div > ul.actions a:not(.download a, #signin a)',
			'ul.pages li > *',
			'div.social a',
			'div.prompt.overlay h3',
			'div.prompt.text h3',
			'#tabs a'
			];	
		
		} else {
		
			tradeGothicCondensed = [
			'h3:not(.twitter h3, .section > div > h3, .pane.small h3, .widget-event.program h3, .story h3, div.prompt h3, .section-help div.main div.widget-editorial h3, #latest_news #poll > h3, #signin-overlay #signin h3, #cart h3, #clique h3, #page-facebook-connect-rules #rules h3)',
			'ul.tabs a',
			'ul.categories li a',
			'.content h4:not(.program h4, .story h4, .sidebar .tags h4, ul.tags h4, #featured_news h4, div.sidebar div.featured div.widget-editorial h4, .section-help .sidebar h4, #inquiry h4, #featured div.tabbed > div h4, body.japanese #announcements li.news h4)',
			'.widget-event.program h4 strong',
			'.widget-event.program ul.tickets .available a',
			'div > ul.actions a:not(.download a, #signin a)',
			'form > ul.actions a',
			'div.widget-account.subscription ul.actions a',
			'ul.pages li > *',
			'#qas li > strong span',
			'div.social a',
			'#member_navigation ul li',
			'div.widget-editorial.headlines.featured li > strong span',
			'div.widget-editorial.headlines.featured li > a',
			'div.prompt.overlay h3',
			'div.prompt.text h3',
			'#help-anchors ul li a',
			'#widget div.info h4',
			'div.tabbed ul.tabs li strong',
			'#memberships div.package ul li strong',
			'#memberships div.package ul li span',
			'#customer ul.customer a',
			'#customer ul.customer span',
			'.section-store div.sidebar > h3',
			'.section-store #departments > ul > li > a',
			'.section-store #departments > ul > li > strong a',
			'td a.action',
			'.section-store div.main ul.actions li a.action',
			'#tickets > p',
			'#page-buy-greatesthits div.story blockquote h4',
			'div.layout a.tour',
			'#vip-bar a',
			'ul.actions li.soldout',
			'#page-glee #player div.details p',
			'#page-travel div.information div.story h3,',
			'#page-travel div.information div.story h4',
			'#page-opening_acts blockquote > h3',
			'#page-opening_acts blockquote > h4',
			'#page-opening_acts blockquote > ul > li > a',
			'p.top a',
			'#notice h4',
			'#navigation > li > a',
			'.section-home #lastnight h3', 
			'.section-home #lastnight h4 a span', 
			'.section-home ul.announcements li > strong', 
			'.section-home ul.ticker strong', 
			'.section-home ul.ticker span', 
			'.section-home li.event a.date', 
			'.section-home li.event h4 a span',
			'.section-home li.event .available a',
			'.section-home li.merch dt',
			'#page-croatia h2',
			'#page-ticketdesigns h2',
			'#page-referral #prizes .grand span'
			];
		
		}
		
		tradeGothicExtended = [
		'.content h2:not(.story h2, .backstagejbj h2, .section-livinonaprayer h2, #page-croatia h2, #page-ticketdesigns h2)',
		'#title h2:not(.backstagejbj #title h2)',
		'.widget-event.program h3:not(#lastnight h3)',
		'.section > div > h3:not(.section-store div.sidebar > h3)',
		'.section > form > div > h3',
		'.widget-event.program a.date:not(.section-home .widget-event.program a.date, #page-tour #archive a.date)',
		'.widget-editorial:not(#qas, .section-home .activity) ul.leads > li > strong',
		'.widget-editorial ul.stories > li > strong',
		'#qas li > strong abbr',
		'div.pane.display > strong',
		'div.widget-editorial.headlines.featured li > strong abbr',
		'.section-help div.main div.widget-editorial h3',
		'#latest_news #poll > h3', 
		'#page-facebook-connect-rules #rules h3'
		];
		
		garaline = [
		'.backstagejbj .content h2:not(.story h2)',
		'.backstagejbj #title h2'
		];
		
		$(tradeGothicExtended.toString()).css('visibility', 'hidden');
		$(tradeGothicCondensed.toString()).css('visibility', 'hidden');
		$(garaline.toString()).css('visibility', 'hidden');

	}
		
	function cufon() {
				
		Cufon.replace(tradeGothicExtended, { fontFamily: 'Trade Gothic Extended', hover: true });
		$(tradeGothicExtended.toString()).css('visibility', 'visible');
	
		Cufon.replace(tradeGothicCondensed, { fontFamily: 'Trade Gothic Condensed', hover: true });
		$(tradeGothicCondensed.toString()).css('visibility', 'visible');
		
		if (backstagejbj == true){
			
			Cufon.replace(garaline, { fontFamily: 'Garaline', hover: true });
			$(garaline.toString()).css('visibility', 'visible');
		
		}


/* Refreshes */

		//	$('ul.controls a.skip, ul.controls a.back').click(function() { Cufon.refresh(); });

		
	}
	

/* FUNCTION: QA'S
---------------------------------------------------------------------------- */

	function qas() {

		$('a.action.submit').livequery(function() {
		
			$(this).unbind('click').click(function() {

				if ($.cookie('qa_submitted')) {
	
					$('#title').append('<div class="widget-alert alert"><h3>You have already submitted your question for today</h3><p>Please try again tomorrow.</p>');
					Cufon.refresh();
					return false;

	
				} else {
				
					$.cookie("qa_submitted", true, { expires: 1, domain: "bonjovi.com" });
					$(this).siblings('input[type=submit]').click();
					return false;
				
				}
		
			});

		});
	
	}


/* FUNCTION: BROWSER DETECTION
---------------------------------------------------------------------------- */

	function browser() {
			
		if (navigator.userAgent.match('MSIE 6')) { browser = "ie6";	}
		else if (navigator.userAgent.match('MSIE 7')) { browser = "ie7"; }
		else if (navigator.userAgent.match('MSIE 8')) { browser = "ie8"; }
		else if (navigator.userAgent.match('Firefox')) { browser = "gecko"; }	
		else if (navigator.userAgent.match('AppleWebKit')) { browser = "webkit"; }
		$('body').addClass(browser);

	}


/* FUNCTION: CONTEST LEGALS
----------------------------------------------------------------------------- */

	function contestLegals() {

		$('div.widget-poll input[type=submit]').val('Enter the Contest');

		// Create Legals Box & Expand/Contract Legals Button
		$('div.story').find('ins').parent('p').wrap('<ul class="actions"><li><a href="#" class="action legal expand"></a></li></ul>');
		$('div.story').find('a.legal').text('Expand Terms and Conditions');
		$('div.story').find('ul.actions').nextAll().wrapAll('<div class="legal"><div class="markup"><div></div></div></div>');
		$('div.story').find('a.legal').click(function() {

			if ($(this).hasClass('expand')) {

				$(this).text('Collapse Terms and Conditions');
				$(this).removeClass('expand').addClass('collapse');
				$(this).parent('li').parent('ul.actions').siblings('div.legal').addClass('expand');

			} else {

				$(this).text('Expand Terms and Conditions');			
				$(this).removeClass('collapse').addClass('expand');
				$(this).parent('li').parent('ul.actions').siblings('div.legal').removeClass('expand');

			}

			if (typeof(window['Cufon']) != "undefined") Cufon.refresh();
			return false;

		});

		if (page == "contest") {

			$('div.story div.legal p:first').prepend('<h3>Contest Terms and Conditions</h3>').show();

		} else if (page == "mission") {

			$('div.story div.legal p:first').prepend('<h3>Mission Terms and Conditions</h3>').show();

		}


		// Additional Functionality for Legal Agreement
		if ($('div.story div.legal').length > 0 ) {

			if (page == "contest") {

				$('div.modify.submit-media div.group.details fieldset').append('<label class="terms"><input id="contest_terms" type="checkbox" value="1" name="contest_terms" /><em>I agree to the Contest terms set forth above</em></label><br />');

			} else if (page == "mission") {

				$('div.modify.submit-media div.group.details fieldset').append('<label class="terms"><input id="contest_terms" type="checkbox" value="1" name="contest_terms" /><em>I agree to the Mission terms set forth above</em></label><br />');

			}

			// Toggling Submit Button
			$('div.modify.submit-media ul.actions input').attr('disabled','disabled').addClass('disabled');
			$('div.modify.submit-media').addClass('disabled');
			$('div.modify.submit-media ul.actions a.submit').hide();

			$('div.widget-photo.modify.submit-media ul.actions li:first').append('<em>Submit Photo</em>');
			$('div.widget-media.modify.submit-media ul.actions li:first').append('<em>Submit Video</em>');

			$('div.modify.submit-media div.group.details label.terms input').click(function() {

				if ( $(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').hasClass('disabled') ) {

					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').removeAttr('disabled');
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').removeClass('disabled');
					$(this).parent().parent().parent().parent('div.modify.submit-media').removeClass('disabled');
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').siblings('a.submit').show();
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').siblings('em').hide();

				} else { 

					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').attr('disabled','disabled');
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').addClass('disabled');
					$(this).parent().parent().parent().parent('div.modify.submit-media').addClass('disabled');
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').siblings('a.submit').hide();
					$(this).parent().parent().parent().siblings('ul.actions').children('li.submit').children('input').siblings('em').show();

				}

			});


		}

	}


/* FUNCTION: CHAT POPUP
----------------------------------------------------------------------------- */

	function chat() {

		$('a.launch, #navigation li.chat a[class!=public]').click(function() {
			
			window.open( site_host + $(this).attr('href'),'Chat','width=980,height=675,resizable=0,scrollbars=0,toolbar=0,location=0,directories=0,status=0,menubar=0');
			return false;

		});

	}


/* FUNCTION: LOCALIZATION
---------------------------------------------------------------------------- */

	function geoLocate() {

		if ($.cookie('geoLocation.country')) {

			geoLocation.country = $.cookie('geoLocation.country');
			geoLocation.subcontinent = $.cookie('geoLocation.subcontinent');

		} else {

			geoLocation.country = 'US';
			geoLocation.subcontinent = 'United States';

			$.getJSON('/user/geolocation', function(location) {
			
				var options = { expires: 1 };
				geoLocation.country = location.country;
				geoLocation.subcontinent = location.subcontinent;
				$.cookie('geoLocation.country', geoLocation.country, options)
				$.cookie('geoLocation.subcontinent', geoLocation.subcontinent, options)
			
			});
		
		}

	}


/* FUNCTION: TRUNCATE
---------------------------------------------------------------------------- */

	function truncate(selector, length) {
	
		$(selector).each(function() {

			if ($(this).text().length > length) {

				var text = $(this).text().slice(0, length);
				var text = text.slice(0, text.lastIndexOf(' ')) + '...';

				$(this).html(text);

			}

		});
		
	}
	
	
/* FUNCTION: MEMBER PROFILE PLACEHOLDERS
--------------------------------------------------------------------------- */

	function memberPlaceholders() {

		$('div.widget-member a.picture, div.widget-friend a.picture, div.widget-comment a.picture').each(function() {

			if ($(this).children('img').attr('src').match('placeholder.gif')) {
				$(this).children('img').attr('src', $(this).children('img').attr('src').replace('placeholder.gif', 'placeholder-member' + Math.round(Math.random()*3 + 1) + '.gif'));
			}

		});

	}	
	
/* FUNCTION: ACTIONS
--------------------------------------------------------------------------- */

	function actions() {
	
	
/* Swap ad in featured area for news accordion when tab is clicked */	
		
		if ($('#featured .tabbed').length > 0) {

			$('#featured .tabbed ul.tabs a').click(function() {
			
				if ($('.tabbed .ad').length > 0) {
				
					$('.tabbed .ad').fadeOut(function() { 
					
						$(this).remove();
						$('.tabbed .accordion').fadeIn();
						
					});
				
				}
			
			});

		}
	
	
/* News Accordions */

		if ($('div.accordion').length > 0) {	
		$('div.accordion h3').click(function() {
		$(this).parent().siblings().find('ul.headlines').slideUp('fast');
		$(this).parent().siblings().removeClass('selected');
		$(this).siblings('ul.headlines').slideDown('fast');
		$(this).parent().addClass('selected');
		});
		$('div.accordion > div:first-child > h3').click();
		}
	
	}


/* FUNCTION: CYCLE
--------------------------------------------------------------------------- */

	function cycle() {
	
		$('#navigation ul.photos, #navigation ul.clips').cycle({ fx: 'scrollLeft', speed: 400, timeout: 6000 });

	}


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

	function markup() {

		$('div.section div.sidebar:first-child ul.tags h4 a').each(function() { truncate($(this), 50); });

/* Japanese Translations */

		if (page == "signup") {

			$('#optin em:contains("Custom")').parent('label').addClass('custom').hide();
			$('#optin #mailing_list_entry_custom').val('Signup');
			
			$('div.widget-subscribe.JA input#mailing_list_entry_email').siblings('em').text('メールアドレス');
			$('div.widget-subscribe.JA input#mailing_list_entry_mobile').siblings('em').text('携帯電話番号');
			$('div.widget-subscribe.JA input#mailing_list_entry_mobile').siblings('small').text('(任意)');
			$('div.widget-subscribe.JA input#mailing_list_entry_postal_code').siblings('em').text('郵便番号');
			$('div.widget-subscribe.JA select#mailing_list_entry_country').siblings('em').text('国');
			$('div.widget-subscribe.JA select#mailing_list_entry_country > option').text('国・地域を選択');
			$('div.widget-subscribe.JA select#mailing_list_entry_country optgroup').attr('label', '一般的な国');
			$('div.widget-subscribe.JA select#mailing_list_entry_country optgroup + optgroup').attr('label', 'その他');

			$('div.widget-subscribe.JA').parents('body').find('div.widget-alert').each(function() {
			
				if ($(this).find('h3').text() == "Sorry, some additional information is required") {
				
					$(this).find('h3').text('正しく必要項目').css({
					
						'width':		'162px',
						'height':		'24px',
						'text-indent': 	'-5000px',
						'background':	'url(' + asset_host + '/2/images/section-signup/h3-required-ja.gif) no-repeat',
						'margin-left':	'auto',
						'margin-right':	'auto'
					
					});
				
				} else if ($(this).find('h3').text() == "You are already registered!") {
				
					$(this).find('h3').text('登録完了！').css({
					
						'width':		'109px',
						'height':		'24px',
						'text-indent': 	'-5000px',
						'background':	'url(' + asset_host + '/2/images/section-signup/h3-registered-ja.gif) no-repeat',
						'margin-left':	'auto',
						'margin-right':	'auto'
					
					});
				
				}

				if ($(this).find('p').text() == "Please double-check the page below for any missing or wrong information") {
				
					$(this).find('p').text('再度登録内容に間違いが無いかご確認してください。');
				
				} else if ($(this).find('p').text() == "Please double-check the page below for any missing or wrong information") {
				
					$(this).find('p').text("(It's Hard) Letting You Go - Live from O2 Arena へアクセス");
				
				}
			
			});

			$('div.widget-subscribe.JA label.error strong').each(function() {
			
				if ($(this).text() == "This is Required" || $(this).text() == "Invalid Email Address") {

					$(this).text('必須項目');
				
				}
			
			});
		
		}
		
		if (page == "bj-videos") {

			$('div.JA').parents('body').find('div.widget-alert').each(function() {
			
				if ($(this).find('h3').text() == "Thanks for Joining the Mailing List!") {
				
					$(this).find('h3').text('BonJovi.comへようこそ！').css({
					
						'width':		'285px',
						'height':		'24px',
						'text-indent': 	'-5000px',
						'background':	'url(' + asset_host + '/2/images/section-signup/h3-welcome-ja.gif) no-repeat',
						'margin-left':	'auto',
						'margin-right':	'auto'
					
					});
				
				}

				if ($(this).find('p').text() == "Please check your e-mail to confirm your subscription.") {
				
					$(this).find('p').text('メールをチェックして本登録をして下さい。');
				
				}
			
			});
		
		}


/* Portuguese Translations */
	
	$('#page-preshow.portuguese').find('.widget-subscribe em:eq(2)').html("Número de telemóvel");
	$('#page-preshow.portuguese').find('.widget-subscribe em:eq(3)').html("Código Postal");
	$('#page-preshow.portuguese').find('.widget-subscribe em:eq(4)').html("País");
	$('#page-preshow.portuguese').find('.widget-subscribe small').html("(opcional)");
	$('#page-preshow.portuguese').find('.widget-subscribe input.save').attr('src', asset_host + '/2/images/actions/input-entertowin-pt.png');

asset_host + 'bonjovi/2/images/actions/input-entertowin.png'
	
/* Featured Content Structure Changes */

		$('div.section.featured .widget-editorial.browse. ul.leads > li').each(function() {

			if ($(this).children('img').length > 0) {
		
				var href = $(this).children('h4').children('a').attr('href');
				$(this).children('img').wrap('<a class="image" href="' + href + '"></a>');
				truncate($(this).children('h4').children('a'), 80);
			
			}
		
		});
		
		
/* Editorial > Leads */

		$('ul.leads > li > img + h4').each(function() { $(this).insertBefore($(this).siblings('img')); });
		$('ul.leads > li > a.comments:visible').each(function() { $(this).wrap('<div class="social"></div>'); });
		

/* News Poll */

		$('#poll h4 + a.comments:visible').each(function() { $(this).wrap('<div class="social"></div>'); });
		$('#poll tbody.votes tr:not(:first)').each(function() { $(this).children('td:first').children('strong:not(:contains("Your Vote:"))').prepend('Your Vote: ') });
			

/* Move Narrow Columns' Actions Under Heading */	
	
		$('.sidebar div.browse:not(#introduction) > ul.actions, .left div > ul.actions').each(function() { $(this).insertAfter($(this).siblings('h3')); });
	
	
/* Language Changes */	
	
		$('#qas ul.leads a.action.display').text('Read Answer');
		$('.widget-subscribe.modify ul.actions .submit a').text('Sign Up');
		$('.widget-event.browse.program.featured ul.actions a.browse').text('Find More Tickets');
		$('#page-optin .widget-subscribe ul.actions a').text('Continue');

		
/* Q&A */

		if ($('#qas ul.actions a.ask').length == 0) $('#qas > ul.actions').prepend('<li><a class="action ask" href="/qas#ask">Ask a Question</a></li>');


/* Events */
		
		$('div.widget-event.featured ul.tickets li').each(function() {
		if ($(this).children('span').length > 0 || $(this).children('a').length > 0) {
		$(this).children('span').text( $(this).children('span').text().replace(/Pre-sale/, 'Fan Club Pre-sale').replace(/VIP Ticket/, 'Fan Club VIP Package') );
		$(this).children('a').text( $(this).children('a').text().replace(/Pre-sale/, 'Fan Club Pre-sale').replace(/VIP Ticket/, 'Fan Club VIP Package') );
		}
		});
	

/* Reword Comments Message on Notice Page */

		$('body#page-new div.widget-alert h3').text('Thank You For Your Feedback!');
		
		
/* Page BJ-Videos Alert */	

		$('div.widget-alert h3:contains(Mailing)').text('Welcome to the Bonjovi.com Community!');
		$('<p>Go to <a href="/photos/crowd_shots">Exclusive 2011 Live Gallery</a> now.</p>').insertAfter('#page-signup:not(".japanese") div.widget-alert h3:contains(registered)');
		$('<pWatch <a href="/bj-videos/all/its_hard_hard_letting_you_go__live_from_o2_arena">(It\'s Hard) Letting You Go - Live from O2 Arena</a></p>').insertAfter('#page-signup.japanese div.widget-alert h3:contains(登録完了！)');
		$('<p>Watch <a href="/bj-videos/all/its_hard_hard_letting_you_go__live_from_o2_arena">(It\'s Hard) Letting You Go - Live from O2 Arena</a></p>').insertAfter('#page-signup-09-14-10 div.widget-alert h3:contains(registered)');


/* Localized Welcome Message */	

		$('#page-index #introduction ul.actions a').each(function() {
		
			$(this).attr('href', 'http://www.bonjovi.com').text('Go to the English Site');
		
		});


	}


/* FUNCTION: FEATURED MERCHANDISE
--------------------------------------------------------------------------- */

	function merchandise() {
		
		if ($('div.merch #bonjovionline').length > 0) {
				
			if ($('div.sidebar div.merch').length > 0) {
				
				var _so = new SWFObject(asset_host + '/2/flash/merchandise-skyscraper.swf', 'bonjovionline_featured', '144', '695', '#FFFFFF');
				_so.addParam('allowScriptAccess', 'always');
				_so.addParam('wmode', 'transparent');
				_so.write('bonjovionline');

			} else {
				
				var _so = new SWFObject(asset_host + '/2/flash/merchandise.swf', 'bonjovionline_featured', '780', '250', '#FFFFFF');
				_so.addParam('allowScriptAccess', 'always');
				_so.addParam('wmode', 'transparent');
				_so.write('bonjovionline');
						
			}
			
		}

	}

	
/* FUNCTION: HEADER
--------------------------------------------------------------------------- */

	function header() {
	
		$('div#network ul.menu strong, div#network li.joinus strong, div#network li.store strong').click(function() {
		
			if ($(this).parent().hasClass('joinus')) {
				var $menu = $(this).parent();
			} else if ($(this).parent().hasClass('store')){
				var $menu = $(this).parent();
			} else {
				var $menu = $(this).parent().parent().parent();
			}

			var $bar = $menu.parent();
			var original = $bar.css('width');

			$bar.animate({ width: '50px' }, 'fast', function() {

				if ($menu.hasClass('open')) {
					$menu.removeClass('open');
					$menu.siblings('li').show();
				} else {
					$menu.siblings('li').hide();
					$menu.addClass('open');
				}

				$bar.animate({ width: original }, 'fast');

			});
			
			return false;

		});

		$('div.media.photos ul.photos').cycle({ fx: 'scrollLeft', speed: 400, timeout: 3000 });

		var so = new SWFObject(asset_host + '/2/images/header/videos.swf', 'videos_button', '100', '50', '9', '#000000');
		if ($('#videos_button').length > 0) so.write('videos_button');

		if (geoLocation.subcontinent.match('Europe')) {
			$('#navigation li.store a').attr('href','http://www.bonjovi-store.eu');			
		}

	}
	
	
/* FUNCTION: TWITTER
--------------------------------------------------------------------------- */

	function twitter() {
	
		$('.twitter').tweet({
		username: 'bonjovi',
		count: 10
		});

	}
	
	function twitterCallback() {
		
		// Remove @Replies
		$('ul.tweet_list > li').each(function() {
		var tweet = $(this).children('span').children('a:first-child').text();
		if (tweet.match(/^\@/)) $(this).remove();		
		});
		
		// Slideshow
		if ($('.tabbed .tweet_list').length > 0) $('.tabbed .tweet_list').cycle({ fx: 'scrollUp', speed: 300, timeout: 7000, before: retweet, pause: 1 });
		if ($('div.browser div.sidebar .tweet_list').length > 0) $('div.browser div.sidebar .tweet_list').cycle({ fx: 'scrollUp', speed: 300, timeout: 7000, before: retweet, pause: 1 });
		
	}
	
	function retweet() {
	
		// Build Retweet Link
		var user = "bonjovi";
		var tweet = $(this).find('.tweet_text').text();
		var url = "http://twitter.com/?status=RT @" + user + " " + tweet;
		var url = encodeURI(url);
		$(this).closest('div').find('a.retweet').attr('href', url);
	
	}
	

/* FUNCTION: FOLLOWING COMMENT BOX
----------------------------------------------------------------------------- */

	function commentBox() {
										
		// Positions & Heights
		var boxTop = $('#comments div.sidebar div.widget-comment.modify').offset().top - parseFloat($('#comments div.sidebar div.widget-comment.modify').css('margin-top').replace(/auto/, 0));
		var boxBottom = boxTop + $('#comments div.sidebar div.widget-comment.modify').innerHeight();
		var boxHeight = boxBottom - boxTop;
		var floor = $('#comments div.container').offset().top + $('#comments div.container').height() - parseFloat($('#comments div.sidebar div.widget-comment.modify').css('margin-top').replace(/auto/, 0));

		$(window).scroll(function() {
						
			// Y Position of Scroll
			var viewportTop = $(this).scrollTop();
		
			// Is that Below the Form?
			if (viewportTop >= boxTop && viewportTop < floor - boxHeight) {

				$('#comments div.sidebar div.widget-comment.modify').addClass('floating').removeClass('bottom');

			} else if (viewportTop > floor - boxHeight) {

				$('#comments div.sidebar div.widget-comment.modify').addClass('bottom').removeClass('floating');
				
			} else {
		
				$('#comments div.sidebar div.widget-comment.modify').removeClass('floating');

			}
		
		});	
		
	}
	
	
/* FUNCTION: COMMENT CHARACTER COUNTER
----------------------------------------------------------------------------- */	
	
	function commentCounter() {
		
		var max = 700;
		$('div.widget-comment.modify small').prepend('<strong><var>' + max + '</var> characters left<span> / </span></strong>');
		$('div.widget-comment.modify textarea').keyup(function() { characterCount($(this), max) });
		$('div.widget-comment.modify textarea').change(function() { characterCount($(this), max) });	
		characterCount($('div.widget-comment.modify textarea'), max);

	}

	function characterCount(editor,max) {

		var count = max - editor.val().length;

		if (count > 0) {

			$(editor).parent().children('small').children('strong').children('var').text(count);
			$(editor).parent().children('small').children('strong').children('var.error').removeClass('error');

		} else {

			$(editor).parent().children('small').children('strong').children('var').text(count);
			$(editor).parent().children('small').children('strong').children('var').addClass('error');

		}

	}
	
	
/* FUNCTION: AddThis - Leads
----------------------------------------------------------------------------- */

	function addThisLeads(exception) {
		
		var addthis_config = {
			
		    data_track_clickback: true
		
		}
						
		if (exception == 'home') {

			$('ul.announcements li.news').each(function() {
			
				var editorialURL = $(this).children('h4').children('a').attr('href');
				var editorialTitle = $(this).children('h4').text();
				
				$(this).append('<div class="social"><a rev="canonical" class="addthis_button-leads" addthis:url="' + site_host + editorialURL + '" addthis:title="Bon Jovi &#134; ' + editorialTitle + '">Share This</a></div>');

			});
		
			$('ul.announcements li.tweet').each(function() {
		
				// Build Retweet Link
				var user = "bonjovi";
				var tweet = $(this).find('h4').text();
				var url = "http://twitter.com/?status=RT @" + user + " " + tweet;
				var url = encodeURI(url);
		
				$(this).append('<div class="social"><a class="retweet" href="' + url + '" target="_blank">Retweet This</a></div>');
	
			});
		
		} else {
		
			$('ul.leads:not(".section-home ul.leads") > li').each(function() {
			
					var editorialURL = $(this).children('h4').children('a').attr('href');
					var editorialTitle = $(this).children('h4').text();
	
					$(this).children('div.social').each(function() { 
						
						$(this).append('<a rev="canonical" class="addthis_button-leads" addthis:url="' + site_host + editorialURL + '" addthis:title="Bon Jovi &#134; ' + editorialTitle + '">Share This</a>');
						
					});		
	
			});
			
			$('#poll:not(".section-home #poll") div').each(function() {
						
					var pollURL = $(this).children('h4').children('a').attr('href');
					var pollTitle = $(this).children('h4').text();
	
					$(this).children('div.social').each(function() { 
						
						$(this).append('<a rev="canonical" class="addthis_button-leads" addthis:url="' + site_host + pollURL + '" addthis:title="Bon Jovi &#134; ' + pollTitle + '">Share This</a>');
						
					});		
	
			});
		
		}
		
	}
	
		
/* FUNCTIONS: THE CIRCLE COUNTDOWN
-----------------------------------------------------------------------------*/ 

	function countdown() {

		// Countdown
		/* var _so = new SWFObject(asset_host + '/2/flash/geoCountdown.swf', 'countdown_flash', '100%', '100%', '#000000');
		_so.addParam('allowScriptAccess', 'always');
		_so.addParam('wmode', 'transparent');
		_so.addVariable('localXML', asset_host + '/2/xml/nationalTime.xml');
		_so.write('timer'); */

		// Listen
		var _so = new SWFObject(asset_host + '/2/flash/jbj_stream.swf', 'countdown_preview', '100%', '100%', '#000000');
		_so.addParam('allowScriptAccess', 'always');
		_so.addParam('wmode', 'transparent');
		_so.write('preview');

		$('#countdown #listen').show();

	}

	// CALLED FROM SWF
	function localizedCountdown(country) {
				
		setTimeout(function() {

			switch (country) {

				case 'CH':
				case 'DE':
				case 'AT':

					$('#countdown').addClass('de');
					break;

				case 'IE':
				case 'UK':
				case 'GB':

					$('#countdown').addClass('uk');
					break;

				case 'JP':

					$('#countdown').addClass('jp');
					break;

				case 'IT':
				case 'AN':

					$('#countdown').addClass('it');
					break;

				default:

					if (language == "es") {

						$('#countdown').addClass('es');

					} else if (language == "nl") {

						$('#countdown').addClass('nl');

					} else if (language == "pt") {

						$('#countdown').addClass('pt');

					} else {

						$('#countdown').addClass('us');

					}

			}

		}, 300);

	}

	function countdownOver() { $('body').addClass('countdown_over'); }
	

/* FUNCTIONS: IE HOME PAGE FIX
-----------------------------------------------------------------------------*/ 

	function ieFix() {

		$('.tabbed .ad, .tabbed .twitter').fadeIn('slow');

	}
	

/* FUNCTIONS: 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") {

			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") && (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').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") {
			
			$('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();
			
		});		
		
	}
	
	
/* EXTERNAL LINKS
----------------------------------------------------------------------------- */

	function externalLinks() {
	
		$('a[rel=external]').click(function() {

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

			return false;

		});
		
	}
	

/* MSG COUNTDOWN
--------------------------------------------------------------------------- */

	function msgCountdown() {

		if ((geoLocation.length == 0) || (geoLocation.country == "US") || (geoLocation.country == "CA")) {

			$("#featured ul.tabs li.msg").css('display', 'inline');

		} else {

			// Removing Geo-restricted Tab
			$("#featured #msg").remove();
			$("#featured ul.tabs li.msg").remove();

		}

	}


/* SPECIAL EDITION RE-RELEASES
--------------------------------------------------------------------------- */

	function specialEdition() {

		if ((geoLocation.country == "US") || (geoLocation.country == "CA")) {

			$("#featured #special-edition").addClass('may-11');

		} else if (geoLocation.country == "JP") {

			$("#featured #special-edition").addClass('may-20');

		} else if ((geoLocation.country == "DE") || (geoLocation.country == "AU") || (geoLocation.country == "AT") || (geoLocation.country == "CH") || (geoLocation.country == "ZA") || (geoLocation.country == "IT")) {

			$("#featured #special-edition").addClass('may-21');

		} else if ((geoLocation.country == "BE") || (geoLocation.country == "NO") || (geoLocation.country == "NZ") || (geoLocation.country == "HK") || (geoLocation.country == "MY") || (geoLocation.country == "SG") || (geoLocation.country == "PL") || (geoLocation.country == "CZ") || (geoLocation.country == "RU") || (geoLocation.country == "DK") || (geoLocation.country == "GB") || (geoLocation.country == "FR")){

			$("#featured #special-edition").addClass('may-24');

		} else if ((geoLocation.country == "BR") || (geoLocation.country == "ES") || (geoLocation.country == "AR") || (geoLocation.country == "MX") || (geoLocation.country == "KR")) {

			$("#featured #special-edition").addClass('may-25');

		} else if ((geoLocation.country == "SE") || (geoLocation.country == "FI")) {

			$("#featured #special-edition").addClass('may-26');

		} else if (geoLocation.country == "NL") {

			$("#featured #special-edition").addClass('may-28');

		} else if (geoLocation.country == "PH") {

			$("#featured #special-edition").addClass('june-1');

		} else if (geoLocation.country == "TW") {

			$("#featured #special-edition").addClass('june-11');

		} else if (geoLocation.country == "ID") {

			$("#featured #special-edition").addClass('june-30');

		}

	}	
	
	
/* FEATURED VEVO PLAYER WHAT DO YOU GOT
--------------------------------------------------------------------------- */

	function vevoPlayer() {

		if ((geoLocation.country == "US") || (geoLocation.country == "CA")) {
			
			// Removing CT video
			$("#featured #what_do_you_got div.main #vevoplayer").show();
			$("#featured #what_do_you_got div.main div.video").remove();

		} else {

			// Removing VEVO Player
			$("#featured #what_do_you_got div.main div.video").show();
			$("#featured #what_do_you_got div.main #vevoplayer").remove();

		}


	}	
	
	
/* MARKUP CHANGES FOR SIGNUP PAGE (DE)
--------------------------------------------------------------------------- */	

	function signUp() {

		// Page Signup DE
		$('#optin.signup.DE label em:contains(E-mail)').text('E-Mail-Adresse');
		$('#optin.signup.DE label em:contains(Mobile)').text('Handynummer');
		$('#optin.signup.DE label em:contains(ZIP)').text('Postleitzahl');
		$('#optin.signup.DE label em:contains(Country)').text('Land');			
			
		// Page Signup Alert DE
		$('#page-signup_de div.widget-alert h3:contains(registered)').text('Du bist bereits registriert');
		$('#page-signup_de div.widget-alert p:contains(Watch)').remove();
		$('<p>Schau Dir hier das Video <a href="/bj-videos/all/its_hard_hard_letting_you_go__live_from_o2_arena">(It\'s Hard) Letting You Go - Live from O2 Arena</a> an.</p>').insertAfter('#page-signup_de div.widget-alert h3:contains(registriert)');

		// Page Bj-videos DE
		$('#page-bj-videos_de div.widget-alert.success h3').text('Herzlich Willkommen in der Bon Jovi Community!');


	}
	
	
/* FEATURED GREATEST HITS CHANGE LINK URL
--------------------------------------------------------------------------- */

	function greatestHits() {

		if (geoLocation.country == "US") {
			
			$('#featured #greatest-hits a.restoftheworld').remove();
			$('<a class="us" href="http://www.amazon.com/gp/product/B004A2V3K0?ie=UTF8&tag=bojo07-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=B004A2V3K0">Buy Bon Jovis Greatest Hits!</a>').appendTo('#featured #greatest-hits div.main');
		} 
		
	}
	
	
/* FUNCTION: Bon Jovi Yourself
----------------------------------------------------------------------------- */

	function bonJoviYourself() {

		if  (geoLocation.country == "DE") {

			$("#featured #bonjovi-yourself").addClass('german');
			$('#featured #bonjovi-yourself div.main a').attr('href','http://www.bon-jovi-yourself.de/');

		}
		
	}
	
	
/* MARKUP CHANGES FOR PRESHOW PAGE
--------------------------------------------------------------------------- */	

	function preShow() {
		
		$('#page-preshow #optin em:contains("Custom")').parent('label').addClass('custom').hide();
		$('#page-preshow #optin #mailing_list_entry_custom').val('preshow');
		$('#page-preshow div.widget-alert h3:contains(registered)').text('You are already registered for the Bon Jovi community and entered for the contest! Thanks for being part of the Bon Jovi community.');
		$('#page-preshow div.widget-alert h3:contains(Welcome)').text('You have successfully entered the contest and joined the Bon Jovi community! Please check your e-mail for confirm your subscription.');

	}


/* MARKUP CHANGES FOR LIVE 2011 CONTEST PAGE
--------------------------------------------------------------------------- */	

	function live2011Contest() {

		$('#page-live2011_contest #optin em:contains("Custom")').parent('label').addClass('custom').hide();
		$('#page-live2011_contest #optin #mailing_list_entry_custom').val('Live 2011 Contest');

	}


/* SUB-NAVIGATION CATEGORY TITLE BAR
--------------------------------------------------------------------------- */	

	function title() {

		$('#navigation > li').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });

	}


/* FUNCTION: TICKET DESIGN CONTEST FOR CROATIA
---------------------------------------------------------------------------- */

	function croatia() {

		// Copy changes

		$('#upload input.add').val('Pošalji fotografiju');
		$('#upload a.submit').text('Pošalji fotografiju');

		$('#upload div.group.upload h4').text('Pošalji fotografiju');
		$('#upload div.group.upload p').text('Fotografije moraju biti u JPEG formatu i bit će automatski odrezane ili smanjene po potrebi.');
		$('#upload div.group.upload label em').text('Odaberi .JPG datoteku');

		$('#upload div.group.details h4').text('Detalji');
		$('#upload div.group.details label:eq(0) em').text('Naslov');
		$('#upload div.group.details label:eq(1) em').text('Datum snimke');
		$('#upload div.group.details #photo_date_taken_2i option:eq(0)').text('Mjesec');
		$('#upload div.group.details #photo_date_taken_3i option:eq(0)').text('Dan');
		$('#upload div.group.details #photo_date_taken_1i option:eq(0)').text('Godina');
		$('#upload div.group.details #photo_date_taken_1i + small').text('Opcionalno');
		$('#upload div.group.details fieldset #terms_conditions + em').html('Slažem se s pravilima za predaju fotografija i crteža navedenima u <a href="/terms">Uvjetima korištenja usluge</a>.');
		$('#upload div.group.details fieldset #thread_disabled + em').text('Ne želim da drugi mogu komentirati ovu fotografiju');

		$('div.widget-alert.success h3').text('Slanje je uspješno');
		$('div.widget-alert.success p').html('Informacije o rezultatima prati na <a href="http://www.facebook.com/BonJovi" target="_blank">Bon Jovi Facebook stranicama</a>!');
		
	}


/* FUNCTION: TICKET DESIGN CONTEST FOR OTHER COUNTRIES
---------------------------------------------------------------------------- */

	function ticketdesigns() {

		// Copy changes
		$('div.widget-alert.success h3').text('Upload Successful');
		$('div.widget-alert.success p').html('Follow <a href="http://www.facebook.com/BonJovi" target="_blank">Bon Jovi\'s Facebook page</a> for information about the winners!');

		// Form submission
		if ($('#upload').length > 0) {
		
			var oldTag = $('#upload').siblings('input[name="tag"]').val();
			var oldAppend = $('#upload').siblings('input[name="append"]').val();
			var oldSuccessPage = $('#upload').siblings('input[name="photo[success_page]"]').val();
		
			// Markup changes
			$('#upload .details h4').after('<label class="event"><em>City</em><select id="event_taken_2i"></select></label><br />');
			$('#upload .details select#event_taken_2i').append('<option value="">Choose A City</option>');

			// Populate dropdown
			$('#events tbody tr').each(function(index) {
			
				var eventDate = $(this).children('td.date').children('a').children('strong').text();
				var eventCity = $(this).children('td.details').children('a').children('strong').text();
				var eventTag;

				$.each($(this).children('td.details').children('a').attr('href').replace(/\//, '-').split('-'), function(index, value) {
				
					if (value.match('__')) eventTag = value;
				
				});
			
				$('#upload .details select#event_taken_2i').append('<option value="' + (parseInt(index) + 1) +'" tag="' + eventTag + '">' + eventDate + ' - ' + eventCity + '</option>');
			
			});

			// Update form values
		    $("#upload .details select#event_taken_2i").change(function () {

				var selectedTag = $('#upload .details select#event_taken_2i option:selected').attr('tag');
				
				if ($('#upload .details select#event_taken_2i option:selected').val() == '') {

					$('#upload').siblings('input[name="tag"]').val(oldTag);
					$('#upload').siblings('input[name="append"]').val(oldAppend);
					$('#upload').siblings('input[name="photo[success_page]"]').val(oldSuccessPage);
				
				} else {
				
					$('#upload').siblings('input[name="tag"]').val(oldTag + '-' + selectedTag);
					$('#upload').siblings('input[name="append"]').val(oldAppend + '-' + selectedTag);
					$('#upload').siblings('input[name="photo[success_page]"]').val(oldSuccessPage + '-' + selectedTag);

				}

	        })
	
			// Error detection			
			$('#upload li.submit *').click(function() {
			
				if ($('#upload .details select#event_taken_2i option:selected').val() == '') {

					$('label.event:not(.error)').addClass('error').append('<strong>Required</strong>');

					return false;									
				
				} else {
				
					$('#upload').parents('form').submit();
				
				}
				
				return false;
			
			});
		
		}
	
	}
