$(document).ready(function() {

	var billboardId = '#c114',
		billboardElement = $(billboardId)[0];
	
	if (billboardElement) {
		// div.csc-textpic-imagewrap
		//   dl.csc-textpic-image csc-textpic-firstcol csc-textpic-lastcol
		//		dt
		//		dd
		
		var billboardWidth = 704,
			billboardHeight = 400 + 5;
		
		// Get image soruces & captions
		var billboards = [];
		$(billboardId + ' div.csc-textpic-imagewrap dl').each(
			function() {
				var image = $(this).find('img'),
					paragraph = $(this).find('p');
				billboard = {  // All values types are String
					'src': '/' + image.attr('src'),
					'width': image.attr('width'),  
					'height': image.attr('height'),
					'alt': paragraph.text()
				}
				billboards.push(billboard);
			}
		)
		// console.log(billboards);
		
		var header = $(billboardId + ' h1.csc-firstHeader')
			.css({'width': billboardWidth + 'px', 'position': 'relative'})
			.html(
				'<span class="first" style="position: absolute; right: 0;">' + billboards[0].alt + '</span>'),
		headers = header.find('span');
		// $(headers[0]).html(billboards[0].alt);
		
		// console.log(headers)
		$(billboardId + ' div.csc-textpic-imagewrap')
			.css({
				'width': billboardWidth + 'px',
				'height': billboardHeight + 'px'
			})
			.crossSlide({
				sleep: 8,
				fade: 2
			},
			billboards,
			function(indexIn, billboardIn, indexOut, billboardOut) {
				// This call back will be invoked twice
				// #1 Single image phase: the index of the image in the array and the <img> object currently being animated (2 arguments)
				// #2 Cross fade phase: index and img element of the incoming image, plus index and img element of the outgoing image (4 arguments)
				
				if (indexOut == undefined) { // Only two arguments supplied -> starting single image phase, put up caption
					// $(headers[0]).text(billboardIn.alt)
					// $(headers[0]).fadeIn(0.5); //animate({ opacity: 1 })
				} else { // starting cross-fade phase, take out caption
					header.html(
						'<span class="first" style="position: absolute; right: 0;">' + billboards[indexIn].alt + '</span>'
						 + '<span class="second" style="position: absolute; right: 0;">' + billboards[indexOut].alt + '</span>'),
					header.find('.first').hide().fadeIn(2000);
					header.find('.second').show().fadeOut(2000);
					// $(headers[0]).html(billboardIn.alt); //.css({'opacity': 0, 'display': 'inline'})
					// $(headers[0]).hide().fadeIn(3);
					// $(headers[1]).html(billboardOut.alt); //.css({'opacity': 1, 'display': 'inline'})
					// $(headers[1]).show().fadeOut(3);
				}
			}
		);
	}
	
	// Embed flash icon with sound
	$('#languages .icon').addClass('swf').flash(
		{
			'swf': 'fileadmin/scripts/icon.swf',
			'width': 72,
			'height': 35,
			'bgcolor': "#333333"
		}
	);
	
	// Extend the $.support object for feature detection
	// Adobe Flash ActiveXObject or plugin 
	$.support.flash = false;
	try {
	  var flashObject = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
	  if(flashObject) $.support.flash = true;
	} catch(event) {
	  $.support.flash = navigator.mimeTypes ["application/x-shockwave-flash"] != undefined;
	}
	
	// HTML5 <video>
	$.support.html5video = typeof HTMLVideoElement != undefined;
	
	window.scrollTo(0,1)
});
