$(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;
					}
			});
	});

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

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




// --- Make links open in new window

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

	}); 
	
//--- Sets the height of the Nav garnish

	$('#sidebar-left li.active').append('<div class="active-background"><img src="/sites/all/themes/bdi/images/not-front-li-active-bg.png" /><div class="active-garnish"></div></div');
	
	var active_height = $('#sidebar-left li.active a').height(); 
// 	alert(active_height);
	active_height = (active_height + 6);	
	$('#sidebar-left .active-background img').css('height',active_height);	


//--- add social networking to links
	$('#block-menu-secondary-links ul').append('<li class="facebook"><a href="https://www.facebook.com/bdiinsulation" target="_blank"><img src="/sites/default/files/uploaded-images/facebook_16.png" width="16" height="16" style="border: 0px initial initial;" /></a></li>');
	$('#block-menu-secondary-links ul').append('<li class="youtube"><a href="<a href="http://www.youtube.com/user/bdiinsulation1" target="_blank"><img src="/sites/default/files/uploaded-images/youtube_16.png" width="16" height="16" style="border: 0px initial initial;" /></a></li>');

	

//---- 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'));
		});
	});





});
