
//requires jQuery


//wait for the DOM to be loaded
$( document ).ready( function() {
								   
	//GENERIC SITE ELEMENTS
	GenSiteElements.init();
	
	//Navigation.
	$( 'div#nav ul li a' ).append( '<span class="right"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="left"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="top"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="bottom"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="topLeft"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="topRight"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="bottomLeft"></span>' );
	$( 'div#nav ul li a' ).append( '<span class="bottomRight"></span>' );
	
	//HOME
	//Home banner flash.
	swfobject.embedSWF( "flash/homeShowcase.swf", "flashHomeShowcase", "550", "600", "9.0.28", "flash/expressInstall.swf", {}, { wmode: 'transparent' } );
	$( 'body.home div#nav ul li a[href="index.html"]' ).addClass( 'selected' );
	$( 'body.services div#nav ul li a[href="services.html"]' ).addClass( 'selected' );
	$( 'body.portfolio div#nav ul li a[href="portfolio.html"]' ).addClass( 'selected' );
	$( 'body.about div#nav ul li a[href="about.html"]' ).addClass( 'selected' );
	$( 'body.contact div#nav ul li a[href="contact.html"]' ).addClass( 'selected' );
	
	//SERVICES
	swfobject.embedSWF( "flash/videoPlayer.swf", "flashVideoPlayer", "400", "300", "9.0.28", "flash/expressInstall.swf", { file:'../video/aurion-intro.f4v', image: 'images/toyotaAurionMovHero.jpg', autostart: false, controlbar: 'none', skin: 'http://www.tmgtaylormadegraphics.com.au/flash/bekle.swf' }, { allowfullscreen: true, wmode: 'transparent' } );
	
	//CAROUSELS
	$('ul#carouselList').jcarousel({
		scroll: 6,
        auto: 5,
        wrap: 'last',
        initCallback: carouselList_initCallback
    });
	
	$('ul#carouselList li a').click( function( event ){
		$( "div#portfolioWrapper" ).html( '<img src="images/ajax-loader-indicator-big-blue.gif" style="position: absolute; left: 47%; top: 47%;" />' );
		var myLink = $(this).attr('href');
		$( "div#portfolioWrapper" ).load( myLink + " div#portfolioContent" );
		event.preventDefault();
	} );
	
} );


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();
    });
};



//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()
	{
		$( 'blockquote' ).each( function(){
			var myTitle = $( this ).attr( 'title' );
			var myCite = $( this ).attr( 'cite' );
			$( this ).prepend( '<h3>' + myTitle + '</h3>' );
			$( 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
		$( 'ol li' ).wrapInner( '<span class="olItemContent"></span>' );
		//activate ordered list styling via adding class - edit styles in stylesheet
		$( 'ol' ).addClass( 'javaScriptStyled' );
	}
	,
	//handles external links
	setExternalLinks : function()
	{
		$( 'a[rel="external"]' ).each( function(){
			$( this ).addClass( 'externalLink' );
			
		} );
		
		//$( 'a[rel="external"]' ).click( function(){
			
			//window.open( $( this ).attr( 'href' ) );
			//return( false );
		//} );
	}//end function setExternalLinks
	
	
};//end object literal siteElements

