/* VANESSA HUDGENS */
/* JQUERY Functions
----------------------------------------------------------------------------- */


	function closeViewer() {

	$('#enlarged').fadeOut();

	return false;		

	}
	

/* LOAD FUNCTION / ELEMENT INITIALIZATION
----------------------------------------------------------------------------- */


	$(window).load(function() {



/* ENLARGED PHOTO VIEWER
----------------------------------------------------------------------------- */


	if (section == "vanessa") {

		$('#page-vanessa ul.photos').css('visibility','visible');
		$('#layout').prepend('<div id="enlarged"><div id="viewer"><div id="crop"><img /></div><h4>Caption Goes Here</h4><a class="action close" href="#">Close</a></div></div>');
		$('#enlarged').hide();

		$('div.widget-photo.thumbnails ul.photos li > a').click(function() {

			var photo = $(this).children('img').attr('src').replace('thumb.',''); 
			var caption = $(this).children('img').attr('title');

			if ($('#enlarged').hasClass('portrait')) {

				$('#enlarged').removeClass('portrait');

			}

			if ($(this).children('img').hasClass('portrait')) {

				$('#enlarged').addClass('portrait');

			}

			$('#enlarged img').attr('src',photo);
			$('#enlarged img').attr('title',caption);
			$('#enlarged h4').text(caption);
			$('#enlarged').fadeIn();

			return false;

		});

		$('#enlarged div img').click(closeViewer);
		$('#enlarged div a.close').click(closeViewer);


	}


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


	});
	

/* Functions
----------------------------------------------------------------------------- */

	$(document).ready(function() {
		

/* COPPA COMPLIANCE ON MAILINGLIST
----------------------------------------------------------------------------- */

		// DISABLING DOB DROPDOWNS IF PARENT CONSENT FIELD IS PRESENT
		if ($('#official-lists input#mailing_list_entry_parent_email').length > 0) {
			
			$('#official-lists').find('select').attr('disabled', 'disabled').parent().addClass('disabled');
			
			// Setting Cookie if under 13 years old
			var month = $('#official-lists select#mailing_list_entry_birthday_2i').val();
			var day = $('#official-lists select#mailing_list_entry_birthday_3i').val();
			var year = $('#official-lists select#mailing_list_entry_birthday_1i').val();

			$.cookie('date-of-birth', month + '-' + day + '-' + year, {expires: 365, domain: 'sparkart.net', path: '/'});
						
		}
			
		
		// PRE-FILL DOB DROPDOWNS AND DISABLE IF COOKIE IS PRESENT (FOR RETURN VISITORS AND PAGE RELOADS)												
		if ($.cookie('date-of-birth')) {
							
			var date = $.cookie('date-of-birth');
						
			var dob = date.split('-');
			var month = dob[0];
			var day = dob[1];
			var year = dob[2];
			
			// Set Month Dropdown
			$('#mailing_list_entry_birthday_2i').children('option').each(function(index) {

				if ($(this).val() == month) {
					
				$("#mailing_list_entry_birthday_2i")[0].selectedIndex = index;
				
				}

			});
			
			// Set Day Dropdown
			$('#mailing_list_entry_birthday_3i').children('option').each(function(index) {

				if ($(this).val() == day) {
					
				$("#mailing_list_entry_birthday_3i")[0].selectedIndex = index;
				
				}

			});
			
			// Set Year Dropdown
			$('#mailing_list_entry_birthday_1i').children('option').each(function(index) {

				if ($(this).val() == year) {
					
				$("#mailing_list_entry_birthday_1i")[0].selectedIndex = index;
				
				}

			});
			
			// Disabling Dropdowns
			$('#official-lists').find('select').attr('disabled', 'disabled').parent().addClass('disabled');
			
			// Un-disabling Dropdowns on Form Submit (so it can submit data in dropdowns)
			$('#official-lists').parent('form').submit(function(){
				
				$('#official-lists label.disabled select').removeAttr('disabled');
								
			});
				
		};
		
		
		// DELETE COOKIE & RESET FORM IF SUCCESS MESSAGE IS DETECTED
		if ($('div.widget-alert.success p:contains("Please check your e-mail to confirm your subscription.")').length > 0) {
			
			$.cookie('date-of-birth', null, {domain: 'sparkart.net', path: '/'});
			$('#official-lists label.disabled select').removeAttr('disabled');
			$('#official-lists label.disabled select').each(function(){
			
				$(this)[0].selectedIndex = 0;
				
			});
			
		}
		
		
		// CHANGING PARENTAL CONSENT ALERT TEXT
		$('div.widget-alert.error p:contains("Please enter their e-mail address below.")').text("To continue, we'll need to get your parent or guardian's permission. Please enter their e-mail address above.");
		
				

/* TEXT TRUNCATION
----------------------------------------------------------------------------- */
		
		
		$('#archive li a').truncate(30, { chars: /[a-zA-Z0-9]/, trail: [ "&nbsp;&hellip;" ] } );
		$('#news_headlines li a').truncate(30, { chars: /[a-zA-Z0-9]/, trail: [ "&nbsp;&hellip;" ] } );
		$('#press_headlines li a').truncate(30, { chars: /[a-zA-Z0-9]/, trail: [ "&nbsp;&hellip;" ] } );


/* TOGGLING THE OFFICIAL MAILING & MOBILE LIST
----------------------------------------------------------------------------- */

		$('#official-lists ul.actions').append('<li><a class="action cancel" href="#">Cancel</a></li>');
		
		$('#nav-officiallists a').click(function () {
		
			$('#official-lists label').removeClass('error');
			$('#official-lists strong').remove();	
			$('#official-lists label input').val("").attr("title","");
			$('#official-lists').show();
			$('div.widget-alert.error').hide();
			return false
		
		});

		$('#official-lists a.cancel').click(function () {
		
			$('#official-lists').hide();
			$('div.widget-alert.error').hide();
		
		});

		$('#official-lists label').each(function() {

			if ($(this).attr('class') == "error") {
		
				$(this).parent().show();
			
			}
			
		});
		
		$("#official-lists label.error").each(function() {
		
			var message = $(this).children('strong').text();
			$(this).children('input[type=text]').val(message).attr("title", message);
		
		});
		
		$("#official-lists label.error input[type=text]").click(function() {
		
			var label = $(this).attr("title");
			if (label == $(this).val()) {
			
				$(this).val("");
			
			}			
		
		});
		
		$("#official-lists label.error input[type=text]").blur(function() {
		
			var label = $(this).attr("title");
			if ($(this).val() == "") {
			
				$(this).val(label);
			
			}
			
		});	


/* SIFR Replacement
----------------------------------------------------------------------------- */


		if (section == "home" || section == "vanessa" || section == "music" || section == "member" || section == "appearances"  || section == "news") {
		
			sifr();
			
		}


/* ADD PARENTHESISES around small
----------------------------------------------------------------------------- */

		$('small').prepend("(");
		$('small').append(")");		


/* REMOVE UNDERLINE OF LAST DT AND DD IN DL
----------------------------------------------------------------------------- */

		$('dl dt:last').addClass("last");
		$('dl dd:last').addClass("last");


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


	});