$( document ).ready( function(){
	
	$( '#navigation li' )
		.mouseover( function(){
			if ( $( this ).parent().hasClass( 'submenu' ) ) return;
			
			$( '#navigation li a' ).removeClass( 'hover' );
			$( this ).find( '.submenu' ).show();
			$( this ).find( 'a' ).addClass( 'hover' );
		})
		.mouseout( function(){
			if ( $( this ).parent().hasClass( 'submenu' ) ) return;
			if ( $( this ).parent().parent().hasClass( 'submenu' ) ) return;
			if ( $( this ).parent().parent().parent().parent().hasClass( 'submenu' ) ) return;
			
			$( '#navigation li a' ).removeClass( 'hover' );
			$( '.submenu' ).hide();
		});
		
	
	$( '.read-more' ).click( function(){
		var div = $( this ).parent().find( '.hidden' );
		if ( div.css('display') == 'none') {
			div.fadeIn('dev');
			$( this ).removeClass('image-button').removeClass('read-more').addClass('hide').html('Hide');
		}else {
			div.hide();
			$( this ).addClass('image-button').addClass('read-more').removeClass('hide').html('Read More');
		}
		//.toggle();
		return false;
	});
	
	$( '.services-learn-more' ).click( function(){
		var div = $( this ).parent().find( '.service-form' );
		if ( div.css('display') == 'none') {
			div.fadeIn('dev');
		}else {
			div.fadeOut('dev');
		}
		return false;
	});
	
	$( '.tabs a' ).click( function(){
		$( '.tabs a' ).removeClass( 'active' );
		$( this ).addClass( 'active' );
		
		var id = $( this ).attr('title') + '-tab';
		$( '.tab-content' ).hide();
		$( '#' + id ).show();
		
		return false;
	});
	
	
	// Slides
	if ( $('.view-slides').length > 0 ) {
		var zindex = $('.view-slides a').length + 1;
		$('.view-slides a').each( function(){
			$(this).css({ 'z-index' : zindex });
			zindex--;
		});
		$('.portfolio-main-image').attr({'href': $('.view-slides a:eq(0)').attr('href') });
		$('.portfolio-main-image img').attr({ 'alt': $('.view-slides a:eq(0) img').attr('alt') });
		
		$('.view-slides a').lightBox();
		
		
		//$('.portfolio-main-image').lightBox();
	} else {
		$('.portfolio-main-image').click( function(){ return false; });
	}
	
	
	$( '.blink' )
		.focus( function(){
			if ( $(this).attr('value') == $(this).attr('title') )
				$(this).attr({ 'value' : '' });
		})
		.blur( function(){
			if ( $(this).attr('value') == '') 
				$(this).attr({ 'value' : $(this).attr('title') })
		});
		
		
	if( $('#report-gallery').length > 0 ) {
		$('.report-gallery-thumbs a').lightBox();
		_set_active_report_image( $('.report-gallery-thumbs a:eq(0)') );
		
		$('.report-gallery-thumbs a').hover(
			function(){
				_set_active_report_image( $( this ) );
			},
			function(){}
		);
	}
	
	
	$('#header-flash').click( function(){ /*expand_header_flash();*/ });
	
});

function _set_active_report_image ( anchor ) {
	$('.report-gallery-thumbs a').removeClass('active-image');
	var html = '<a href="' + $( anchor ).attr('href') + '" class="_lightbox">' + $( anchor ).html() + '</a>';
	$('#report-big-image').html( html );
	$( anchor ).addClass('active-image');
	
	$('#report-big-image a').lightBox();
}

function open_window( id ) {
	var h = $( 'body' ).height() > $( window ).height() ? $( 'body' ).height() : $( window ).height();
	$('#black-screen').css({ 'height': h });
			
	$( '#black-screen' ).show().css({ 'opacity': 0 });
	$( '#black-screen' ).fadeTo( 'dev', 0.8, function(){
		$( id ).show();
	});
}

function close_window( id ) {
	$( id ).hide();
	$( '#black-screen' ).fadeTo( 'dev', 0, function(){
		$( this ).hide();
	});
	return false;
}


function expand_header_flash() { $('#header-flash').css({'z-index' : '4002'}); }
function collapse_header_flash(){ $('#header-flash').css({'z-index' : '4000'}); }