	//	Youtube API load
	var tag = document.createElement('script');
	tag.src = "http://www.youtube.com/player_api";
	var firstScriptTag = document.getElementsByTagName('script')[0];
	firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================
$(document).ready(function(){	

	//	3rd level pages back link positioning
	$("ul#back").each(function(){
		var	pos	= $("article#main>header").position();

		$(this).css("left",pos.left+$("article#main>header").width()-$(this).width());
	});

	//	Init searchbar
	$('form#search input[name="findtext"]').liveSearch({url: '/site/quicksearch.php?findtext='});

	$('form#search input[name="findtext"]').blur( function() {
		if( $(this).val() != "" )
		{
			$(this).addClass("active");
		}
		else
		{
			$(this).removeClass("active");
		}
	});

	$('form#search input[name="findtext"]:not(:empty)').addClass("active");

    //	See More (portfolio list)
	$('a.see-more,a.expand').click(function(){
		$(this).hide();
		$(this).next("div.hidden").show();
	});


	$("object").attr("wmode","transparent");

//-------------------------------------------------------------------------------------------------------
//	External Links
//-------------------------------------------------------------------------------------------------------
	$('a[href^="http://"]').attr("target", "_blank");

	$("#share").hover(
		function () {
			$(this).find("ul").fadeIn( 75 );
		}, 
		function () {
			$(this).find("ul").fadeOut( 75 );
		}
	);

//-------------------------------------------------------------------------------------------------------
//	Share/Email
//-------------------------------------------------------------------------------------------------------
	$("a#share-email").overlay({
		mask: {
			color:			'black',
			loadSpeed:		100,
			opacity:		0.75
		},

		onBeforeLoad: function() {
			// grab wrapper element inside content
			var wrap	= this.getOverlay().find(".contentWrap");
			var	url		= this.getTrigger().attr("href");
			wrap.empty().prepend('<iframe id="emailthis" src="'+url+'"></iframe>');
		}
	});

//-------------------------------------------------------------------------------------------------------
//	Social Media Share - Open new window
//-------------------------------------------------------------------------------------------------------
	$("a#share-facebook,a#share-twitter,a#share-linkedin").click(function(event){

		//	Master category for all shares
		var	category	= 'Share';

		//	Share category
		var	subcategory	= $(this).attr("id");
		subcategory		= subcategory.split("-");
		subcategory		= subcategory[ ( subcategory.length - 1 ) ];

		//	Label based on title
		var	label		= $(document).attr("title");

		//	Send the event to Analytics
		_gaq.push(['_trackEvent', category, subcategory, label ]);
		
		var	attributes	= "width=550,height=300,location=0,menubar=0,toolbar=0";
		window.open( $(this).attr("href"), "share", attributes, true );
		event.preventDefault();
	});

//-------------------------------------------------------------------------------------------------------
//	Track Downloads
//-------------------------------------------------------------------------------------------------------
	$("a.download,a[href$='pdf'],a[href$='doc'],a[href$='mp3']").click(function(){

		//	Master category for all downloads
		var	category	= 'Downloads';

		//	Path of file being downloaded
		var	filepath	= $(this).attr("href");

		//	Use the file extention as the "action" parameter for the event
		filepath		= filepath.split(".");
		var	filetype	= filepath[ ( filepath.length - 1 ) ].toUpperCase();

		//	Label based on title or href
		var	label		= $(this).attr("title");

		if( !label )
		{
			label		= $(this).attr("href");
		}


		//	Send the event to Analytics
		_gaq.push(['_trackEvent', category, filetype, label ]);
	});

	//	PDF links open new tab
	$("a[href$='pdf']").click(function(){
		$(this).attr("target","_blank");
	});


//---------------------------------------------------------------------------------------------------------
//	Portfolio Slideshow
//---------------------------------------------------------------------------------------------------------
/*
	$("ul.slidebuttons").tabs(".slides > .slide", {
		effect:			'fade',
		fadeOutSpeed:	"slow",
		rotate:			true
	}).slideshow({
		autoplay:		true,
		clickable:		false
	});
*/
//---------------------------------------------------------------------------------------------------------
//	Image Overlay
//---------------------------------------------------------------------------------------------------------
/*
	// setup triggers
	$("images[rel]").each(function(i) {
			
		$(this).overlay({

			mask: {
				color:			'#ebecff',
				loadSpeed:		200,
				opacity:		0.9
			},

			// common configuration for each overlay
			oneInstance: false, 
			closeOnClick: false, 
			 
			
		});			
	});

*/

	$("iframe[title='YouTube video player']").attr("enablejsapi",1);

	var	ytplayer;

	var triggers = $("img[rel]").overlay({
		mask: {
			color:			'black',
			loadSpeed:		100,
			opacity:		0.75
		},

//		closeOnClick: false,

		onBeforeLoad: function() {

			var videoplayer = this.getOverlay().find("embed");
			videoplayer.attr("wmode","transparent");

			
			var videoplayerid = this.getOverlay().attr("id");
			ytplayer = this.getOverlay();

		},

		onBeforeClose: function() {

			var videoplayerid = this.getOverlay().attr("id");
			var	player_id	= "yt" + videoplayerid.substr( 5, videoplayerid.length );

			ytplayer	= document.getElementById(player_id);

			//	Stop the video
			if( ytplayer )
			{
				ytplayer.stopVideo();
			}

		}

	
	});
	$(".image-overlay").click(function(e){
//		triggers.eq(0).overlay().close();
	});

//-------------------------------------------------------------------------------------------------------
//	Position Client overlay
//-------------------------------------------------------------------------------------------------------
	$('.valign-center').each( function() {
		var top_offset	= ( $(this).parent().height() - $(this).height() ) / 2;
		$(this).css("margin-top",top_offset+"px");
	});

	//---------------------------------------------------------------------------------------------------------
	//		remove text from the textboxes when one focuses on the textbox
	//---------------------------------------------------------------------------------------------------------
    $('.inline-label input,.inline-label textarea').each(function(){

		$(this).focus(function(){
			$(this).siblings("label").fadeTo( 75, 0 );
		});

		$(this).blur(function(){
			if( $(this).val() )
			{
				fade_on_blur	= 0;
			}
			else
			{
				fade_on_blur	= 1.0;
			}
			$(this).siblings("label").fadeTo( 75, fade_on_blur );
		});

		if( $(this).val() )
		{
			$(this).siblings("label").fadeTo( 0, 0 );
		}

	});

	//---------------------------------------------------------------------------------------------------------
	//	custom menu highlight
	//---------------------------------------------------------------------------------------------------------
    $("#sectionnav ul.m1 a.active").parentsUntil("#sectionnav").find("a.a0.active:first").removeClass("active");

});
$(window).resize(function(){	

	//	Init searchbar
	$("ul#back").each(function(){
		var	pos	= $("article#main>header").position();

		$(this).css("left",pos.left+$("article#main>header").width()-$(this).width());
	});

});

onStateChange

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
}

function onStateChange(playerId) {
	alert( playerID );
//	ytplayer = document.getElementById("myytplayer");
}

