function watchBox(boxtype) {
	//console.log(boxtype,'hitting watchbox');
	if (!($('#'+boxtype+'Icon').hasClass('openbound'))) {
	//console.log(boxtype,'adding click');
	$('#'+boxtype+'Icon').one('click', function(e) {
		activeScan();
		$('#vidWindow').html('');
		$('#rightPanel span').removeClass('active');
		if ($(this).attr('id')=='vidIcon') {
				$('#vidWindow').html('<div><object width="593" height="311"><param name="movie" value="http://www.youtube.com/v/'+window.vid_id+'&hl=en_US&fs=1&color1=0x3a3a3a&color2=0x999999&hd=1&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+window.vid_id+'&hl=en_US&fs=1&color1=0x3a3a3a&color2=0x999999&hd=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="593" height="311"></embed></object></div>');
		}
		//console.log($(this),'removing click');
		$(this).removeClass('openbound').addClass('active').unbind('click');
		$(this).one('click', function(e) {
			//window.runScreenChanger = true;
			$('#videoWindow').html('');
			$('.dialogWindow').hide();
			$(this).removeClass('active');
			watchBox($(this).attr('rel'));
		});
		//window.runScreenChanger = false;
		$('.dialogWindow').hide();
		$('#'+boxtype+'Window').show();
	}).addClass('openbound');
	}
}















function screenFader(items, sliderCount) {
	//console.log('topfader launched');
	//console.log(items);
	
	
	//Set the opacity of all images to 0
	$('#ssBox div.ssItem').css({opacity: 0.0});
	//Get the first image and display it (set it to full opacity)
	$('#ssBox div.ssItem:first').css({opacity: 1.0});
	
	//alert(sliderCount);
	
	if(sliderCount>=1) { 
	window.runScreenChanger=true;
	currentSlider = 0;
	all = $('#ssBox div.ssItem');
		function slidescreen(to, force) {
			if (window.runScreenChanger || force) {
			newto = (to==sliderCount) ? 0 : parseInt(to) + 1;
			$('div#narrBox').fadeOut(500);
			//$('div#ssBox').fadeOut(500, function () {
				
				
		//console.log(all);

	//if no IMGs have the show class, grab the first image
	var current = ($('#ssBox div.show')?  $('#ssBox div.show') : $('#ssBox div:first'));
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	//var next = ((current.next().length) ? current.next() : $('#ssBox div:first'));	
	//Get next image caption
	//var caption = next.find('img').attr('rel');
	//Set the fade in effect for the next image, show class has higher z-index
	$(all[to]).css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 500);
	//Hide the current image
	current.animate({opacity: 0.0}, 500).removeClass('show');
				
				
				//console.log(to); console.log(items[to].capt);
				$('#narrBox').text(items[to].capt);
				$('#paginate-slider4 a').removeClass('current');
				setTimeout(function() { $('div#ssBox').add('div#narrBox').fadeIn(500); $('#paginate-slider4 a[rel=' + to + ']').addClass('current'); }, 500);
			};
			setTimeout(function() { slidescreen(newto, 0); }, 5000);
		}	
	setTimeout(function() { slidescreen(1, 0); }, 6000);
	
	$('#paginate-slider4 a').click(function(e) {
		window.runScreenChanger = false;
		slidescreen($(this).attr('rel'), 1);
		return false;
	});
	}
	
	
}



function activeScan() {
	$('#rightPanel span.active').unbind('click');
	$('#rightPanel span.active').each(function(i) {
		watchBox($(this).attr('rel'));
	});
}

