
//requires jQuery

//wait for the DOM to be loaded
jQuery( document ).ready( function() {
								   
	//GENERIC SITE ELEMENTS
	GenSiteElements.init();
	
	//IE6 FIX.
	ieSixFix.init();
	
	//SCRIPT LOADING.
	/*
	$.lazy({					
		src: 'script/jquery.treeview.js',
		name: 'treeview',
		dependencies: {
			js: ['script/jquery.cookie.js'],
			css: ['css/jquery.treeview.css']
		},
		cache: true
	});
	*/
	
	//FONT REPLACEMENT
	FontReplacement.init();
	
	//NAVIGATION
	$( 'div#nav ul' ).treeview({
			persist: "location",
			collapsed: true,
			unique: true,
			animated: "fast"
	});
	
	//SLIDESHOWS.
	SlideShow.init();
	
	//GALLERIES.
	
	$( 'ul.gallery li a[rel=imageGallery]' ).fancybox({
		/*'href'				: 'portfolio-identity-dnc.html',*/
		'ajax' 				: { cache : false },
		'autoDimensions'	: true,
		'centerOnScroll'	: true,
		'padding'			: 40,
		'overlayOpacity'	: 0.6,
		'scrolling'			: 'no',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'outside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		},
		'onComplete'		: function(){ FontReplacement.lightbox(); }
	});
	
	//HOME
	//$('body.home ul#slideshow li div.info').append('<div class="topLeft"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="topRight"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="top"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="left"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="right"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="bottomLeft"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="bottom"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="bottomRight"></div>');
	//$('body.home ul#slideshow li div.info').append('<div class="arrow"></div>');
	
	//HOME BANNER
	swfobject.embedSWF( "flash/home-banner.swf", "flashBanner", "760", "456", "9.0.28", "flash/expressInstall.swf", {}, { wmode: 'transparent' } );
	
} );//end document ready


//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.genStyle li' ).wrapInner( '<span class="olItemContent"></span>' );
		//activate ordered list styling via adding class - edit styles in stylesheet
		jQuery( 'ol.genStyle' ).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


//Handles font replacement strategy.
FontReplacement = 
{
	init : function()
	{
		Cufon.replace('h1');
		Cufon.replace('h2');
		Cufon.replace('h3');
		Cufon.replace( 'div#nav > ul > li > a', { hover: true } );
		Cufon.replace( 'ol#breadcrumbs li' );
		Cufon.replace( 'ul#siteList > li > a', { hover: true } );
	}
	,
	lightbox : function()
	{
		Cufon.replace('div#portfolioContent h3');
	}
};//end FontReplacement


//Handles IE6 fixes.
//Use on elements which should degrade reasonably gracefully if JavaScript is not available.
ieSixFix = 
{
	init : function()
	{
		ieSixFix.setFooter();
		ieSixFix.setForms();
		ieSixFix.setHeaders();
	}//end init
	,
	setFooter : function()
	{
		$( 'div#footer ul li:first-child' ).addClass( 'first' );
	}
	,
	setForms : function()
	{
		$( 'form input[type="text"]' ).addClass( 'text' );
		$( 'form input[type="password"]' ).addClass( 'password' );
	}//end setForms
	,
	setHeaders : function()
	{
		$( 'div#col1 h2:first-child' ).addClass('first');
		$( 'div#col2 h2:first-child' ).addClass('first');
		$( 'div#col3 h2:first-child' ).addClass('first');
		$( 'div#col1 h3:first-child' ).addClass('first');
		$( 'div#col2 h3:first-child' ).addClass('first');
		$( 'div#col3 h3:first-child' ).addClass('first');
	}
};//end ieSixFix


//Handles slide shows.
SlideShow = 
{
	init : function( pmIndex )
	{
		//Determine slide to start on.
		if( pmIndex == undefined ){ pmIndex = 0 };
		
		//Place necessary DOM elements
		$( 'ul#slideshow' ).after( '<div id="slideshowNav"><h4>See More</h4><a id="slideshowPrev" href="javascript:;">Prev</a><div id="pager"></div><a id="slideshowNext" href="javascript:;">Next</a></div>' );
		
		//Setup plugin.
		$( 'ul#slideshow' ).cycle({
			fx: 'scrollHorz',
			speed: 1000, 
	    	timeout: 6000,
			pause: true,
			prev: 'div#slideshowNav a#slideshowPrev', 
	    	next: 'div#slideshowNav a#slideshowNext',
			pager: 'div#slideshowNav div#pager',
			startingSlide: pmIndex,
			cleartypeNoBg: true,
			before: SlideShow.onBefore,
			after: SlideShow.onAfter
		});
	}
	,
	onBefore : function(curr, next, opts)
	{
		if( $('body').hasClass( 'home' ) )
		{
			//alert("Before");
			///$(curr).children('div.info').hide();
			///$(next).children('div.info').hide();
			//console.log($(curr).children('div.info'))
		};//end if
	}
	,
	onAfter : function(curr, next, opts)
	{
		if( $('body').hasClass( 'home' ) )
		{
			///$(next).children('div.info').animate( { opacity: 'show', top: '+=15px' }, 500 );
			//alert("After");
			//console.log(opts)
		};//end if
	}
};//end SlideShow
