/* 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; });
	
	});
	
	$(window).load(function() {

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

		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();

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

		// Facebook Javascript SDK
		if (window.FB) {
			FB.init({
			
				xfbml: true
			
			});
		}

	});
	
	
/* FUNCTION: CUFON
---------------------------------------------------------------------------- */

	function hideCufon() {
	
		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',
		'#title ul 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)',
		'.widget-event.program h4 strong',
		'.widget-event.program ul.tickets .available a',
		'div > ul.actions a:not(.download a, #signin 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'
		];
		
		tradeGothicExtended = [
		'.content h2:not(.story h2, .backstagejbj h2)',
		'#title h2:not(.backstagejbj #title h2)',
		'.widget-event.program h3',
		'.section > div > h3:not(.section-store div.sidebar > h3)',
		'.section > form > div > h3',
		'.widget-event.program a.date',
		'.widget-editorial:not(#qas) 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'
		];
		
		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); });
	
	
/* 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>Watch <a href="/bj-videos/all/hard_letting_you_go__live_from_o2_arena">Hard Letting You Go - Live from O2 Arena</a></p>').insertAfter('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() {
		
		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('div.social').each(function() { 
					
					$(this).append('<a class="addthis_button-leads" addthis:url="' + site_host + editorialURL + '" addthis:title="Bon Jovi &#134; ' + editorialTitle + '">Share This</a>');
					
				});		

		});
		
		$('#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 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" && 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').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').show();
			$('#signin-overlay #signin div.signin').hide();
			
		});		
		
	}
	
	
/* 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');

		}

	}	