/* BRANDON FLOWERS MUSIC */
/* Section Home Stylesheet
--------------------------------------------------------------------------------- */


	$(window).load(function() {
	
		// POPUP MOBILE SIGN UP
		if (page == "index") {
		
			$('a.mobile-signup').click(function() {
		
				window.open('/mobile-signup','mobile_signup','width=355,height=168,menubar=no,scrollbars=no,resizable=no,location=no');		
				return false;
		
			});
		
		}
		
		markup();
		tabs('removeEmptyTabs');
		comments();
		cufon();
		signinOverlay();
		emailOverlay();
		truncate("td.location a", 28);
		truncate("td.details a", 28);
		truncate("#page-index #news ul.headlines li a", 70);
		truncate("#page-index #upcoming ul > li > h4 > a > span", 28);
		truncate("#page-videos ul#clips li > div > a", 64);
		
		// PLUGIN: CLIQUE FORMS (Adds text into input forms)
		$('#mailing_list_entry_email').cliqueForms({ placeholder: "Enter your e-mail address" });
		
		// PLUGIN: CLIQUE ACTIONS (Replaces submit buttons with text links)
		try { $('input[type=submit]').cliqueActions(); } catch (error) { alert('Error: Missing Clique Actions Plugin'); }
		
	});
	
	
/* FUNCTION: MARKUP CHANGES
----------------------------------------------------------------------------- */


	function markup() {
	
		$('a.action.browse').text("See All");
		
		//Section Home		
		$('#page-index a.tally.going span').text("Attending");
		
		//Section Tour
		$('table.events tr:eq(1)').addClass("one");
		$('table.events tr:eq(2)').addClass("two");
		$('table.events tr:eq(3)').addClass("three");
		$('table.events tr:eq(4)').addClass("four");
		$('table.events tr:eq(5)').addClass("five");
		$('table.events tr:eq(6)').addClass("six");
		$('table.events tr:eq(7)').addClass("seven");
		$('td.tallies.rsvp a span').text("Attending");	
		$('li.toggle.going em').text("I'm Attending");
		$('li.toggle.notgoing em').text("I Can't Attend");
		$('#page-index div.widget-event.placeholder p').text("Tour Dates TBD");
		$('.section-tour div.widget-event.placeholder p').text("Sign up to receive tour date announcements");
		$('<a class="email-signup" href="#">Sign Up to Receive Tour Date Announcements</a>').insertAfter(".section-tour div.widget-event.placeholder p");
				
		//Section News
		$('#page-news ul.headlines li a:not(a.comments)').wrap("<div></div>");
		$('#page-news ul.headlines li:eq(0)').addClass("one");
		$('#page-news ul.headlines li:eq(1)').addClass("two");
		$('#page-news ul.headlines li:eq(2)').addClass("three");
		$('#page-news ul.headlines li:eq(3)').addClass("four");
		$('#page-news ul.headlines li:eq(4)').addClass("one");
		$('#page-news ul.headlines li:eq(5)').addClass("two");
		$('#page-news ul.headlines li:eq(6)').addClass("three");
		
		//Section Photos
		$('#page-photo dd.related').appendTo("div.widget-photo.display ul.actions");
		$('#page-photos ul.photos li:eq(0)').addClass("one");
		$('#page-photos ul.photos li:eq(1)').addClass("two");
		$('#page-photos ul.photos li:eq(2)').addClass("three");
		$('#page-photos ul.photos li:eq(3)').addClass("four");
		$('#page-photos ul.photos li:eq(4)').addClass("five");
		$('#page-photos ul.photos li:eq(5)').addClass("six");
		$('#page-photos ul.photos li:eq(6)').addClass("seven");
		$('#page-photos ul.photos li:eq(7)').addClass("eight");
		$('#page-photos ul.photos li:eq(8)').addClass("nine");
		$('#page-photos ul.photos li:eq(9)').addClass("ten");
		$('#page-photos ul.photos li:eq(10)').addClass("eleven");
		$('#page-photos ul.photos li:eq(11)').addClass("twelve");
		$('#page-photos ul.photos li:eq(12)').addClass("thirteen");
		$('#page-photos ul.photos li:eq(13)').addClass("fourteen");
		$('#page-photos ul.photos li:eq(14)').addClass("fifteen");
		$('#page-photos ul.photos li:eq(15)').addClass("sixteen");
		$('#page-photos ul.photos li:eq(16)').addClass("seventeen");
		$('#page-photos ul.photos li:eq(17)').addClass("eighteen");
		$('#page-photos ul.photos li:eq(18)').addClass("nineteen");
		$('#page-photos ul.photos li:eq(19)').addClass("twenty");
		$('#page-photos ul.photos li:eq(20)').addClass("twentyone");
		$('#page-photos ul.photos li:eq(21)').addClass("twentytwo");
		$('#page-photos ul.photos li:eq(22)').addClass("twentythree");
		$('#page-photos ul.photos li:eq(23)').addClass("twentyfour");
		$('#page-photos ul.photos li:eq(24)').addClass("twentyfive");
		$('#page-photos ul.photos li:eq(25)').addClass("twentysix");
		$('#page-photos ul.photos li:eq(26)').addClass("twentyseven");
		
		$('div.widget-photo img').attr("title", "");
		
		
		//Section Videos
		$('<em></em>').prependTo("#page-videos ul#clips li > a");
		
		
		//Comments
		$("#comments div.post span a").attr("href", "#");
		$("#comments ul.comments li div.member a").attr("href", "#")
			
	}
	
	
