$(document).ready(function() {

	// ---  Start Input Box Interactivity   [not used]

	$('#edit-submitted-phone').each(function() {
			var default_value = this.value;
			$(this).focus(function() {
					if(this.value == default_value) {
							this.value = '';
					}
			});
			$(this).blur(function() {
					if(this.value == '') {
							this.value = default_value;
					}
			});
	});



//---  Removes redundant login buttons

	$('#header a[href$="preferred-vendors"]').remove();



//--- Move the service links around

	$(".front .service-links").prependTo("#block-block-5");


//--- Add some classes

	$('#nice-menu-1>li:last-child').addClass('last');	

	$('#block-block-5 td:contains("Property Type"),#block-block-5 td:contains("Features")').parent().addClass('hide hidden-by-funcs');
	$('#block-block-5 input:text').each(function() {		
		$(this).addClass('input-text');
	});

	//---Sets active class on top level of Nice menu

	if ($('#nice-menu-1 ul li a.active').length>0) {
		$('#nice-menu-1 ul li a.active').parent().parent().parent().addClass('active-trail');
	};
	if ($('#nice-menu-1 ul ul li a.active').length>0) {
		$('#nice-menu-1 ul ul li a.active').parent().parent().parent().parent().parent().addClass('active-trail');
	};


//--- Makes seperate lines of links function as one

	$('.views-row').bind('mouseenter', function() {
		$(this).addClass('hover');
	}).bind('mouseleave', function() {
		$(this).removeClass('hover');
	});

	$('.block').bind('mouseenter', function() {
		$(this).addClass('hover');
	}).bind('mouseleave', function() {
		$(this).removeClass('hover');
	});


// --- Change input background color on focus

	$('#content input').bind('focus', function() {
		$(this).addClass('focus');
	}).bind('blur', function() {
		$(this).removeClass('focus');
	});



// --- Make links open in new window

//--- Set PDFs to open in new window

	$("#content-area a").each(function() {
		$("a[href$='pdf']").attr('target','_blank');
	});

	$("#jdock #block-menu-primary-links").each(function() {
		$("a[href^='http']").attr('target','_blank');
	});

//---- Lightbox Multi-View   [ -- Dont' forget the CSS and to enable the Lightbox 2 Module!!! -- ]
	// These blocks set up a mouseenter event system that replaces the visible detail image with a detail image matching the moused-over thumbnail
	// Visible Thumbnails are in  .views-field-field-images-fid-1
	// Hidden Details are in      .views-field-field-images-fid
	// Visible Detail image is    .views-field-field-images-fid-2

	var view_class = '.view-id-lightbox_multi_view';
	var visible_thumbs = '.views-field-field-images-fid-1';
	var hidden_details = '.views-field-field-images-fid';
	var visible_detail = '.views-field-field-images-fid-2';

	//Give field-images matching item numbers
	$(view_class+' .views-row').each(function() {
		var itemid = 0;
		var sibling = $(this).find(hidden_details+' .field-item:first-child');
		$(this).find(visible_thumbs+' .field-item').each(function() {
			$(this).attr('itemid',itemid);
			sibling.attr('itemid',itemid).addClass('item-'+itemid);
			sibling = sibling.next();
			itemid++;
		});
	});
	//Add mouseenter events to each of the thumbnail images
	$(view_class+' '+visible_thumbs+' img').each(function (i) {
		$(this).bind('mouseenter',function(e){
			viewsrow = $(this).parent().parent().parent().parent().parent();
			var itemid = $(this).parent().parent().attr('itemid');
			var linkobj = $(this).parent();

			previewimg = viewsrow.find(hidden_details+' .item-'+itemid+' img').attr('src');
			viewsrow.find(visible_detail+' img').attr('src',previewimg);
			viewsrow.find(visible_detail+' a').attr('href',linkobj.attr('href'));
		});
	});



//--- Cleanup admin UI

	//--- Lightbox Set, Testimonial, Rotated Image

		var hidden_sections=new Array();
		var i;
	
		hidden_sections[0] = ".page-node-add-lightbox-set";
		hidden_sections[1] = ".node-type-lightbox-set.section-node-edit";
		hidden_sections[2] = ".page-node-add-testimonial";
		hidden_sections[3] = ".node-type-testimonial.section-node-edit";		
		hidden_sections[4] = ".page-node-add-rotated-image";
		hidden_sections[5] = ".node-type-rotated-image.section-node-edit";				
	
		for (i = 0; i < hidden_sections.length; ++i) {
			$(hidden_sections[i]+" #edit-format-2-wrapper").parent().parent().addClass('hide');			
			$(hidden_sections[i]+" #edit-node-weight-wrapper").parent().parent().addClass('hide');						
			$(hidden_sections[i]+" fieldset").addClass('hide');									
			$(hidden_sections[i]+" .body-field-wrapper").addClass('hide');												
		}	
});

