$(document).ready(function(){
	
	// Tab Toggle
	var tabContainers = $('#view > .tab');
	tabContainers.hide().filter(':first').show();
	$('#view .tabs a').click(function () {
	        tabContainers.hide();
	        tabContainers.filter(this.hash).show();
	        $('#view .tabs a').removeClass('selected');
	        $(this).addClass('selected');
	        return false;
	}).filter(':first').click();
	
	// Newsletter Sign Up
	var newsletterField = '#newsletter-signup input[type="text"]';
	var newsletterFieldDefault = 'Email Address';
	if ($(newsletterField.length > 0)){
		$(newsletterField).focus(function(){  
	    	if($(this).attr('value') == newsletterFieldDefault) $(this).attr('value', '');  
		});  
		$(newsletterField).blur(function(){  
	    	if($(this).attr('value') == '') $(this).attr('value', newsletterFieldDefault);  
		});
	}
	// show proper section navigation
	$('#content #section-nav ul').css('display','block');
	$('#content #section-nav ul ul').css('display','none');
	$('#content #section-nav ul ul ul').css('display','none');
	$('#content #section-nav ul a:path').addClass('active');
	$('#content #section-nav ul a:path:current').addClass('current');
	$('#content #section-nav ul a:path.active').parent().find('> ul').css('display','block');
	if ($('#content #section-nav > ul a:path').length > 1){
		$('#content #section-nav > ul > li:first-child a:path.active').parent().find('> ul').css('display','none');
		$('#content #section-nav > ul > li:first-child a:path').removeClass('active')
		$('#content #section-nav > ul > li:first-child ul li a:path').removeClass('active')
	};
	
	// clean borders form selected nodes
	$('#content #section-nav ul a:path:current').parent().next().find('a span').css('border','none');
	$('#content #section-nav ul a:path:first-child').css('border','none');
	$('#content #section-nav ul a:path:first-child').next().find('a span:first').css('border','none');
	$('#content #section-nav ul a:path:current').parent().parent().parent().next().find('a span').css('border','none');
	$('#content #section-nav ul a:path:current').parent().parent().parent().parent().parent().next().find('a span').css('border','none');
	
	if ($('#content #section-nav ul.nav li a.active span').parent().parent().find('ul').length == 0){
		$('#content #section-nav ul.nav li a.active span').css('background',"#900 url('/ui/img/nav/arrow-fff-03.png') no-repeat 0 11px");
	}
	
	//console.log($('#content #section-nav ul a:path:current'));

	// homepage flash
	$('.home #banner').flash({   
		swf: '/ui/swf/homepage.swf',
		width: 890,
		height: 370 
	});
	
	// article collapsing
	if ($('#content #view .article').length > 0){
		$('#content #view .article').truncate({max_length:250, more:'... More', less:'... Less'});
	}
	
	// project spotlight gallery
	$('#gallery').galleria({history:false,clickNext:true});
	$('.galleria_wrapper').css('width','668px').css('height','252px');
});

// sIFR settings
var tradegothic = { 
	src: '/ui/swf/trade-gothic.swf', 
	ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 61, 1.21, 64, 1.2, 65, 1.21, 112, 1.2, 113, 1.19, 116, 1.2, 118, 1.19, 122, 1.2, 123, 1.19, 1.2] 
};
sIFR.useStyleCheck = true;
sIFR.forceTextTransform = true;
sIFR.activate(tradegothic);
sIFR.replace(tradegothic, { selector: '#content #view h2', css: [ '.sIFR-root { color: #990000; }', '.sIFR-root { text-transform: uppercase; }' ], wmode: 'transparent', tuneHeight: -4} );
sIFR.replace(tradegothic, { selector: '#content #view h3', css: [ '.sIFR-root { color: #333333; }' ], wmode: 'transparent'} );

