/* PAULA ABDUL TEMPLATE */
/* Javascript Functions
----------------------------------------------------------------------------- */


	$(document).ready(function() {
	});


/* POST-LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {


/* MOVE "READ MORE" LINK
----------------------------------------------------------------------------- */


		if (page == "index" || page == "news" || section == "client") {

			readmore();

		}


/* TEXT MODIFICATION
--------------------------------------------------------------------------- */


		$('div.widget-event.browse.placeholder h3:contains("Past Events") ~ p:contains("No upcoming performances have been scheduled at this time")').text('There are no past performances to display.');

		// Last <dt> and <dd> elements

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


/* CHAT PROMPT FOR PUBLIC USERS
--------------------------------------------------------------------------- */


		if (page == "index" && logged_in == "false") {

			$('#dim').click(function() {

				$('div.prompt.chat').show();
				$(this).addClass("dim");

			});

		};


/* CLIQUE SIGN IN PAGE
----------------------------------------------------------------------------- */


		if (page == 'login' || page == 'index') {


			// START SLIDESHOWS

			$('ul.tiers').before('<div id="paging">').cycle({

				fade: true,
				speed: 400,
				timeout: 9000,
				pager: '#paging',
				before: function() { if (window.console) console.log(this.src); }

			});

			$('div#benefits ul').cycle({

				fade: true,
				speed: 400,
				timeout: 6000
		
			});


			// CUSTOMIZE PAGING LINKS
				
			$('#paging a:nth-child(1)').livequery(function() { $(this).addClass('basic'); });
			$('#paging a:nth-child(1)').livequery(function() { $(this).text('Basic'); });
		
			$('#paging a:nth-child(2)').livequery(function() { $(this).addClass('deluxe'); });
			$('#paging a:nth-child(2)').livequery(function() { $(this).text('Deluxe'); });
		
			$('#paging a:nth-child(3)').livequery(function() { $(this).addClass('premiere'); });
			$('#paging a:nth-child(3)').livequery(function() { $(this).text('Premiere'); });

		}


/* MEMBER NAVIGATION DROPDOWN
----------------------------------------------------------------------------- */


		$('ul#navigation li:has(ul)').hover(function() {

			$(this).addClass('hover');

		}, function() {

			$(this).removeClass('hover');

		});


/* FUNCTION CALLS
----------------------------------------------------------------------------- */


		killTabs();
		tabs();
		paging();
		truncate();
		comments();

		if (page == "index") {

			photoSlideshow();
		
		}


/* END POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */


	});


/* FUNCTION: KILL TABS
----------------------------------------------------------------------------- */ 


	function killTabs() {

		// REMOVE EMPTY JAVASCRIPT TAB AND PANE
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').children('li').each(function() {

			var pane = $(this).children('a').attr('href');

			if ( $(this).parent().parent().find(pane).children('*').length == 0 ) {

				$(this).remove();
				$(this).parent().parent().find(pane).remove();

			}

		});

		// REMOVE TABBED PANEL
		$('div.tabbed').not(".static, .ajax").children('ul.tabs').each(function() {

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

				$(this).parent().remove();

			}

		});

	}


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


	function tabs() {

		// FEATURES BOX TABS
		if (page == 'index') {

			$('div#features > ul.tabs').tabs({

				fxSlide: false,

				show: function() {

					// PHOTOS TAB
					if ($('#photos:visible').length > 0) {

						$('#tv div.flash div').empty();
						$('#voicemail div.flash div').empty();

						photoSlideshow();

						$('div#features div.widget-photo.slideshow div a, a#photos_back, a#photos_next').hover(

							function() {

								$('a#photos_back').show();
								$('a#photos_next').show();

							},
							function() {

								$('a#photos_back').hide();
								$('a#photos_next').hide();

							}

						)

					} 

					// VOICEMAIL TAB
					else if ($('#voicemail:visible').length > 0) {

						$('#tv div.flash div').empty();

						photoSlideshow();

						var radio_player = $('#voicemail div.flash div').attr('id');
						eval(radio_player)();

					}

					// TV TAB
					else if ($('#tv:visible').length > 0) {

						$('#voicemail div.flash div').empty();

						photoSlideshow();

						var video_player = $('#tv div.flash div').attr('id');
						eval(video_player)();

					}

					else {

					}

				}

			});

		}

		// JAVASCRIPT TABS

		if (page != "upcoming" && page != "going" && page != "past") {

			$('div.tabbed').not("#features, .ajax, .static").children('ul.tabs').tabs({

				fxSlide: false,

				click: function() {

				}, load: function() {

					truncate();

				}, show: function() {

					truncate();

				}

			});

		}

		// AJAX TABS
		$('div.tabbed.ajax > ul.tabs').tabs({

			fxSlide: false,

			click: function() {

				loading('start');

			}, load: function() {

				truncate();
				sifr();
				loading('stop');

			}, show: function() {

				truncate();
				sifr();
				loading('stop');

			}

		});
		
	}


