jQuery(function($) {
	// Grab all images path
	var images = [];
	$('#slideshow img').each(function() {
		images.push(this.src);
	});
	
	// Grab section from DOM
	var section = $('#slideshow').attr('class');
	
	// Generate the image slideshow
	swfobject.embedSWF('/uploadedfiles/en/_system/swf/masthead.swf', 'flashmasthead', '533', '240', '10.0.0', false, { img: images, section: section }, { wmode:'opaque', menu:'false' }, {});
	
	// Generate slideshow for missing flash plugin
	$('#slideshow').cycle();
	
	// Generate divider for breadcrumbs
	$('.breadcrumbs li').not(':last').each(function() {
		$(this).find('a').after(' &raquo;');
	});
	
	$('.breadcrumbs li:first-child').addClass('first');
	
	// Featured content for subpage
	$('.featured-content ol').cycle({
		pager: '.featured-content-control .pager',
		next: '.featured-content-control .scroller .next',
		prev: '.featured-content-control .scroller .prev',
		pause: true,
		cleartypeNoBg: true
	});
	
	if ($('.featured-content li').length == 1) {
		$('.featured-content-control .scroller').hide();
	}
	else {
		$('.featured-content-control .scroller').show();
	}
	
	// Tracking for featured content
	$('.featured-content li:first-child').addClass('first-child');
	$('.featured-content .content').each(function() {
		var content = $(this);
		var title = content.find('h5').text();
		var cta = content.find('span.more a').text();
		var links = content.find('a').click(function() {
			//trace('title = '+title+'; cta text = '+cta+';');
			pageTracker._trackEvent('Subpage Sidebar Carousel', cta, title);
			return true;
		});
	});
	
	// Back to map
	$('.back-to-map a').colorbox({
		iframe: true,
		href: '/uploadedFiles/en/map.html',
		opacity: 0,
		innerWidth: 958,
		innerHeight: 518,
		onOpen: function() {
			$('.back-to-map a').hide();
		},
		onClosed: function() {
			$('.back-to-map a').show();
			closePopUp(); // close any popups if its opened
			if ($('body.itinerary').length)
				window.location.reload();
			else
				$('#itinerary-count').itineraryCounter();
		}
	});
	
	// What's nearby / Related attractions content toggler
	$('.nearby ul, .related-attractions ul').sentosaToggleContent();
	
	if ($('.itinerary.listing .no_item_added').length) 
		$('.itinerary fieldset.action').addClass('hide');
	else 
		$('.itinerary fieldset.action').removeClass('hide');
	
});
