$(document).ready(function() {

	//---Resets the hover class on docready (in case it is open for some reason)

	$(".view-projects-menu .proj-menu-container").each(function() {
		$(this).removeClass('hover');
	});



//--- Team Interactivity

	$('.view-team img.imagecache-team_name').hover(
    function(){$(this).stop().animate({width: '220px', height:'163px', top: '-35px', left:'-36px'}, 200);},
		function(){$(this).stop().animate({width: '127px', height:'93px', top: '0', left:'0'}, 100);}
	);

// --- Creates Blackout effect when hovering over menu

	$('#block-nice_menus-1').bind('mouseenter', function() {
		$('#black-screen').addClass('show');
	}).bind('mouseleave', function() {
		$('#black-screen').removeClass('show');
	});


//--- Activates the touch-points on the individual projects page

 	$('.view-projects .touchpoint-trigger').parent().bind('mouseenter mouseleave', function() {
 		$(this).toggleClass('hover');
 	});



// --- Make links open in new window

	$(".view-folio-docs .filefield-file a").each(function() {
		$(this).attr("target", "_blank");
	});


// --- Content Type Cleanup

$(".page-node-add-project fieldset").addClass('hide');
$(".page-node-add-project #edit-taxonomy-1-wrapper").parent().parent().removeClass('hide');
$(".node-type-project.section-node-edit fieldset").addClass('hide');
$(".node-type-project.section-node-edit #edit-taxonomy-1-wrapper").parent().parent().removeClass('hide');
$(".node-type-project.section-node-edit #edit-path-wrapper").parent().parent().removeClass('hide');



//---- Positions slide show images on top of their respective slides

	var view_class = '#block-views-projects-block_3';
	var posx = '#field-touchpoint-x';
	var posy = '#field-touchpoint-y';

	var slidenid = $('.field-bg').attr('slidenid');
//alert(slidenid);
	$('.field-touchpoint.slidenid-'+slidenid).show();

	$(view_class+' .views-row .field-touchpoint').each(function() {
		var left = 0;
		var top = 0;
		$(this).find(posx).each(function() {
			$left = $(this).html();
			$(this).parent().parent().css('left',$left+'px');
			if (($left) > 650) {
				$(this).parent().css('left','-180px');
				//alert ("foo");
			}
		});
		$(this).find(posy).each(function() {
			$top = $(this).html();
			$(this).parent().parent().css('top',$top+'px');
			if (($top) < 200) {
				$(this).parent().css('top','210px');
				//alert ("foo");
			}
		});
	});


//---- Re-labels the Title and Alt to X and Y

	$("#field-touch-point-items tr label").each(function (i) {
		$('#field-touch-point-items').html($('#field-touch-point-items').html().replace('Alternate Text','X-Value'));
		$('#field-touch-point-items').html($('#field-touch-point-items').html().replace('Title','Y-Value'));
	});

	$("#field-touch-point-items tr .form-item").each(function (i) {
		$('#field-touch-point-items').html($('#field-touch-point-items').html().replace('This text will be used by screen readers, search engines, or when the image cannot be loaded.',''));
		$('#field-touch-point-items').html($('#field-touch-point-items').html().replace('The title is used as a tool tip when the user hovers the mouse over the image.',''));
	});

	$(".field-touchpoint-image").each(function (i) {
		$('img').attr('title','');
		$('img').attr('alt','');
	});


//--- Nice Menu Active Fix

	$('#block-nice_menus-1 .active').parent().parent().parent().addClass('active-trail');
	$('#block-nice_menus-1 .active').parent().parent().parent().parent().parent().addClass('active-trail');
	$('#block-nice_menus-1 .active').parent().parent().parent().parent().parent().parent().parent().addClass('active-trail');
	$('#block-nice_menus-1 ul li:last-child').addClass('last');


//--- Cleanup Top Primary Menu

	$('#header #menu-680').remove();
	$('#header #menu-681').remove();
	$('#header #nice-menu-1 li:last-child').addClass('last');


	//--- Front page menu tweaks

	$('#nice-menu-1 li.menu-680').remove();
	$('#nice-menu-1 li.menu-681').remove();

	$(".front #nice-menu-1 li ul").each(function() {
		var count = $(this).children().length;
		$(this).css('top',((count*-40) - 53)+'px');
	});

	$('#header #nice-menu-1 li').bind('mouseenter', function() {
		$(this).addClass('hover');
	}).bind('mouseleave', function() {
		$(this).removeClass('hover');
	});


//--- Enables Dock for Portfolio Projects Page

	//---Get the elements into containers

	$('.view-projects-menu .view-content h3').each(function(){
		$(this).nextUntil('h3').wrapAll('<div class="proj-menu"></div>');
	});
	$('.view-projects-menu .view-content h3').each(function(){
		$(this).nextUntil('h3').andSelf().wrapAll('<div class="proj-menu-container"></div>');
	});


	//---Label the containers

	var menunum = 0;
	$('.view-projects-menu .view-content .proj-menu-container .proj-menu').each(function() {
		menunum ++;
		$(this).attr('id','menu'+menunum);
	});


	//---Get rid of excess containers

	$('.view-projects-menu .view-content img').parent().parent().unwrap();
	$('.view-projects-menu .view-content img').parent().parent().unwrap();
	$('.view-projects-menu .view-content img').parent().parent().contents().unwrap();


	//---Add the first and last designations

	$('.view-projects-menu>.view-content div:first-child').addClass('first');
	$('.view-projects-menu>.view-content div:last-child').addClass('last');


	//---Here is the interactivity

	$('.view-projects-menu .proj-menu-container').bind('mouseenter', function() {
		$(this).addClass('hover');
	}).bind('mouseleave', function() {
		$(this).removeClass('hover');
	});
	$('.view-projects-menu .proj-menu-container a').bind('click', function() {
		$('.view-projects-menu .proj-menu-container').removeClass('hover');
		return true;
	});

	if ($('.view-projects-menu').length>0) {
	$('.view-projects-menu .proj-menu-container.last').html($('.view-projects-menu .proj-menu-container.last').html().replace('military-aerospace','<a href="/portfolio/military-aerospace">military-aerospace</a>'));
				};

//---Disable the links being set on the taxonomy terms (first-level links)

	$('.proj-menu-container h3 a').addClass('disabled');
	$('.proj-menu-container.last h3 a').removeClass('disabled');
	$("a.disabled").click(function(){
		//alert('disabled');
			return false;
	});


//---  Elegantly show the menu once it's done loading

$('#block-views-projects_menu-block_1').css('display','block');

//--- End Dock Code




//--- New Menu Interactivity


	$('.proj-menu img').hover(
    function(){$(this).stop().animate({width: '120px', height:'120px', marginTop: '-20px', marginLeft:'-30px'}, 80);},
		function(){$(this).stop().animate({width: '80px', height:'80px', marginTop: '0px', marginLeft:'0px'}, 40);}
	);

	var timeout;
	$('.proj-menu img').hover(function() {
			id=$(this).parent().attr('id');
		  timeout = setTimeout("$('#'+id+' div').show().css('opacity',0).animate({'opacity':1},200)",100);
		},function() {
			id=$(this).parent().attr('id');
			$('#'+id+' div').hide();
			clearTimeout(timeout);
		}
	);



	//---Resets the hover class on docready (in case it is open for some reason)

	$(".view-projects-menu .proj-menu-container").each(function() {
		$(this).removeClass('hover');
	});



});
