/* POST-LOAD FUNCTION
----------------------------------------------------------------------------- */


	$(window).load(function() {
	
	$('#footer div.widget-alert').appendTo('#title'); 
	


/* RANDOM BACKGROUNDS
----------------------------------------------------------------------------- */

	var random = Math.floor(Math.random()*6) + 1;
	$('body').addClass('bg' + random);
	



/* SITE-ONLY
----------------------------------------------------------------------------- */


	if (section != "messageboard" && section != "checkout" ) {


/* FUNCTION CALLS
----------------------------------------------------------------------------- */


	// PLUGIN: ACTIONS (Replaces submit buttons with text links)
	try { $('input[type=submit]').chicleActions(); } catch (error) { alert('Error: Missing chicle Actions Plugin'); }

	// PLUGIN: FORMS (Adds text into input forms)
	$('#mailing_list_entry_email').chicleForms({ placeholder: "Enter Your E-mail Address" });

	if (page == "index" || page == "news" || section == "client") {

		readmore();

	}
	
	if (page == 'index') {
		
		banners();
		events();
		
	}

	killTabs();
	tabs();
	cufon();
	paging();
	truncate();
	comments();
	if (section == "bio") biography();
	if (section == "agenda") sponsorship();


/* STORE FUNCTIONALITY
----------------------------------------------------------------------------- */


		if (section == "store") {
		
		
			// SUB-DEPARTMENTS
			$('#subcategories').each(function() {
		
				var category = $('#subcategories h3').text();
				$('#subcategories ul').find('a:contains("Everything")').parent().remove();
				$('#subcategories ul').appendTo('#departments li:has(a:contains("' + category + '"))');
				$('#subcategories').remove();
		
			});
			
			// PLUGIN: FORMS
			try {
			$('.widget-item.search input#query').chicleForms({ placeholder: "Search Store" });
			$('.widget-item.search input#query').css('visibility', 'visible'); // Will not chain to previous function?
			$('#mailing_list_entry_email').chicleForms({ placeholder: "Enter Your Email Address" });
			$('#mailing_list_entry_mobile').chicleForms({ placeholder: "Enter Your Mobile Number" });
			} catch (error) { alert('Error: Missing Chicle Forms Plugin'); }

			// PLUGIN: ITEM WIDGET
			try {
			$('div.widget-item.display:not(.photos, .gift)').chicleItemWidget({

				checkStock: false,
				pressure: false,
				browser: 'thumbnails', // thumbnails / slideshow
				removeEmptyThumbs: true, // Removes rows of empty thumbnails
				viewer: true, // Shows enlarged images
				preview: false, // Preview enlarged images when hovering thumbnails
				zoom: 'drag' // loupe / drag / none

			});
			$('.widget-item.browse.tooltip').chicleItemWidget();
			$('.widget-item.filter').chicleItemWidget();
			} catch (error) { alert('Error: Missing chicle Item Plugin'); }

			// PLUGIN: ALERT WIDGET
			try { $('div.widget-alert.added').chicleAlertWidget(); } catch (error) { alert('Error: Missing chicle Alert Plugin'); }

			// PLUGIN: UPLOADER
			if (page == "item" && $('#review').length > 0) { try { $('#review').chiclePhotoUploader(); } catch (error) { alert('Error: Missing chicle Uploader Plugin'); } }
						
			
			
		}
	

/* END SITE-ONLY
----------------------------------------------------------------------------- */


	}


/* END POST-LOAD FUNCTIONS
----------------------------------------------------------------------------- */


	});



	
/* FUNCTION: CUFON REPLACEMENTS
----------------------------------------------------------------------------- */


	function cufon() {
	
		var tradegothic_medium = [
			
		
			'#page-photos #scope div.widget-tag h3',
			
			'.program .events li em',
			'.program .events li strong abbr',
			'#sidebar #departments li a',
					
			'a.action.another'
			
		];

		var MuseoSans = [ 
		
			'h2',
			'h3',
			'h4',
			'a.action',
			'ul.pages a',
			'ul.pages strong',			
			'div.program ul.tickets li a',
			'.section-tour td.tickets a',
			
			'.program .events li strong span',
			'#navigation li a'
			
		];

		Cufon.replace(tradegothic_medium, { fontFamily: 'TradeGothic_Medium', hover: true });
		Cufon.replace(MuseoSans, { fontFamily: 'Museo Sans 500', hover: true });
		
		$(tradegothic_medium.toString()).css('visibility', 'visible');
		$(MuseoSans.toString()).css('visibility', 'visible');
						
	}


/* 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();

			// IF 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 + '">Leer Más...</a>');

			}

			// IF LAST CHILD IS ANOTHER ELEMENT
			else {

				$(this).find('div.story > *:last-child').after('<br /><a class="readmore" href="' + link + '">Leer más...</a>');

			}

		});

	}





/* FUNCTION: SHOW UPCOMING EVENTS IF THERE ARE NO FEATURED EVENTS
----------------------------------------------------------------------------- */


	function events() {
	
		if ($('div.widget-event.featured').length > 0) {
		
			$('div.widget-event.upcoming').hide();
			
		}
		
		else {
		
			$(this).parent('div.widget-event.featured').hide();
			$('div.widget-event.upcoming').show();

		}
		
	}
