
//requires jQuery


//wait for the DOM to be loaded
jQuery( document ).ready( function() {
	
	//GENERIC SITE ELEMENTS
	GenSiteElements.init();
	
	//LAYOUT
	$('div#content div.contentBlock').append('<div class="topLeft"></div>');
	$('div#content div.contentBlock').append('<div class="top"></div>');
	$('div#content div.contentBlock').append('<div class="topRight"></div>');
	$('div#content div.contentBlock').append('<div class="left"></div>');
	$('div#content div.contentBlock').append('<div class="right"></div>');
	$('div#content div.contentBlock').append('<div class="bottomLeft"></div>');
	$('div#content div.contentBlock').append('<div class="bottom"></div>');
	$('div#content div.contentBlock').append('<div class="bottomRight"></div>');
	$('div#content div.contentBlock').append('<div class="clearAll"></div>');
	
	$('div#footer').append('<div id="footerLogoBg"></div>');
	
	//FONT REPLACEMENT
	FontReplacement.init();
	
	//IE6 FIX.
	ieSixFix.init();
	
	//NAVIGATION
	$( 'div#nav ul' ).lavaLamp();
	/*
	var myUrl = location.href + "";
	var myFilename = myUrl.substring(myUrl.lastIndexOf('/')+1);
	$('div#nav > ul > li > a').each( function(){
		var myHref = $(this).attr('href');
		if( myFilename == myHref ){ $(this).addClass('selected'); };
	} );
	*/
	
	//VIDEO
	
	swfobject.embedSWF(
		"flash/videoPlayer.swf",
		"showreelPlayer",
		"700",
		"394",
		"9.0.28",
		"flash/expressInstall.swf",
		{ file:'xml/showreel-play-list.xml', image: '', autostart: true, volume: 0, repeat: 'always',controlbar: 'over', skin: 'flash/bekle.swf' },
		{ allowfullscreen: true, wmode: 'transparent' }
	);
	/*
	swfobject.embedSWF(
		"flash/videoPlayer.swf",
		"showreelPlayer",
		"700",
		"394",
		"9.0.28",
		"flash/expressInstall.swf",
		{ file:'../video/aerial-footage.mp4', image: '', autostart: true, volume: 0, repeat: 'always',controlbar: 'over', skin: 'flash/bekle.swf' },
		{ allowfullscreen: true, wmode: 'transparent' }
	);
	*/
	swfobject.embedSWF(
		"flash/videoPlayer.swf",
		"aerialReel",
		"700",
		"394",
		"9.0.28",
		"flash/expressInstall.swf",
		{ file:'../video/aerial-footage.mp4', image: '', autostart: true, volume: 100, repeat: 'always',controlbar: 'over', skin: 'flash/bekle.swf' },
		{ allowfullscreen: true, wmode: 'transparent' }
	);
	
	swfobject.embedSWF(
		"flash/videoPlayer.swf",
		"miningReel",
		"700",
		"394",
		"9.0.28",
		"flash/expressInstall.swf",
		{ file:'../video/nickel-mine-footage.mp4', image: '', autostart: true, volume: 100, repeat: 'always',controlbar: 'over', skin: 'flash/bekle.swf' },
		{ allowfullscreen: true, wmode: 'transparent' }
	);
	
	LightBox.init();
	
	
	//PORTFOLIO
	swfobject.embedSWF(
		"flash/portfolio.swf",
		"portfolioGallery",
		"760",
		"300",
		"9.0.28",
		"flash/expressInstall.swf",
		{},
		{ wmode: 'transparent' }
	);
	
	//CONTACT
	$('div#captchaWrapper img#captcha').after('<a href="javascript:;" id="captcha_reload">Reload Image</a>');
	$('div#captchaWrapper a#captcha_reload').click(function(event){
		var mySrc = 'script/securimage/securimage_show.php?' + Math.random();
		$('img#captcha').attr( 'src', mySrc );
		event.preventDefault();
	});
	
} );


LightBox =
{
	init : function()
	{
		if(!$().colorbox){ return; };
		
		$('a[href="aerials-reel.html"]').click(function(event){
			$.fn.colorbox( { html:'<div id="videoPlayer"></div>', width: '740px', height: '470px' } );
			swfobject.embedSWF(
				"flash/videoPlayer.swf",
				"videoPlayer",
				"700",
				"394",
				"9.0.28",
				"flash/expressInstall.swf",
				{ file: '../video/aerial-footage.mp4', image: '', autostart: true, volume: 100, repeat: 'none',controlbar: 'over', skin: 'flash/bekle.swf' },
				{ allowfullscreen: true, wmode: 'transparent' }
			);
			event.preventDefault();
		});
		
		$('a[href="mining-reel.html"]').click(function(event){
			$.fn.colorbox( { html:'<div id="videoPlayer"></div>', width: '740px', height: '470px' } );
			swfobject.embedSWF(
				"flash/videoPlayer.swf",
				"videoPlayer",
				"700",
				"394",
				"9.0.28",
				"flash/expressInstall.swf",
				{ file: '../video/nickel-mine-footage.mp4', image: '', autostart: true, volume: 100, repeat: 'none',controlbar: 'over', skin: 'flash/bekle.swf' },
				{ allowfullscreen: true, wmode: 'transparent' }
			);
			event.preventDefault();
		});
		
	}//end init
};//end LightBox



Portfolio = 
{
	loadVideo: function( pmPath )
	{
		//Assemble path to required video.
		var myVideoPath = "../video/" + pmPath;
		
		//$.fn.colorbox({href:'index.html'});
		$.fn.colorbox( { html:'<div id="videoPlayer" style="margin: 0px auto 0px auto;"></div>', innerWidth: '700px', innerHeight: '404px' } );
		
		swfobject.embedSWF(
			"flash/videoPlayer.swf",
			"videoPlayer",
			"700",
			"394",
			"9.0.28",
			"flash/expressInstall.swf",
			{ file: myVideoPath, image: '', autostart: true, volume: 100, repeat: 'none',controlbar: 'over', skin: 'flash/bekle.swf' },
			{ allowfullscreen: true, wmode: 'transparent' }
		);
	}
}


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


//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


//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