/* FUNCTION: LOADING INDICATOR
----------------------------------------------------------------------------- */


	function loading(event) {

		/*if (event == "start") {

			$('#loading').animate({
			left: '0px'
			}, 300);

		} else {

			$('#loading').animate({
			left: '-54px'
			}, 300);

		}*/

	}


/* FUNCTION: PAGING FOR TABS
----------------------------------------------------------------------------- */ 


	function paging() {

		// AJAX TABS
		$('div.tabbed.ajax ul.paging a').livequery('click', function(event) {

			loading('start');

			$(this).parents('div.pane').load($(this).attr('href'), function(data) {

				truncate();
				sifr();
				loading('stop');

			});

			return false;

		});

		// JAVASCRIPT TABS
		$('div.tabbed:not(.ajax):not(.static) ul.paging a, div.tabbed:not(.ajax):not(.static) ul.pages a').each(function() {

			var pane = $(this).parents('div.pane').attr('id'); 

			$(this).attr('href', $(this).attr('href') + '#' + pane); 

		});

	}


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


	function truncate() {

		// DESCRIPTIONS OF TITLED BROWSE WIDGETS
		$('div#content div.titled strong').each(function() {
		
			if ($(this).text().length >= 55) {
		
				var text = $(this).text().slice(0,55);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});
		
		// MEMBER STATUS
		$('div.grid.split div#content .member dd.status').each(function() {
		
			if ($(this).text().length >= 50) {
		
				var text = $(this).text().slice(0,50);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
		
			}
		
		});

		$('div.grid.two_thirds div#content .member dd.status').each(function() {
		
			if ($(this).text().length >= 80) {
		
				var text = $(this).text().slice(0,80);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});

		// MEMBER ALIAS
		$('div.grid.split div#content .member a.alias strong').each(function() {
		
			if ($(this).text().length >= 15) {
		
				var text = $(this).text().slice(0,15);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
		
			}
		
		});

		$('div.grid.two_thirds div#content .member a.alias strong').each(function() {
		
			if ($(this).text().length >= 30) {
		
				var text = $(this).text().slice(0,30);
		
				$(this).text(text);
				$(this).append('<var>&nbsp;&hellip;</var>');
				
			}
		
		});

	}


/* FUNCTION: COMMENTS
--------------------------------------------------------------------------- */


	function comments() {

		// ADDS CANCEL BUTTON FUNCTIONALITY
		$('#comment a.cancel').click(function() {

			$('#comment textarea').val('');
			$('#comments-panel > ul').tabsClick(1);
			return false;

		});
		
	}


/* FUNCTION: MOVE "READ MORE" LINK
----------------------------------------------------------------------------- */ 


	function readmore() {

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

			var link = $(this).find('a.display').attr('href');
			$(this).find('ul.actions').remove();

			// LAST CHILD IS P.LEAD
			if ( $(this).find('div.story > *:last-child').hasClass('lead') ) {

				$(this).find('div.story p.lead:last').append('&nbsp;&nbsp;<a class="readmore" href="' + link + '">Read More...</a>');

			}
			// LAST CHILD IS ANOTHER ELEMENT
			else {

				$(this).find('div.story > *:last-child').after('<br /><a class="readmore" href="' + link + '">Read More...</a>');

			}

		});

	}