/* FUNCTION: CUFON REPLACEMENTS
----------------------------------------------------------------------------- */


	function cufon() {
		
		var eurostile_medium = [
		
			'a.prompt',
			'#event h4',
			'div.widget-photo.display h4',
			'#rsvp h3',
			'h2',
			'.section-legal h3',
			'.section-legal h4',
			'#page-account h3',
			'#page-account h4',
			'#membership h3',
			'#page-welcome div.widget-account h3'
		
		];

		var eurostile_condensed_bold = [ 
				

			
		];
		
		Cufon.replace(eurostile_medium, { fontFamily: 'Eurostile', hover: true });
		Cufon.replace(eurostile_condensed_bold, { fontFamily: 'Eurostile', hover: true });	
		
		$(eurostile_medium.toString()).css('visibility', 'visible');
		$(eurostile_condensed_bold.toString()).css('visibility', 'visible');

				
	}



/* COMMENTS
----------------------------------------------------------------------------- */


	function comments() {
	
		$('#comments a.prompt.post').click(function() {
		
			$('#post').show().find('textarea').focus();
			$(this).hide();
		
			return false;
		
		});
	
	}

	
	
/* 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);
		Cufon.refresh();
		}
		});
		
	}	
	
	
/* 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
		$('a.prompt.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();
			
		});		
		
	}	
	
	
/* FUNCTIONS: EMAIL SIGN UP OVERLAY
----------------------------------------------------------------------------- */


	function shrinkFlash() {
		
		$('div.widget-media div.flash').addClass("shrink");
		
		}
	
	function expandFlash() {
		
		$('div.widget-media div.flash').removeClass("shrink");
		
		}
		
	function emailOverlay() {	
	
		// SET HEIGHT OF OVERLAY
		$('#email-overlay').css('height', $(document).height());
		
		// OPEN OVERLAY
		$('.email-signup').click(function() {
										
			$('body').addClass('overlay');
			$('#email-overlay').fadeIn('fast');
			
			if ((navigator.userAgent.match('MSIE 7')) || (navigator.userAgent.match('MSIE 8'))) {
				
			shrinkFlash();
			
			}
			
			return false;
			
		});
		
		// CLOSE OVERLAY
		$('#optin a.close').click(function() {
			
			$('body').removeClass('overlay');
			$('#email-overlay').fadeOut('fast');
			
			if ((navigator.userAgent.match('MSIE 7')) || (navigator.userAgent.match('MSIE 8'))) {
				
			expandFlash();
			
			}
			
			return false;
				
		});
						
	}	
		
	
	



	
	

