
//requires jQuery


//wait for the DOM to be loaded
jQuery( document ).ready( function() {
							   
	//GENERIC SITE ELEMENTS
	GenSiteElements.init();
	
	//TREE NAV
	$( 'div#nav ul#navigation' ).treeview({
		persist: "location",
		collapsed: true,
		unique: true,
		animated: "fast"
	});
	
	//ALLOW ENLARGED VERSIONS OF IMAGES
	$( 'img.enlarge' ).each( function(){
		var myImgSrc = $( this ).attr( "src" );
		myImgSrcLrge = myImgSrc.replace( /.jpg/, "_large.jpg" );
		$( this ).wrap( "<a></a>" );
		$( this ).parent().attr( "href", myImgSrcLrge );
		$( this ).parent().addClass( "enlargeImgLink" );
	});
		
	//SHOW ENLARGED IMAGES IN LIGHTBOX
	/*
	$( 'a.enlargeImgLink' ).fancybox( {
		overlayOpacity : 0.5,
		zoomOpacity : false,
		zoomSpeedIn : 500,
		zoomSpeedOut : 500//
		//easingIn : 'easeOutBack',
		//easingOut : 'easeInBack'
	} );
	*/
	
	$( 'ul.gallery li a' ).colorbox( { transition: "elastic", current: "{current} of {total}" } );
	$( 'ul.jcarousel-skin-default li a' ).colorbox( { transition: "elastic", current: "{current} of {total}" } );
	
	//MEDIA FILES.
	$( 'a.videoLink' ).each( function( pmIndex ){
									  
		//Get video file path from link.
		var myVideoFile = $( this ).attr( "href" );
		
		var myIsAudio = myVideoFile.indexOf( 'audio/' ) > -1;
		var myFileType = ( myIsAudio ) ? 'sound' : 'video';
		var myHeight = ( myIsAudio ) ? '20' : '360';
		
		//Adjust local path for swf location.
		myVideoFile = myVideoFile.replace( /video/, "../video" );
		//myVideoFile = myVideoFile.replace( /audio/, "../audio" );
		
		//Get unique div names for each video holder.
		var myVideoDivName = "video_" + pmIndex;
		var myVideoPlayerDivName = "videoPlayer_" + pmIndex;
		
		//Write video holder html.
		$( 'div#content' ).append( '<div id="' + myVideoDivName + '" class="video"><div id="' + myVideoPlayerDivName + '" class="videoPlayer"></div></div>' );
		
		//Embed media player
		swfobject.embedSWF("flash/videoPlayer.swf", myVideoPlayerDivName, "640", myHeight, "9.0.28", "", { file: myVideoFile, autostart: false, type: myFileType }, { allowfullscreen: !myIsAudio, wmode: 'transparent' });
		
		//Activate light boc functionality on link.
		$( this ).colorbox( { inline: true, href: '#' + myVideoPlayerDivName, title: "" } );
	});
	
	//HOME
	if( $( 'body' ).hasClass( 'home' ) )
	{
		//alert( 'hello' );
		swfobject.embedSWF( "flash/videoPlayer.swf", "videoPlayer", "384", "236", "9.0.28", "", { file: '../video/sydney-australia-2006-trailer.f4v', autostart: true, volume: 100, repeat: 'always' }, { allowfullscreen: true, wmode: 'transparent' });
		//swfobject.embedSWF( "flash/videoPlayer.swf", "videoPlayer", "640", '360', "9.0.28", "", { , type: myFileType }, { wmode: 'transparent' });
		//alert( 'hello2' );
	};//end if
	
	//NEWS TICKER
	$( "div#news" ).css( "display", "block" ); //IE fix
	$( "div#news ul#newsTicker" ).liScroll( { travelocity: 0.05 } );
	
	$( 'p.introPara' ).each( function( pmIndex ){
		var myText = $(this).text();
		var myLimitText = myText.substring( 0,200 );
		$(this).text( myLimitText + "..." );
	} );
	
	//CAROUSELS
	jQuery('ul#carouselList').jcarousel({
        auto: 5,
        wrap: 'last',
        initCallback: carouselList_initCallback
    });
	
} );

function carouselList_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        //carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        //carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function poo( pmLink )
{
	var myLink = pmLink;
	
	swfobject.embedSWF("flash/videoPlayer.swf", "videoPlayer", "640", "360", "9.0.28", "", { file: myLink, stretching: 'exactfit', autostart: true }, { allowfullscreen: true, wmode: 'transparent' });
}


//handles setting site elements
GenSiteElements =
{
	//handles setting up site elements
	init : function()
	{
		GenSiteElements.setBlockquotes();
		GenSiteElements.setOrderedLists();
		GenSiteElements.setExternalLinks();
	}//end function init
	,
	//handles setting up block quotes
	setBlockquotes : function()
	{
		jQuery( 'blockquote' ).each( function(){
			var myTitle = jQuery( this ).attr( 'title' );
			var myCite = jQuery( this ).attr( 'cite' );
			jQuery( this ).prepend( '<h3>' + myTitle + '</h3>' );
			jQuery( this ).append( '<p class="cite"><a href=\"' + myCite + '\">Source</a></p>' );
		} );
	}//end function setBlockquotes
	,
	//handles setting ordered list
	setOrderedLists : function()
	{
		//edit ordered list dom to allow styling
		jQuery( 'ol li' ).wrapInner( '<span class="olItemContent"></span>' );
		//activate ordered list styling via adding class - edit styles in stylesheet
		jQuery( 'ol' ).addClass( 'javaScriptStyled' );
	}
	,
	//handles external links
	setExternalLinks : function()
	{
		jQuery( 'a[rel="external"]' ).each( function(){
			jQuery( this ).addClass( 'externalLink' );
			
		} );
		
		//jQuery( 'a[rel="external"]' ).click( function(){
			
			//window.open( jQuery( this ).attr( 'href' ) );
			//return( false );
		//} );
	}//end function setExternalLinks
	
	
};//end object literal siteElements
