var TimeToFade = 250;

var xmlHttp;

window.MessageWindowDisplayed = false;


function switchTab(thisTab, tabNumber)
{
	if(thisTab != null && thisTab.className.indexOf('Active') == -1 && tabNumber > 0 && tabNumber < 4)
	{
		if(tabNumber == 1)
		{
			if(thisTab.nextSibling.className.indexOf('Active') != -1)
			{
				thisTab.nextSibling.className = thisTab.nextSibling.className.replace('Active', '');
				thisTab.nextSibling.nextSibling.nextSibling.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
			else if(thisTab.nextSibling.nextSibling.className.indexOf('Active') != -1)
			{
				thisTab.nextSibling.nextSibling.className = thisTab.nextSibling.nextSibling.className.replace('Active', '');
				thisTab.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
		}
		else if(tabNumber == 2)
		{
			if(thisTab.previousSibling.className.indexOf('Active') != -1)
			{
				thisTab.previousSibling.className = thisTab.previousSibling.className.replace('Active', '');
				thisTab.nextSibling.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
			else if(thisTab.nextSibling.className.indexOf('Active') != -1)
			{
				thisTab.nextSibling.className = thisTab.nextSibling.className.replace('Active', '');
				thisTab.nextSibling.nextSibling.nextSibling.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
		}
		else if(tabNumber == 3)
		{
			if(thisTab.previousSibling.className.indexOf('Active') != -1)
			{
				thisTab.previousSibling.className = thisTab.previousSibling.className.replace('Active', '');
				thisTab.nextSibling.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
			else if(thisTab.previousSibling.previousSibling.className.indexOf('Active') != -1)
			{
				thisTab.previousSibling.previousSibling.className = thisTab.previousSibling.previousSibling.className.replace('Active', '');
				thisTab.nextSibling.style.display = 'none';
				
				thisTab.className = thisTab.className + 'Active';
				thisTab.nextSibling.nextSibling.nextSibling.style.display = 'block';
			}
		}
	}
}

var ZeroDegreeYouTubePlayers = {};

function onytplayerStateChange(newState) {
	alert(newState.parentNode);
	//alert("Player's new state: " + newState);
}

function onYouTubePlayerReady(id)
{
	//alert("Event Fired");
	
	
	
	var thisPlayer = document.getElementById(id);
	
	
	
	//thisPlayer.id = 'test';
	
	var GalleryContainer = thisPlayer.parentNode.parentNode;
	
	
	/*
	var MediaContainer =  document.getElementById(id).parentNode;
	
	alert(MediaContainer.tagName);
	
	var GalleryContainer = MediaContainer.parentNode;
	
	alert("Down Here...");
	*/
	//alert(document.getElementById(id).getVideoUrl());
	
	if(GalleryContainer != null && parseInt(GalleryContainer.GalleryId) >= 0)
	{
		//thisPlayer.id = 'ZeroDegreeGallery_' + GalleryContainer.GalleryId + '_' + window.ZeroDegreeGallery[GalleryContainer.GalleryId].getVideosQuantity();
		
		
		
		
		if(thisPlayer != null && thisPlayer.tagName != 'P')
		{
			//alert(thisPlayer.getVideoUrl());
		}
		else
		{
			
			thisPlayer = window.ZeroDegreeGallery[GalleryContainer.GalleryId].getElementByOldId(id);
			
			
			
			if(thisPlayer != null)
			{
				//alert(thisPlayer.getVideoUrl());
				
				//thisPlayer.playVideo();
				
				//thisPlayer.addEventListener("onStateChange", "onytplayerStateChange");
				
				 ZeroDegreeYouTubePlayers[thisPlayer.id] = function (state) { 
					//alert(thisPlayer.id);
				}; 
				
				thisPlayer.addEventListener("onStateChange", "ZeroDegreeYouTubePlayers." + thisPlayer.id); 
				
			}
			else
			{
				//alert("Player Not Found");
			}
		}
		
		//alert(thisPlayer.getVideoUrl());
		//alert(thisPlayer.id);
	}
	
	//alert(thisPlayer.parentElement.parentElement.GalleryId);
	
	
}




function ZeroDegreeGallery(galleryId, id)
{
	this.hideGallery = function()
	{
		
		if(this.mediaCount > 1)
		{
			if(this.scrollingPreview)
			{
				$(this.container).animate({height: '0px'}, 500, 'easeInOutCubic');
			}
			else
			{
				$(this.container).animate({height: '0px'}, 500, 'easeInOutCubic');
			}
			
			$(this.contentContainer).delay(500).animate({opacity: '0'}, 500, 'easeInOutCubic');
			
			$("IMG", this.previewContainer).animate({opacity: '0'}, 500, 'easeInOutCubic');
			
		//	$("IMG", this.mediaPreviews[0]).stop(true, false).animate({opacity: '1'}, 500, 'easeInOutCubic');
		}
		else
		{
			$(this.container).animate({height: '0px'}, 500, 'easeInOutCubic');
			
			$(this.contentContainer).delay(500).animate({opacity: '0'}, 500, 'easeInOutCubic');
		}
		
		this.galleryShown = false;
	}
	
	this.showGallery = function()
	{
		
		
		if(this.mediaCount > 1)
		{
			if(this.scrollingPreview)
			{
				$(this.container).animate({height: (parseInt(this.maxHeight) + 120) + 'px'}, 500, 'easeInOutCubic');
			}
			else
			{
				$(this.container).animate({height: (parseInt(this.maxHeight) + 100) + 'px'}, 500, 'easeInOutCubic');
			}
			
			$(this.contentContainer).delay(500).animate({opacity: '1'}, 500, 'easeInOutCubic');
			
			$("IMG", this.previewContainer).animate({opacity: '.75'}, 500, 'easeInOutCubic');
			
	//		$("IMG", this.mediaPreviews[0]).stop(true, false).animate({opacity: '1'}, 500, 'easeInOutCubic');
		}
		else
		{
			$(this.container).animate({height: (parseInt(this.maxHeight) + 10) + 'px'}, 500, 'easeInOutCubic');
			
			$(this.contentContainer).delay(500).animate({opacity: '1'}, 500, 'easeInOutCubic');
		}
		
		this.galleryShown = true;
	
	}
	
	this.getVideoId = function(url)
	{
		var videoSplit = url.split('?');
		if(videoSplit.length == 2)
		{
			var videoArgsSplit = videoSplit[1].split('&');
			var i = 0;
			
			while(i < videoArgsSplit.length)
			{
				if(videoArgsSplit[i].indexOf('v=') == 0)
				{
					var videoIdSplit = videoArgsSplit[i].split('=');
					if(videoIdSplit.length == 2)
					{
						return(videoIdSplit[1]);
					}
				}
				i++;
			}	
			return ('');
		}
		else
		{
			return (videoField.value);
		}
	}
	
	//this.createPreview function(img_id, crop_id, x, y, width, height) {
	//	$(crop_id).update('<img id="' + crop_id + '_img" src="' + $(img_id).getAttribute('src') + '" style="display:none" />');
	
	this.getPreview = function(source)
	{
		var imgContainer = null;
		
		var newImg = null;
		
		//alert("getPreview");
		
		if(source != null && (source.tagName == "IMG" || source.tagName == 'OBJECT' || source.tagName == 'DIV'))
		{
			imgContainer = document.createElement("DIV");
			
			imgContainer.style.position = 'absolute';
			
			imgContainer.style.overflow = 'hidden';
			
			//$(imgContainer).css({'border': 'none', 'border-bottom-left-radius' : '10px 10px', 'border-bottom-right-radius' : '10px 10px', 'border-top-left-radius' :'10px 10px', 'border-top-right-radius' : '10px 10px'});
			
			//$(imgContainer).corner("10px");
			
			imgContainer.style.height = '75px';
			
			imgContainer.style.width = '75px';
			
			imgContainer.OriginalWidth = 75;
			
			imgContainer.OriginalHeight = 75;
			
			$(imgContainer).css({border: '3px double #ccc'});
			
			
			
			//imgMask = document.createElement("A");
			
			newImg = document.createElement("IMG");
			
			newImg.style.position = 'absolute';
			
			//newImg.style.display = 'inline';
			
			$(newImg).css({opacity: '.75'});
			
			
			$(newImg).load(function() {  
						   
						   var new_w = 75;
						   var new_h = 75;
						   
						   var nw = 75;
						   var nh = 75;
						   
						   var h = this.height;
						   var w = this.width;
						   
						   
						   var old_x = w;
						   var old_y = h;
						   
						   var thumb_w = 0;
						   var thumb_h = 0;
						   
						   if((old_x > new_w) || (old_y > new_h))
						   {
							if ((old_x/new_w) < (old_y/new_h)) 
						   {
						   thumb_w = new_w;
						   thumb_h = old_y * (new_w / old_x);
						   }
						   else if ((old_x / new_w) > (old_y / new_h)) 
						   {
						   thumb_w = old_x * (new_h / old_y);
						   thumb_h = new_h;
						   }
						   else
						   {
						   thumb_w = new_w;
						   thumb_h = new_h;
						   }
						   }
						   else
						   {
						   thumb_w = old_x;
						   thumb_h = old_y;
						   }
						   
						   var wm = thumb_w / nw;
						   var hm = thumb_h / nh;
						   
						   var h_height = nh / 2;
						   var w_height = nw / 2;
						   
						   
						   var half_height = thumb_h / 2;
						   
						   var int_height = half_height - h_height;
						   
						   var half_width = thumb_w / 2;
						   var int_width = half_width - w_height;
						   
						   this.style.height = thumb_h + 'px';
						   
						   this.style.width = thumb_w + 'px';
						   
						   this.OriginalHeight = thumb_h;
						   
						   this.OriginalWidth = thumb_w;
						   
						   this.OriginalTop = (-1 * int_height);
						   
						   this.OriginalLeft = (-1 * int_width);
						   
						   this.style.top = (-1 * int_height) + 'px';
						   
						   this.style.left = (-1 * int_width) + 'px';
						   
						   
						  // $(this).css('opacity', '.75');
						   
						   });
			
			
			newImg.Gallery = this;
			
			newImg.MediaId = source.MediaId;
			
			if (source.tagName == 'OBJECT' || source.tagName == 'DIV')
			{
				newImg.src = "http://img.youtube.com/vi/" + source.name + "/1.jpg";
			}
			else
			{
				newImg.src = source.src;
			}
			
			
			
			//newImg.style.width = '130px';
			
			//newImg.style.height = '97px';
			
			
			//imgMask.appendChild(newImg);
			
			//imgContainer.appendChild(imgMask);
			
			imgContainer.appendChild(newImg);
		}
		
		/*
		else if(source != null && (source.tagName == 'OBJECT' || source.tagName == 'DIV'))
		{
			imgContainer = document.createElement("DIV");
			
			imgContainer.style.position = 'absolute';
			
			imgContainer.style.overflow = 'hidden';
			
			imgContainer.style.height = '75px';
			
			imgContainer.style.width = '75px';
			
			newImg = document.createElement("IMG");
			
			newImg.style.position = 'absolute';
			
			$(newImg).load(function() {  
			
			var new_w = 75;
			var new_h = 75;
			
			var nw = 75;
			var nh = 75;
			
			var h = this.height;
			var w = this.width;
			
			
			var old_x = w;
			var old_y = h;
			
			var thumb_w = 0;
			var thumb_h = 0;
			
			if((old_x > new_w) || (old_y > new_h))
			{
				if ((old_x/new_w) < (old_y/new_h)) 
				{
					thumb_w = new_w;
					thumb_h = old_y * (new_w / old_x);
				}
				else if ((old_x / new_w) > (old_y / new_h)) 
				{
					thumb_w = old_x * (new_h / old_y);
					thumb_h = new_h;
				}
				else
				{
					thumb_w = new_w;
					thumb_h = new_h;
				}
			}
			else
			{
				thumb_w = old_x;
				thumb_h = old_y;
			}
			
			var wm = thumb_w / nw;
			var hm = thumb_h / nh;
			
			var h_height = nh / 2;
			var w_height = nw / 2;
			
			
			var half_height = thumb_h / 2;
			
			var int_height = half_height - h_height;
			
			var half_width = thumb_w / 2;
			var int_width = half_width - w_height;
			
			this.style.height = thumb_h + 'px';
			
			this.style.width = thumb_w + 'px';
			
			this.style.top = (-1 * int_height) + 'px';
			
			this.style.left = (-1 * int_width) + 'px';
						   });
			
			newImg.src = "http://img.youtube.com/vi/" + source.name + "/1.jpg";
			
			imgContainer.appendChild(newImg);
			
			//alert(source.name);
			
			//alert(source.ytid);
			
			//var videoId = this.getVideoId(source.getVideoUrl());
			
			//alert(videoId);
			
		}
		*/
		return (imgContainer);
	}
	
	/*
	{
		var imgContainer = null;
		
		var newImg = null;
		
		//alert("getPreview");
		
		if(source != null && source.tagName == "IMG")
		{
			imgContainer = document.createElement("DIV");
			
			imgContainer.style.position = 'absolute';
			
			imgContainer.style.overflow = 'hidden';
			
			imgContainer.style.height = '75px';
			
			imgContainer.style.width = '75px';
			
			newImg = document.createElement("IMG");
			
			newImg.style.position = 'absolute';
			
			newImg.src = source.src;
			
			
			
			//newImg.style.width = '130px';
			
			//newImg.style.height = '97px';
			
			var new_w = 75;
			var new_h = 75;
			
			var nw = 75;
			var nh = 75;
			
			if (window.BrowserDetect.browser == "Explorer")
			{
				var tempImage = new Image() 
				tempImage.src = source.src;
				var h = tempImage.height;
				var w = tempImage.width;
			}
			else
			{
				var h = source.height;
				var w = source.width;
			}
			
			var old_x = w;
			var old_y = h;
			
			var thumb_w = 0;
			var thumb_h = 0;
			
			if((old_x > new_w) || (old_y > new_h))
			{
				if ((old_x/new_w) < (old_y/new_h)) 
				{
					thumb_w = new_w;
					thumb_h = old_y * (new_w / old_x);
				}
				else if ((old_x / new_w) > (old_y / new_h)) 
				{
					thumb_w = old_x * (new_h / old_y);
					thumb_h = new_h;
				}
				else
				{
					thumb_w = new_w;
					thumb_h = new_h;
				}
			}
			else
			{
				thumb_w = old_x;
				thumb_h = old_y;
			}
			
			var wm = thumb_w / nw;
			var hm = thumb_h / nh;
			
			var h_height = nh / 2;
			var w_height = nw / 2;
			
			
			var half_height = thumb_h / 2;
			
			var int_height = half_height - h_height;
			
			var half_width = thumb_w / 2;
			var int_width = half_width - w_height;
			
			newImg.style.height = thumb_h + 'px';
			
			newImg.style.width = thumb_w + 'px';
			
			newImg.style.top = (-1 * int_height) + 'px';
			
			newImg.style.left = (-1 * int_width) + 'px';
			
			imgContainer.appendChild(newImg);
		}
		else if(source != null && (source.tagName == 'OBJECT' || source.tagName == 'DIV'))
		{
			imgContainer = document.createElement("DIV");
			
			imgContainer.style.position = 'absolute';
			
			imgContainer.style.overflow = 'hidden';
			
			imgContainer.style.height = '75px';
			
			imgContainer.style.width = '75px';
			
			newImg = document.createElement("IMG");
			
			newImg.style.position = 'absolute';
			
			newImg.src = "http://img.youtube.com/vi/" + source.name + "/1.jpg";
			
			var new_w = 75;
			var new_h = 75;
			
			var nw = 75;
			var nh = 75;
			
			if (window.BrowserDetect.browser == "Explorer")
			{
				var tempImage = new Image() 
				tempImage.src = source.src;
				var h = tempImage.height;
				var w = tempImage.width;
			}
			else
			{
				var h = source.height;
				var w = source.width;
			}
			
			var old_x = w;
			var old_y = h;
			
			var thumb_w = 0;
			var thumb_h = 0;
			
			if((old_x > new_w) || (old_y > new_h))
			{
				if ((old_x/new_w) < (old_y/new_h)) 
				{
					thumb_w = new_w;
					thumb_h = old_y * (new_w / old_x);
				}
				else if ((old_x / new_w) > (old_y / new_h)) 
				{
					thumb_w = old_x * (new_h / old_y);
					thumb_h = new_h;
				}
				else
				{
					thumb_w = new_w;
					thumb_h = new_h;
				}
			}
			else
			{
				thumb_w = old_x;
				thumb_h = old_y;
			}
			
			var wm = thumb_w / nw;
			var hm = thumb_h / nh;
			
			var h_height = nh / 2;
			var w_height = nw / 2;
			
			
			var half_height = thumb_h / 2;
			
			var int_height = half_height - h_height;
			
			var half_width = thumb_w / 2;
			var int_width = half_width - w_height;
			
			newImg.style.height = thumb_h + 'px';
			
			newImg.style.width = thumb_w + 'px';
			
			newImg.style.top = (-1 * int_height) + 'px';
			
			newImg.style.left = (-1 * int_width) + 'px';
			
			
			
			imgContainer.appendChild(newImg);
			
			//alert(source.name);
			
			//alert(source.ytid);
			
			//var videoId = this.getVideoId(source.getVideoUrl());
			
			//alert(videoId);
			
		}
		
		return (imgContainer);
	}
	 */
	
	this.nextMediaItem = function()
	{
		if(this.currentMediaId != null && $(this.contentContainer).queue() == 0 && $(this.extraContainer).queue() == 0)
		{
			//this.navRight.oldClick = this.navRight.onclick;
			
			//this.navRight.onclick = null;
			
			//$(this.navRight).preventDefault();
			
			this.moving = true;
			
			if(this.currentMediaId + 1 < this.mediaCount)
			{
				/*
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				{
					if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
					{
						this.mediaItems[this.currentMediaId].stopVideo();
					}
				}*/
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');

				this.extraContainer.style.left = this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				
				
				if(this.mediaItems[this.currentMediaId + 1].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[this.currentMediaId + 1].CaptionOffset) / 2 - 1) + "px; line-height: 15px; font-size: 13px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[this.currentMediaId + 1].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[this.currentMediaId + 1]);
				
				this.currentMediaId++;
				
				
				$(this.contentContainer).stop(true,true).animate({left: '-=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					//$(this.extraContainer).css('opacity', '0');
					
					
					
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				
				//var previewLeft = parseInt(this.previewContainer.style.left.replace('px', ''));
				
				//if(this.currentMediaId * 85)
				
				  // $(this.scrollBar).slider( "value" , 100 );
				
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				//while($(this.extraContainer).queue() > 0) {}
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				//this.extraContainer.innerHTML = '';
				
				this.tempContainer = null;
			}
			else if(this.currentMediaId + 1 == this.mediaCount)
			{
				/*
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				{
					if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
					{
						this.mediaItems[this.currentMediaId].stopVideo();
					}
				}*/
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');
				
				this.extraContainer.style.left = this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				
				
				if(this.mediaItems[0].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[0].CaptionOffset) / 2 - 1) + "px; line-height: 15px; font-size: 13px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[0].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[0]);
				
				this.currentMediaId = 0;
				
				$(this.contentContainer).stop(true,true).animate({left: '-=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				//while($(this.extraContainer).queue() > 0) {}
				
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				//this.extraContainer.innerHTML = '';
				
				this.tempContainer = null;
			}
			
			this.moving = false;
			
			//this.navRight.onclick = this.navRight.oldClick;
			
			//this.oldClick = null;
		}
	}
	
	this.previousMediaItem = function()
	{
		if(this.currentMediaId != null && $(this.contentContainer).queue() == 0 && $(this.extraContainer).queue() == 0)
		{
			this.moving = true;
			
			if(this.currentMediaId - 1 > -1)
			{
				/*
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				{
					if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
					{
						this.mediaItems[this.currentMediaId].stopVideo();
					}
				}
				*/
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');
				
				this.extraContainer.style.left = '-' + this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				
				
				if(this.mediaItems[this.currentMediaId - 1].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[this.currentMediaId - 1].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[this.currentMediaId - 1].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[this.currentMediaId - 1]);
				
				this.currentMediaId--;
				
				$(this.contentContainer).stop(true,true).animate({left: '+=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				this.tempContainer = null;
			}
			else if(this.currentMediaId == 0)
			{
				/*
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				{
					if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
					{
						this.mediaItems[this.currentMediaId].stopVideo();
					}
				}*/
				
				$(this.mediaPreviews[this.currentMediaId]).animate({opacity: '.75', borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');
				
				this.extraContainer.style.left = '-' + this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				
				
				if(this.mediaItems[this.mediaCount - 1].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[this.mediaCount - 1].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[this.mediaCount - 1].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[this.mediaCount - 1]);
				
				this.currentMediaId = this.mediaCount - 1;
				
				$(this.contentContainer).stop(true,true).animate({left: '+=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				this.tempContainer = null;
			}
			
			this.moving = false;
		}
	}
	
	this.showMediaItem = function(id)
	{
		if(parseInt(id) >= 0 && this.mediaItems[id] != null && this.currentMediaId != null && $(this.contentContainer).queue() == 0 && $(this.extraContainer).queue() == 0)
		{
			if(this.currentMediaId < id)
			{
				/*
				 if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				 {
				 if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
				 {
				 this.mediaItems[this.currentMediaId].stopVideo();
				 }
				 }*/
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');
				
				this.extraContainer.style.left = this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				if(this.mediaItems[id].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[id].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[id].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[id]);
				
				this.currentMediaId = id;
				
				
				$(this.contentContainer).stop(true,true).animate({left: '-=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					//$(this.extraContainer).css('opacity', '0');
					
					
					
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '-=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');		
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				//while($(this.extraContainer).queue() > 0) {}
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				//this.extraContainer.innerHTML = '';
				
				this.tempContainer = null;
			}
			else if(this.currentMediaId > id)
			{
				/*
				 if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId.tagName == 'DIV'])
				 {
				 if(this.mediaItems[this.currentMediaId].getPlayerState() > 0)
				 {
				 this.mediaItems[this.currentMediaId].stopVideo();
				 }
				 }
				 */
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#CCC', borderBottomColor: '#CCC', borderLeftColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '.75'}, 250, 'easeInOutCubic');
				
				this.extraContainer.style.left = '-' + this.maxWidth + 'px';
				
				this.extraContainer.innerHTML = '';
				
				
				
				if(this.mediaItems[id].Caption != '')
				{
					this.extraContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.extraContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.extraContainer.offsetHeight - this.mediaItems[id].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[id].Caption + "</div>";
				}
				
				this.extraContainer.appendChild(this.mediaItems[id]);
				
				this.currentMediaId = id;
				
				$(this.contentContainer).stop(true,true).animate({left: '+=' + this.maxWidth + 'px', opacity: '0'}, 1200, 'easeInOutCubic', function() { $(this).html(''); });
				
				if(this.mediaItems[this.currentMediaId].tagName == 'OBJECT' || this.mediaItems[this.currentMediaId].tagName == 'DIV')
				{
					$(this.extraContainer).stop(true,true).delay(800).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				else
				{
					$(this.extraContainer).stop(true,true).delay(250).animate({left: '+=' + this.maxWidth + 'px', opacity: '1'}, 600, 'easeInOutCubic');
				}
				$(this.scrollBar).slider("value", (this.currentMediaId / (this.mediaCount - 1)) * 100);
				
				$(this.mediaPreviews[this.currentMediaId]).animate({borderTopColor: '#333', borderBottomColor: '#333', borderLeftColor: '#333', borderRightColor: '#333'}, 250, 'easeInOutCubic');
				
				$(this.mediaPreviews[this.currentMediaId].firstChild).animate({opacity: '1'}, 250, 'easeInOutCubic');
				
				this.tempContainer = this.contentContainer;
				
				this.contentContainer = this.extraContainer;
				
				this.extraContainer = this.tempContainer;
				
				this.tempContainer = null;
			}
		}
	}
	
	this.getVideosCount = function()
	{
		return(this.videosCount);
	}
	
	this.getElementByOldId = function(id)
	{
		return (document.getElementById(this.mediaOriginalIds[id]));
	}
	
	var container = document.getElementById(id);
	if(container != null)
	{
		this.container = container;
		
		this.container.GalleryId = galleryId;
		
		this.GalleryId = galleryId;
		
		this.container.id = 'Zero_Degree_Gallery_' + galleryId;
		
		this.container.style.width = '100%';
		
		this.container.style.overflow = 'hidden';
		
		this.container.style.position = 'relative';
		
		this.container.style.height = '0px';
		
		//alert(this.container.offsetWidth);
		
		this.mediaContainer = this.container.firstChild;
		
		
		if(this.mediaContainer != null)
		{
			//this.mediaContainer.style.display = 'none';
			
			//this.YouTubePlayers = {}; 
			
			this.mediaContainer.style.position = 'absolute';
			
			this.mediaContainer.style.overflow = 'hidden';
			
			this.mediaContainer.style.height = '0px';
			
			this.mediaContainer.style.width = '0px';
			
			this.mediaContainer.style.left = '-' + (this.container.offsetWidth * 2) + 'px';
			
			this.mediaContainer.style.display = 'block';
			
			
			this.contentContainer = document.createElement("DIV");
			
			this.contentContainer.style.position = 'absolute';
			
			this.contentContainer.style.top = '0px';
			
			this.contentContainer.style.left = '0px';
			
			this.contentContainer.style.width = this.container.offsetWidth + 'px';
			
			this.contentContainer.style.zIndex = '50';
			
			this.container.appendChild(this.contentContainer);
			
			
			this.extraContainer = document.createElement("DIV");
			
			this.extraContainer.style.position = 'absolute';
			
			this.extraContainer.style.top = '0px';
			
			this.extraContainer.style.left = this.container.offsetWidth + 'px';
			
			this.extraContainer.style.width = this.container.offsetWidth + 'px';
			
			this.extraContainer.style.zIndex = '50';
			
			this.container.appendChild(this.extraContainer);
			
			
			this.tempContainer = null;
			
			this.currentMediaId = null;
			
			
			//this.mediaContainer.style.opacity = '0';
			
			//this.mediaContainer.style.filter = 'alpha(opacity = 0)';
			
			
			//alert(this.mediaContainer.firstChild.getVideoBytesLoaded());
			
			this.moving = false;
			
			this.videosCount = 0;
			
			this.imagesCount = 0;
			
			this.mediaCount = 0;
			
			this.maxHeight = 0;
			
			this.scrollingPreview = false;
			
			this.maxWidth = this.container.offsetWidth;
			
			var currentHeight = 0;
			
			this.mediaItems = new Array();
			
			this.mediaCaptions = new Array();
			
			this.mediaPreviews = new Array();
			
			this.mediaOriginalIds = new Object();
			
			this.images = new Array();
			
			this.videos = new Array();
			
			var mediaItem = this.mediaContainer.firstChild;
			
			var previousItem = null;
			
			var oldId = null;
			
			var oldReferenceElement = null;
			
			this.mediaItems = new Array();
			
			while(mediaItem != null)
			{
				//alert(mediaItem.tagName);
				
				if(mediaItem.tagName == 'IMG')
				{
					
					
					oldId = mediaItem.id;
					
					this.mediaOriginalIds[mediaItem.id] = 'Gallery_' + this.GalleryId + '_Media_' + this.mediaCount;
					
					oldReferenceElement = document.createElement("P");
					
					
					
					mediaItem.id = this.mediaOriginalIds[mediaItem.id];
					
					oldReferenceElement.id = oldId;
					
					oldReferenceElement.innerHTML = this.mediaOriginalIds[mediaItem.id];
					
					this.mediaContainer.insertBefore(oldReferenceElement, mediaItem);
					
					//mediaItem = this.getPreview(mediaItem);
					
					//mediaItem.id = this.mediaOriginalIds[oldId];

					
					if (window.BrowserDetect.browser == "Explorer")
					{
						var tempImage = new Image() 
						tempImage.src = mediaItem.src;
						currentHeight = tempImage.height;
					}
					else
					{
						currentHeight = mediaItem.height;
					}
					
					mediaItem.style.verticalAlign = 'middle';
					
					mediaItem.GalleryId = galleryId;
					
					mediaItem.CaptionOffset = mediaItem.offsetHeight;
					
					mediaItem.Caption = '';
					
					mediaItem.style.cursor = 'pointer';
					
					mediaItem.onmousedown = function(e) {
						if (navigator.appName == 'Netscape' && e.which == 3) {
							//alert("J. Geil Says: Please Don't Steal Our Photos!")
							//return false;
							var win = window.open("http://wednesdayjournalonline.mycapture.com/mycapture/index.asp","PhotoStore");
							win.focus();
						}
						else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
								//alert("J. Geil Says: Please Don't Steal Our Photos!")
								//return false;
							var win = window.open("http://wednesdayjournalonline.mycapture.com/mycapture/index.asp","PhotoStore");
							win.focus();
						}
						return false;
					}
					
					mediaItem.onmouseup = function(e) {
						if (navigator.appName == 'Netscape' && e.which == 3) {
							//alert("no right click please")
							//return false;
						}
						else if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
							//alert("no right click please")
							//return false;
						}
						return false;
					}
					
					mediaItem.oncontextmenu = function(e) {
						
						return false;
					}
					
					mediaItem.ondragstart = function(e) {
						
						return false;
					}
					
					mediaItem.ondrag = function(e) {
						
						return false;
					}
					
					mediaItem.ondragend = function(e) {
						
						return false;
					}
					
					mediaItem.onclick = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{	
							
							var gallery = window.ZeroDegreeGallery[element.GalleryId];
							
							if(gallery != null)
							{
								if(gallery.mediaCount > 1)
								{
									gallery.nextMediaItem();
								}
							}
						}
						
					}
					
					mediaItem.imagesCount = this.imagesCount;
					
					mediaItem.mediaCount = this.mediaCount;
					
					previousItem = mediaItem;
					
					this.mediaItems[this.mediaCount] = mediaItem;
					
					mediaItem.MediaId = this.mediaCount;
					
					this.mediaPreviews[this.mediaCount] = this.getPreview(mediaItem);
					
					this.mediaPreviews[this.mediaCount].MediaId = this.mediaCount;
					
					this.mediaPreviews[this.mediaCount].Gallery = this;
					
					
					
					this.imagesCount++;
					
					this.mediaCount++;
				}
				else if(mediaItem.tagName == 'OBJECT' || mediaItem.tagName == 'DIV')
				{
					//alert("Object Found");
					
					oldId = mediaItem.id;
					
					this.mediaOriginalIds[mediaItem.id] = 'Gallery_' + this.GalleryId + '_Media_' + this.mediaCount;
					
					oldReferenceElement = document.createElement("P");
					
					mediaItem.id = this.mediaOriginalIds[mediaItem.id];
					
					mediaItem.Caption = '';
					
					oldReferenceElement.id = oldId;
					
					oldReferenceElement.innerHTML = this.mediaOriginalIds[mediaItem.id];
					
					this.mediaContainer.insertBefore(oldReferenceElement, mediaItem);
					
					//mediaItem = this.getPreview(mediaItem);
					
					//mediaItem.id = this.mediaOriginalIds[oldId];
					
					previousItem = mediaItem;
					
					currentHeight = mediaItem.height;
					
					this.mediaItems[this.mediaCount] = mediaItem;
					
					this.mediaPreviews[this.mediaCount] = this.getPreview(mediaItem);
					
					this.mediaPreviews[this.mediaCount].MediaId = this.mediaCount;
					
					this.mediaPreviews[this.mediaCount].Gallery = this;
					
					this.videosCount++;
					
					this.mediaCount++;
				}
				else if(mediaItem.tagName == 'P' && previousItem != null && mediaItem.innerHTML != '')
				{
					//alert('setting caption');
					previousItem.Caption += mediaItem.innerHTML;
				}
				else if(mediaItem.tagName != 'SCRIPT')
				{
					previousItem = null;
					
				}
				
				if(currentHeight > this.maxHeight)
				{
					this.maxHeight = currentHeight;
				}
				
				
				
				currentHeight = 0;
				
				mediaItem = mediaItem.nextSibling;
			}
			
			//this.maxHeight = 200;
			
			
			if(this.mediaCount > 0)
			{
				if(this.mediaCount > 1)
				{
					this.navLeftLoaded = false;
					
					this.navRightLoaded = false;
					
					this.galleryShown = false;
					
					this.navigationInitialized = false;
					
					this.navLeft = new Image();
					
					this.navLeft.GalleryId = galleryId;
					
					this.navLeft.maxHeight = this.maxHeight;
					
					this.navLeft.maxWidth = this.container.offsetWidth;
					
					this.navLeft.style.position = 'absolute';
					
					this.navLeft.style.display = 'none';
					
					this.navLeft.style.cursor = 'pointer';
					
					this.navLeft.style.zIndex = '51';
					
					this.navLeft.style.left = '-' + this.container.offsetWidth + 'px';
					
					$(this.navLeft).css('opacity', '0');
					
					this.container.appendChild(this.navLeft);
					
					this.navLeft.onload = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							element.style.top =  '-' + element.height + 'px';
							
							var newTop = ((element.maxHeight / 2) - (element.height / 2)) + 'px';
							
							element.style.left = '0px';
							
							element.style.display = 'block';
							
							$(element).delay(1500).animate({opacity: '0.5', top: newTop}, 500, 'easeInOutCubic');	
						}
						
					};
					
					this.navLeft.onmouseover = function(e) {
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).stop(true, true).animate({opacity: '1'}, 500, 'easeInOutCubic');
						}
					}
					
					this.navLeft.onmouseout = function(e) {
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).stop(true, true).animate({opacity: '0.5'}, 500, 'easeInOutCubic');
						}
					}
					
					this.navLeft.onclick = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{	
							
							var gallery = window.ZeroDegreeGallery[element.GalleryId];
							
							if(gallery != null)
							{
								gallery.previousMediaItem();
							}
						}
						
					}
					
					this.navLeft.onmousedown = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).css('opacity', '.75');
						}
					}
					
					this.navLeft.onmouseup = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).css('opacity', '1');
						}
					}
					
					this.navLeft.src = "http://zerodegreemedia.info/ZeroDegreeGallery/smallLeft.png";
					
					this.contentContainer.style.lineHeight = this.maxHeight + 'px';
					
					this.extraContainer.style.lineHeight = this.maxHeight + 'px';
					
					this.navRight = new Image();
					
					this.navRight.GalleryId = galleryId;
					
					this.navRight.maxHeight = this.maxHeight;
					
					this.navRight.maxWidth = this.container.offsetWidth;
					
					this.navRight.style.position = 'absolute';
					
					this.navRight.style.display = 'none';
					
					this.navRight.style.cursor = 'pointer';
					
					this.navRight.style.zIndex = '51';
					
					this.navRight.style.left = '-' + this.container.offsetWidth + 'px';
					
					$(this.navRight).css('opacity', '0');
					
					this.container.appendChild(this.navRight);
					
					this.navRight.onload = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							element.style.top =  '-' + element.height + 'px';
							
							var newTop = ((element.maxHeight / 2) - (element.height / 2)) + 'px';
							
							element.style.left = (element.maxWidth - element.width) + 'px';
							
							element.style.display = 'block';
							
							$(element).delay(1500).animate({opacity: '0.5', top: newTop}, 500, 'easeInOutCubic');
						}
					};
					
					this.navRight.onmouseover = function(e) {
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).stop(true, true).animate({opacity: '1'}, 500, 'easeInOutCubic');
						}
					}
					
					this.navRight.onmouseout = function(e) {
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).stop(true, true).animate({opacity: '0.5'}, 500, 'easeInOutCubic');
						}
					}
															  
					this.navRight.onclick = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{	
							
							var gallery = window.ZeroDegreeGallery[element.GalleryId];
							
							if(gallery != null)
							{
								gallery.nextMediaItem();
							}
						}
						
					}
					
					this.navRight.onmousedown = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).css('opacity', '.75');
						}
					}
					
					this.navRight.onmouseup = function(e) {
						
						var element = null;
						
						if(window.event)
						{
							element = window.event.srcElement;
						}
						else
						{
							element = e.target;
						}
						
						if(element != null)
						{
							$(element).css('opacity', '1');
						}
					}
					
					this.navRight.src = "http://zerodegreemedia.info/ZeroDegreeGallery/smallRight.png";
					
					this.previewContainer = document.createElement("DIV");
					
					this.previewContainer.style.position = 'absolute';
					
					this.previewContainer.style.top = (parseInt(this.maxHeight) + 5) + 'px';
					
					this.previewContainer.style.height = '75px';
					
					this.previewContainer.style.left = '0px';
					
					var i = 0;
					
					var currentPreview = null;
					
					while(i < this.mediaCount)
					{
						
						
						currentPreview = this.mediaPreviews[i];
						
						currentPreview.style.left = (i * 85) + 2 + 'px';
						
						currentPreview.OriginalLeft = (i * 85) + 5;
						
						currentPreview.OriginalTop = 0;
						
						currentPreview.style.cursor = 'pointer';
						
						currentPreview.position = 'relative';
						
						
						
						$(currentPreview).mouseover(function() {
													
													
													if(this.MediaId != this.Gallery.currentMediaId)
													{
													var img = this.firstChild;
													
													//alert(this.offsetWidth);
													
													$(this).stop(true, false).animate({borderTopColor: '#999', borderLeftColor: '#999', borderBottomColor: '#999', borderRightColor: '#999'}, 150, 'easeInOutCubic');
													
													$(img).stop(true, false).animate({opacity: '1'}, 100, 'easeInOutCubic');
													
													//alert(img);
													
													//$(this).stop(true, false).animate({height: (this.OriginalHeight + 6) + 'px', width: (this.OriginalWidth + 6) + 'px', top: (this.OriginalTop - 3) + 'px', left: (this.OriginalLeft - 3) + 'px'}, 100, 'easeInOutCubic');
													//$(":first-child", this).animate({opacity: '1', height: (img.OriginalHeight + 6) + 'px', width: (img.OriginalWidth + 6) + 'px'}, 100, 'easeInOutCubic'); 
													}
													}); 
						
						$(currentPreview).mouseleave(function() { 
													 if(this.MediaId != this.Gallery.currentMediaId)
													 {
													 var img = this.firstChild;
												   
													 $(this).stop(true, false).animate({borderTopColor: '#CCC', borderLeftColor: '#CCC', borderBottomColor: '#CCC', borderRightColor: '#CCC'}, 250, 'easeInOutCubic');
													 $(img).stop(true, false).animate({opacity: '.75'}, 250, 'easeInOutCubic');
													 
													 //$(this).stop(true, false).animate({height: (this.OriginalHeight) + 'px', width: (this.OriginalWidth) + 'px', top: (this.OriginalTop) + 'px', left: (this.OriginalLeft) + 'px'}, 100, 'easeInOutCubic');
												   
													 //$(":first-child", this).animate({opacity: '.75', height: (img.OriginalHeight) + 'px', width: (img.OriginalWidth) + 'px'}, 100, 'easeInOutCubic'); 
													 }
												   }); 
						
						$(currentPreview).click(function() {
												
												//alert(this.Gallery.currentMediaId);
												
												this.Gallery.showMediaItem(this.MediaId);
												
												});
						
						//currentPreview.onclick = function() { alert('Preview Clicked'); };
						if(i == 0)
						{
							this.mediaPreviews[i].style.borderColor = '#333';
							
							$(":first-child", currentPreview).css('opacity', '1');
						}
						else
						{
							$(":first-child", currentPreview).css('opacity', '.75');
						}
						
						this.previewContainer.appendChild(currentPreview);
						
						i++;
					}
					
					if(((i * 85)) <= this.maxWidth)
					{
						var previewWidth = (i * 85);
						
						this.previewContainer.style.left = ((this.maxWidth - previewWidth) / 2) + 'px';
						
						this.container.appendChild(this.previewContainer);
						
						
					}
					else
					{
						
						this.container.appendChild(this.previewContainer);
						
						this.scrollBarHandleWidth = 30;
						
						this.scrollBarWrap = document.createElement("DIV");
						
						//this.scrollBarWrap.id = this.container.id + '_Scroll_Bar';
						
						$(this.scrollBarWrap).addClass('scroll-bar-wrap').css({ 'position' : 'absolute', 'top' : (parseInt(this.maxHeight) + 90) + 'px', 'background-color': '#CCCCD5', 'height' : '20px', 'width' : this.maxWidth + 'px', 'margin-left' : 'auto', 'margin-right' : 'auto', 'border-bottom-left-radius' : '10px 10px', 'border-bottom-right-radius' : '10px 10px', 'border-top-left-radius' :'10px 10px', 'border-top-right-radius' : '10px 10px', 'cursor' : 'pointer'});
						
						this.scrollBar = document.createElement("DIV");
						
						$(this.scrollBar).addClass('scroll-bar');
						
						this.scrollBarWrap.appendChild(this.scrollBar);
						
						//var scrollBar = this.scrollBar;
						
					
						
						this.handleSliderStart = function(e, ui) {
							
							//var parent = this;
								
							//alert(parent.className);
							
							$(this).find(".ui-slider-handle").css("background-color", "#7485A2");
							
						};
						
						
						
						this.handleSliderStop = function(e, ui) { 
							$(this).find(".ui-slider-handle").css("background-color", "#8594AD");
						};
						
						this.handleSliderChange = function (e, ui) { 
							var childCount = $(this).parent().prev().children().length;
							
							//alert(e.parentNode);
							
							//var childWidth = $(".scroll-item").width();
							
							var childWidth = 85;
							
							//var containerWidth = $(this.previewContainer).width();
							
							var containerWidth = (childCount * 85);
							
							//alert(containerWidth);
							
							$(this).parent().prev().animate({left: "-" + ((ui.value / 100) * (containerWidth - $(this).parent().width())) + "px"}, 750, 'easeInOutCubic');
							
							//$(this).parent().prev().stop(true, false).css({left: "-" + ((ui.value / 100) * (containerWidth - $(this).parent().width())) + "px"});

						};
						
						this.handleSliderSlide = function(e, ui) {
							var childCount = $(this).parent().prev().children().length;
							
							//var childWidth = $(".scroll-item").width();
							
							var childWidth = 85;
							
							//var containerWidth = $(this.previewContainer).width();
							
							var containerWidth = (childCount * 85);
							
							$(this).parent().prev().stop(true, false).animate({left: "-" + ((ui.value / 100) * (containerWidth - $(this).parent().width())) + "px"}, 750, 'easeInOutCubic');
							
							//$(this).parent().prev().stop(true, false).css({left: "-" + ((ui.value / 100) * (containerWidth - $(this).parent().width())) + "px"});
							
						};
						
						
						$(this.scrollBar).slider({	animate: true, start: this.handleSliderStart, stop: this.handleSliderStop, change: this.handleSliderChange, slide: this.handleSliderSlide });
						
						$(this.scrollBar).css({ 'height' : '20px', 'position': 'relative', 'margin-left': (this.scrollBarHandleWidth / 2) + 2 + 'px', 'padding-right': '0px', 'width' : this.maxWidth - this.scrollBarHandleWidth - 4 + 'px' });
						
						
						$(this.scrollBar).find(".ui-slider-handle").css({ 'top' : '2px', 'margin-left' : '-15px', 'height' : '16px', 'width' : '30px', 'background-color' : '#8594AD', 'position' : 'absolute', 'border-bottom-left-radius' : '8px 8px', 'border-bottom-right-radius' : '8px 8px', 'border-top-left-radius' : '8px 8px', 'border-top-right-radius' : '8px 8px', 'outline' : 'none' });
						
						
						
						
						
						this.container.appendChild(this.scrollBarWrap);
						
						
						this.scrollingPreview = true;
					}
					
					
					
					
					
					
					
				}
				
				this.contentContainer.style.height = this.maxHeight + 'px';
				
				this.extraContainer.style.height = this.maxHeight + 'px';
				
				if(this.mediaItems[0].tagName == 'OBJECT' || this.mediaItems[0].tagName == 'DIV')
				{
					$(this.contentContainer).css('opacity', '0');
					
					this.currentMediaId = 0;
					
					if(this.mediaItems[0].Caption != '')
					{
						this.contentContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.contentContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.contentContainer.offsetHeight - this.mediaItems[0].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[0].Caption + "</div>";
					}
					
					this.contentContainer.appendChild(this.mediaItems[0]);
					
					//this.contentContainer.style.height = '0px';
					
					if(this.mediaCount > 1)
					{
						if(this.scrollingPreview)
						{
							$(this.container).animate({height: (parseInt(this.maxHeight) + 120) + 'px'}, 1000, 'easeInOutCubic');
						}
						else
						{
							$(this.container).animate({height: (parseInt(this.maxHeight) + 100) + 'px'}, 1000, 'easeInOutCubic');
						}
						
						$(this.contentContainer).delay(1000).animate({opacity: '1'}, 1000, 'easeInOutCubic');
						
						$("IMG", this.previewContainer).animate({opacity: '.75'}, 500, 'easeInOutCubic');
						
						$("IMG", this.mediaPreviews[0]).stop(true, false).animate({opacity: '1'}, 500, 'easeInOutCubic');
					}
					else
					{
						$(this.container).animate({height: (parseInt(this.maxHeight) + 10) + 'px'}, 1000, 'easeInOutCubic');
						
						$(this.contentContainer).delay(1000).animate({opacity: '1'}, 1000, 'easeInOutCubic');
					}
						
					
					
					
					//this.mediaItems[0].playVideo();
					
					//$(this.contentContainer).animate({height: this.maxHeight}, 500, 'easeOutBack');
					
					//$(this.contentContainer).show('fade', {}, 500);
					
					//this.contentContainer.style.height = this.maxHeight + 'px';
					
					//$(this.center).show('fade', {}, 1000);
					
					//$(this.contentContainer).animate({height: this.maxHeight}, 1000, 'easeOutBack');
				}
				else if(this.mediaItems[0].tagName == 'IMG')
				{
					$(this.contentContainer).css('opacity', '0');
					
					this.currentMediaId = 0;
					
					if(this.mediaItems[0].Caption != '')
					{
						this.contentContainer.innerHTML += "<div style='position:absolute; margin:0px; width:" + (this.contentContainer.offsetWidth - 20) + "px; padding-left:10px; padding-right:10px; padding-top:5px; padding-bottom:5px; bottom:" + ((this.contentContainer.offsetHeight - this.mediaItems[0].CaptionOffset) / 2 - 1) + "px; font-size: 13px; line-height: 15px; color:#fff; background-color:#333; opacity:.75; filter: alpha(opacity = 75);'>" + this.mediaItems[0].Caption + "</div>";
					}
					
					this.contentContainer.appendChild(this.mediaItems[0]);
					
					
					
					//this.contentContainer.style.height = '0px';
					
					//this.contentContainer.style.display = 'none';
					
					if(this.mediaCount > 1)
					{
						
						if(this.scrollingPreview)
						{
							$(this.container).animate({height: (parseInt(this.maxHeight) + 120) + 'px'}, 500, 'easeInOutCubic');
						}
						else
						{
							$(this.container).animate({height: (parseInt(this.maxHeight) + 100) + 'px'}, 1000, 'easeInOutCubic');
						}
						
						$(this.contentContainer).delay(500).animate({opacity: '1'}, 500, 'easeInOutCubic');
						
						$("IMG", this.previewContainer).animate({opacity: '.75'}, 500, 'easeInOutCubic');
						
						$("IMG", this.mediaPreviews[0]).stop(true, false).animate({opacity: '1'}, 500, 'easeInOutCubic');
					}
					else
					{
						$(this.container).animate({height: (parseInt(this.maxHeight) + 10) + 'px'}, 500, 'easeInOutCubic');
						
						$(this.contentContainer).delay(500).animate({opacity: '1'}, 500, 'easeInOutCubic');
					}
					
					//$(this.contentContainer).show('fade', {}, 500)
				}
				
				this.galleryShown = true;
				/*
				if(this.navLeftLoaded == true && this.navRightLoaded == true && this.galleryShown == true)
				{
					window.ZeroDegreeGallery[this.GalleryId].initializeNavigation();
					//alert("Show Navigation");
				}*/
				
			}
			
			//alert(window.player.getVideoUrl());
		  
			//alert(mediaItem.getVideoUrl());
		}
		
	}
	
}

function initializeZeroDegreeGallery(id)
{
	if(window.ZeroDegreeGallery == null)
	{
		window.ZeroDegreeGallery = new Object();
		window.ZeroDegreeGalleryById = new Object();
	}
	
	var i = 0;
	
	while(window.ZeroDegreeGallery[i] != null)
	{
		i++;
	}
	
	window.ZeroDegreeGallery[i] = new ZeroDegreeGallery(i, id);
	
	/*
	if(window.ZeroDegreeGallery[i] != null)
	{
		window.ZeroDegreeGalleryById[id] = window.ZeroDegreeGallery[i];
	}
	*/
	/*
	 var container = document.getElementById(id);
	 
	 if(container != null)
	 {
	 //container.Gallery = new OakParkGallery(id);
	 container.Gallery = new NewOakParkGallery(id);
	 }
	 */
}

function toggleZeroDegreeGallery(id)
{
	if(window.ZeroDegreeGallery != null && window.ZeroDegreeGallery[0] != null)
	{
		if(window.ZeroDegreeGallery[0].galleryShown)
		{
			window.ZeroDegreeGallery[0].hideGallery();
			document.getElementById('ZeroDegreeGalleryToggle').innerHTML = 'Show Gallery';
		}
		else
		{
			window.ZeroDegreeGallery[0].showGallery();
			document.getElementById('ZeroDegreeGalleryToggle').innerHTML = 'Hide Gallery';
		}
	}
	else
	{
		initializeZeroDegreeGallery(id);
		document.getElementById('ZeroDegreeGalleryToggle').innerHTML = 'Hide Gallery';
	}
}

function initializeOakParkGallery(id)
{/*
	if(window.OakParkGallery == null)
	{
		window.OakParkGallery = new Array();
	}
	
	var i = 0;
	
	while(window.OakParkGallery[i] != null)
	{
		i++;
	}
	
	window.OakParkGallery[i] = new NewOakParkGallery(i, id);*/
	
	/*
	var container = document.getElementById(id);
	
	if(container != null)
	{
		//container.Gallery = new OakParkGallery(id);
		container.Gallery = new NewOakParkGallery(id);
	}
	 */
}


function OakParkGallery(id)
{
	this.getVideoId = function(url)
	{
		var videoSplit = url.split('?');
		if(videoSplit.length == 2)
		{
			var videoArgsSplit = videoSplit[1].split('&');
			var i = 0;
			
			while(i < videoArgsSplit.length)
			{
				if(videoArgsSplit[i].indexOf('v=') == 0)
				{
					var videoIdSplit = videoArgsSplit[i].split('=');
					if(videoIdSplit.length == 2)
					{
						return(videoIdSplit[1]);
					}
				}
				i++;
			}	
			return ('');
		}
		else
		{
			return (videoField.value);
		}
	}
	
	
	
	var container = document.getElementById(id);
	if(container != null)
	{
		this.container = container;
		
		
		//alert(this.container.offsetWidth);
		
		this.mediaContainer = this.container.firstChild;
		
		this.contentContainer = this.container.firstChild.nextSibling;
		
		this.navigationContainer = this.container.firstChild.nextSibling;
		
		if(this.mediaContainer != null && this.contentContainer != null && this.navigationContainer != null)
		{
			this.mediaContainer.style.display = 'none';
			//alert(this.mediaContainer.firstChild.getVideoBytesLoaded());
			var mediaItem = this.mediaContainer.firstChild;
			
			this.mediaCount = 0;
			
			this.maxHeight = 0;
			
			var currentHeight = 0;
			
			this.mediaItems = new Array();
			
			while(mediaItem != null)
			{
				if (window.BrowserDetect.browser == "Explorer" && mediaItem.tagName == "IMG")
				{
					var tempImage = new Image() 
					tempImage.src = mediaItem.src;
					currentHeight = tempImage.height;
				}
				else
				{
					currentHeight = mediaItem.height;
				}
				
				mediaItem.style.zIndex = "50";
				
				//alert(mediaItem.tagName);
				
				if (window.BrowserDetect.browser == "Explorer" && mediaItem.tagName == "OBJECT")
				{
					var tempDiv = document.createElement("div");
					
					tempDiv.style.zIndex = "50";
					
					tempDiv.appendChild(mediaItem);
					
					this.mediaItems[this.mediaCount] = tempDiv;
				}
				else
				{
					
					
					this.mediaItems[this.mediaCount] = mediaItem;
				}
				
				/*
				 if(mediaItem.tagName == "OBJECT")
				 {
				 alert(this.mediaItems[this.mediaCount].getVideoBytesLoaded());
				 this.mediaItems[this.mediaCount].addEventListener("onStateChange", "onytplayerStateChange");
				 }
				 */
				
				if(currentHeight > this.maxHeight)
				{
					this.maxHeight = currentHeight;
				}
				
				this.mediaCount++;
				
				
				
				mediaItem = mediaItem.nextSibling;
			}
			
			if(this.mediaCount > 0)
			{
				this.contentContainer.style.height = this.maxHeight + 'px';
				
				this.table = document.createElement("table");
				
				this.table.style.position = "relative";
				
				this.table.style.width = (3 * this.container.offsetWidth) + 'px';
				
				this.table.style.left = (this.container.offsetWidth * (-1)) + 'px';
				
				this.tableBody = document.createElement("tbody");
				
				// creating all cells
				
				// creates a table row
				this.row = document.createElement("tr");
				
				
				
				//	for (var i = 0; i < 3; i++) {
				// Create a <td> element and a text node, make the text
				// node the contents of the <td>, and put the <td> at
				// the end of the table row
				this.left = document.createElement("td");
				this.center = document.createElement("td");
				this.right = document.createElement("td");
				this.extra = document.createElement("td");
				
				
				this.left.style.height = this.maxHeight + 'px';
				this.center.style.height = this.maxHeight + 'px';
				this.right.style.height = this.maxHeight + 'px';
				this.extra.style.height = this.maxHeight + 'px';
				
				this.left.style.width = this.container.offsetWidth + 'px';
				this.center.style.width = this.container.offsetWidth + 'px';
				this.right.style.width = this.container.offsetWidth + 'px';
				this.extra.style.width = this.container.offsetWidth + 'px';
				
				
				this.centerContent = document.createElement("div");
				
				this.centerContent.style.position = "relative";
				
				//var cellText = document.createTextNode("cell is row 0, column "+i);
				
				//alert(this.mediaItems[0]);
				//this.center.appendChild(this.centerContent);
				
				//this.centerContent.appendChild(this.mediaItems[0]);
				
				this.center.appendChild(this.mediaItems[0]);
				//this.right.appendChild(this.mediaItems[0]);
				
				this.contentLeft = new Image();
				this.contentLeft.src = "http://oakpark.zerodegreeproduction.com/smallLeft.png";
				
				//alert(this.contentLeft.complete);
				
				if (window.BrowserDetect.browser == "Firefox")
				{
					this.contentLeft.style.position = "absolute";
					//this.contentLeft.style.float = "left";
				}
				else
				{
					this.contentLeft.style.position = "absolute";
				}
				//this.contentLeft.style.float = "left";
				this.contentLeft.style.top = (this.maxHeight / 2 - this.contentLeft.height / 2) + 'px';
				//this.contentLeft.style.left = '0px';
				
				this.contentLeft.style.left = this.container.offsetWidth + 'px';
				this.contentLeft.style.zIndex = "51";
				
				this.contentRight = new Image();
				this.contentRight.src = "http://oakpark.zerodegreeproduction.com/smallRight.png";
				
				if (window.BrowserDetect.browser == "Firefox")
				{
					this.contentRight.style.position = "absolute";
					//this.contentRight.style.float= "right";
				}
				else
				{
					this.contentRight.style.position = "absolute";
				}
				
				//this.contentRight.style.float = "right";
				this.contentRight.style.top = (this.maxHeight / 2 - this.contentLeft.height / 2) + 'px';
				//this.contentRight.style.left = ((this.container.offsetWidth) - this.contentRight.width) + 'px';
				this.contentRight.style.left = ((this.container.offsetWidth * 2) - this.contentRight.width) + 'px';
				this.contentRight.style.zIndex = "51";
				
				//this.contentRight.onclick = function () { alert("Move Right"); };
				
				//this.contentLeft.onclick = function () { alert("Move Left"); };
				
				//this.centerContent.appendChild(this.contentLeft);
				
				//this.centerContent.appendChild(this.contentRight);
				
				this.center.appendChild(this.contentLeft);
				
				this.center.appendChild(this.contentRight);
				
				//this.center.appendChild(this.mediaItems[0]);
				
				
				
				//cell.innerHTML = this.mediaItems[0].innerHTML;
				
				
				
				
				this.row.appendChild(this.left);
				this.row.appendChild(this.center);
				this.row.appendChild(this.right);
				
				this.center.style.display = 'none';
				
				// add the row to the end of the table body
				this.tableBody.appendChild(this.row);
				
				
				// put the <tbody> in the <table>
				this.table.appendChild(this.tableBody);
				// appends <table> into <body>
				
				this.contentContainer.style.height = '0px';
				
				this.contentContainer.appendChild(this.table);
				
				$(this.contentRight).click(function(event) {
										   $(this).animate({left: '-=100px'}, 500, 'easeInOutCubic').animate({left: '+=100px'}, 500, 'easeInOutCubic');
										   });
				
				$(this.center).click(function(event) {
									 $(this.parentElement.parentElement.parentElement).animate({left: '-=300px'}, 500, 'easeInOutCubic').animate({left: '+=300px'}, 500, 'easeInOutCubic');
									 });
				
				$(this.center).show('fade', {}, 1000);
				
				$(this.contentContainer).animate({height: this.maxHeight}, 1000, 'easeInOutCubic');
				
				//tbl.setAttribute("border", "2");
				
				
				//this.contentContainer.innerHTML = this.mediaItems[0].innerHTML;
			}
			
			//alert(this.mediaItems.length);
			
			//
			
			//var videoURL = this.mediaContainer.firstChild.getVideoUrl()
			
			//alert(this.getVideoId(videoURL));
			
			//player = this.mediaContainer.firstChild
			
			//alert(player.getVideoUrl());
			
			//alert(player.playVideo());
			
			//alert(this.mediaContainer.firstChild.tagName);
			
			//alert(this.mediaContainer.firstChild.height);
			
			//alert(this.mediaContainer.firstChild.nextSibling.tagName);
			
			//alert(this.mediaContainer.firstChild.nextSibling.height);
		}
	}
}

window.BrowserDetect = {
init: function () {
	this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	this.version = this.searchVersion(navigator.userAgent)
	|| this.searchVersion(navigator.appVersion)
	|| "an unknown version";
	this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
	for (var i=0;i<data.length;i++)	{
		var dataString = data[i].string;
		var dataProp = data[i].prop;
		this.versionSearchString = data[i].versionSearch || data[i].identity;
		if (dataString) {
			if (dataString.indexOf(data[i].subString) != -1)
				return data[i].identity;
		}
		else if (dataProp)
			return data[i].identity;
	}
},
searchVersion: function (dataString) {
	var index = dataString.indexOf(this.versionSearchString);
	if (index == -1) return;
	return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
			  {
			  string: navigator.userAgent,
			  subString: "Chrome",
			  identity: "Chrome"
			  },
			  { 	string: navigator.userAgent,
			  subString: "OmniWeb",
			  versionSearch: "OmniWeb/",
			  identity: "OmniWeb"
			  },
			  {
			  string: navigator.vendor,
			  subString: "Apple",
			  identity: "Safari",
			  versionSearch: "Version"
			  },
			  {
			  prop: window.opera,
			  identity: "Opera"
			  },
			  {
			  string: navigator.vendor,
			  subString: "iCab",
			  identity: "iCab"
			  },
			  {
			  string: navigator.vendor,
			  subString: "KDE",
			  identity: "Konqueror"
			  },
			  {
			  string: navigator.userAgent,
			  subString: "Firefox",
			  identity: "Firefox"
			  },
			  {
			  string: navigator.vendor,
			  subString: "Camino",
			  identity: "Camino"
			  },
			  {		// for newer Netscapes (6+)
			  string: navigator.userAgent,
			  subString: "Netscape",
			  identity: "Netscape"
			  },
			  {
			  string: navigator.userAgent,
			  subString: "MSIE",
			  identity: "Explorer",
			  versionSearch: "MSIE"
			  },
			  {
			  string: navigator.userAgent,
			  subString: "Gecko",
			  identity: "Mozilla",
			  versionSearch: "rv"
			  },
			  { 		// for older Netscapes (4-)
			  string: navigator.userAgent,
			  subString: "Mozilla",
			  identity: "Netscape",
			  versionSearch: "Mozilla"
			  }
			  ],
	dataOS : [
			  {
			  string: navigator.platform,
			  subString: "Win",
			  identity: "Windows"
			  },
			  {
			  string: navigator.platform,
			  subString: "Mac",
			  identity: "Mac"
			  },
			  {
			  string: navigator.userAgent,
			  subString: "iPhone",
			  identity: "iPhone/iPod"
			  },
			  {
			  string: navigator.platform,
			  subString: "Linux",
			  identity: "Linux"
			  }
			  ]
	
};

window.BrowserDetect.init();

//alert(window.BrowserDetect.browser + window.BrowserDetect.version + window.BrowserDetect.OS);

function fade(eid,level)
{
	var element = document.getElementById(eid);
	if(element == null)
	{
		return;
	}
	
	if(element.FadeState == null)
	{
		//alert(element.style.display);
		if(element.style.display == "block")
		{
			element.FadeState = 2;
		}
		else
		{
			element.FadeState = -2;
		}
	}
	
	if(element.FadeState == -2)
	{
		element.style.display = "block";
	}
    
	if(element.FadeState == 1 || element.FadeState == -1)
	{
		element.FadeState = element.FadeState == 1 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	}
	else
	{
		element.FadeState = element.FadeState == 2 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade;
		setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "','" + level + "')", 1);
	}
}

function animateFade(lastTick, eid, level)
{  
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;
	
	var element = document.getElementById(eid);
	
	if(element.FadeTimeLeft <= elapsedTicks)
	{
		element.style.opacity = element.FadeState == 1 ? level : '0';
		element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? level*100 : '0') + ')';
		//element.FadeState = element.FadeState == 1 ? 2 : -2;
		if(element.FadeState == 1)
		{
			element.FadeState = 2;
			element.style.display = "block";
		}
		else
		{
			element.FadeState = -2;
			element.style.display = "none";
			element.style.opacity = 0;
			element.style.filter = 'alpha(opacity = 0)';
		}
		return;
	}
	
	element.FadeTimeLeft -= elapsedTicks;
	var newOpVal = (element.FadeTimeLeft/TimeToFade) * level;
	if(element.FadeState == 1)
		newOpVal = level - newOpVal;
	
	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
	
	setTimeout("animateFade(" + curTick + ",'" + eid + "','" + level + "')", 1);
}

function windowSize() {
	//var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	//document.getElementById('messageBackground').style.height = document.getElementById('pageContainer').offsetHeight + 'px';
	
	if(document.getElementsByTagName("body")[0].offsetHeight > windowHeight)
	{
	
		document.getElementById('messageBackground').style.height = document.getElementsByTagName("body")[0].offsetHeight + 'px';
	}
	else
	{
		document.getElementById('messageBackground').style.height = windowHeight + 'px';
	}
	
	window.onresize = windowSize;

	/*
	var menu1Div = document.getElementById('menu1');
	if(menu1Div != null)
	{
		menu1Div.style.height = windowHeight - 50;
	}
	
	var menu2Div = document.getElementById('menu2');
	if(menu2Div != null)
	{
		menu2Div.style.height = windowHeight - 50;
	}
	
	var menu3Div = document.getElementById('menu3');
	if(menu3Div != null)
	{
		menu3Div.style.height = windowHeight - 50;
	}
	
	var mainContent = document.getElementById('mainContent');
	if(mainContent != null)
	{
		mainContent.style.height = windowHeight - 50;
		if(menu3Div != null && menu3Div.FadeState > 0)
		{
			mainContent.style.left = '588px';
			if(windowWidth > 1000)
			{
				mainContent.style.width = windowWidth - 588;
			}
			else
			{
				mainContent.style.width = 1000 - 588;
			}
		}
		else
		{
			mainContent.style.left = '392px';
			mainContent.style.width = windowWidth - 392;
		}
	}
	
	window.messageBoxContentHeight = windowHeight * .8;
	
	var messageBoxContent = document.getElementById('messageBoxContent');
	if(messageBoxContent != null)
	{
		messageBoxContent.style.height = window.messageBoxContentHeight + 'px';
	}
	
	*/
	//document.getElementById('debug').innerHTML = windowWidth + ' ' + windowHeight;
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );
}

function start()
{
	moveMessage();
	
	window.onscroll = moveMessage;
	
	windowSize();
	
	//alert(document.getElementById('pageContainer').offsetHeight);
	
}

function toggleListMap()
{
	if(window.ListMapDisplayed == null)
	{
		window.ListMapDisplayed = false;
	}
	
	if(window.ListMapDisplayed === false)
	{
		window.ListMapDisplayed = true;
		$('#ListMapContainer').animate({height: ($('#ListMapBox')[0].offsetHeight + 10) + 'px', opacity: '1'}, 1000, 'easeInOutCubic');
		document.getElementById('ListMapToggle').innerHTML = 'Hide Map';
		//$('#ListMapContainer').animate({height: '100px', opacity: '1'}, 600, 'easeOutBack');

	}
	else
	{
		window.ListMapDisplayed = false;
		$('#ListMapContainer').animate({height: '0px', opacity: '0'}, 1000, 'easeInOutCubic');
		document.getElementById('ListMapToggle').innerHTML = 'Show Map';
	}
}

function toggleMessageWindow()
{
	windowSize();
	
	if(window.MessageWindowDisplayed === false)
	{
		window.MessageWindowDisplayed = true;
		fade('messageBackground', '.5');
		
		setTimeout("fade('messageContent', 1)", 250);
	}
	else
	{
		window.MessageWindowDisplayed = false;
		
		fade('messageContent', 1);
		
		setTimeout("fade('messageBackground', '.5')", 250);
	}
}

function showMessageWindow()
{
	windowSize();
	
	if(window.MessageWindowDisplayed === false)
	{
		window.MessageWindowDisplayed = true;
		fade('messageBackground', '.5');
		
		setTimeout("fade('messageContent', 1)", 250);
	}
}

function displayCommentMessage(name, section, rating, star1, star2)
{
	windowSize();
	
	name = unescape(name);
	
	//name = name.replace('+', ' ');
	
	//name = name.replace(/'+'/g,' ')
	
	if(window.MessageWindowDisplayed === false)
	{
		window.MessageWindowDisplayed = true;
		fade('messageBackground', '.5');
	
		var ratingText = '';
		
		if(rating == true)
		{
			loadStars(star1, star2);
			
			ratingText = "<tr><td class='left'>Rating:</td><td class='right'><img id='1' src='" + star1 + "' onmouseover='highlight(this.id);' onclick='setStar(this.id);' onmouseout='losehighlight(this.id);' /><img id='2' src='" + star1 + "' onmouseover='highlight(this.id);' onclick='setStar(this.id);' onmouseout='losehighlight(this.id);' /><img id='3' src='" + star1 + "' onmouseover='highlight(this.id);' onclick='setStar(this.id);' onmouseout='losehighlight(this.id);' /><img id='4' src='" + star1 + "' onmouseover='highlight(this.id);' onclick='setStar(this.id);' onmouseout='losehighlight(this.id);' /><img id='5' src='" + star1 + "' onmouseover='highlight(this.id);' onclick='setStar(this.id);' onmouseout='losehighlight(this.id);' /><input type='hidden' value='' id='CommentRating' /></td></tr>";
		}
		
		if(window.commentEmail == null)
		{
			window.commentEmail = '';
		}
		
		if(window.commentName == null)
		{
			window.commentName = '';
		}
		
		if(window.commentCity == null)
		{
			window.commentCity = '';
		}
		
		if(window.commentLimit == null)
		{
			window.commentLimit = '500';
		}
		
		
		if(parseInt(window.commentLimit) > 500)
		{
			window.facebookFieldText = "<img src='/FacebookVerified.jpg' style='margin-bottom:-2px; height:14px; width:14px;' /> Facebook Verified";
		}
		else
		{
			window.facebookFieldText = "";
		}

		
		//var phone = '';
		/*
		FB.getLoginStatus(function(response) {
						  if (response.session) {
						  // logged in and connected user, someone you know
						  FB.api('/me', function(response) {
								 
								// alert(response.name);
								 
								 //window.commentName = response.name;
								 
								 //window.commentEmail = response.email;
								 
								 //window.commentCity = response.locale;
								 
								 });
								 
						  } else {
						  // no user session available, someone you dont know
						  }
						  });
		
		*/
		//alert(window.pageYOffset);
		
	
		//document.getElementById('messageContent').style.top = (window.pageYOffset + 100) + 'px';
		
		//document.getElementById('messageContent').innerHTML = "<div class='" + section + "CommentBox'><p class='Title'>Add " + name + " Comment</p><a onclick='closeMessageWindow();'>Close</a><br/><br/></div>";
	
		document.getElementById('messageContent').innerHTML = "<div id='PostCommentBox' class='" + section + "CommentBox'><p class='Title'>Add Comment On: " + name + "</p>"
			+ "<form method='POST' onsubmit='submitComment(); return false;'><input type='hidden' id='ValidComment' value='valid' /><input type='hidden' name='characters' id='MaxValidComment' value=\"" + window.commentLimit + "\" /><span id='CommentErrorText'></span><table>"
			+ "<tr><td class='left'><span id='CommentEmailLabel'><b>Email:</b></span></td><td class='right'><input class='text' type='text' id='CommentEmail' value=\"" + window.commentEmail + "\" /></td></tr>"
			//			+ "<tr><td class='left'><span id='CommentNameLabel'><b>Name:</b></span> <span id='CommentNameFacebookLabel' class='FacebookStyle' style='font-size:13px;'>" + window.facebookFieldText + "</span></td><td class='right'><input name='name' class='text' type='text' id='CommentName' value=\"" + window.commentName + "\" onkeydown=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onkeyup=\"checkName(this.form.name,'CommentNameFacebookLabel');\" /></td></tr>"
		+ "<tr><td class='left'><span id='CommentNameLabel'><b>Name:</b></span> <span id='CommentNameFacebookLabel' class='FacebookStyle' style='font-size:13px;'>" + window.facebookFieldText + "</span></td><td class='right'><input name='name' class='text' type='text' id='CommentName' value=\"" + window.commentName + "\" onkeydown=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onkeyup=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onmousedown=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onmouseup=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onmouseout=\"checkName(this.form.name,'CommentNameFacebookLabel');\" onblur=\"checkName(this.form.name,'CommentNameFacebookLabel');\" /></td></tr>"

			+ "<tr><td class='left'>City:</td><td class='right'><input class='text' type='text' id='CommentCity' value=\"" + window.commentCity + "\" /></td></tr>"
			+ "<tr><td class='left'>Phone:</td><td class='right'><input class='text' type='text' id='CommentPhone' /></td></tr>"
			+ ratingText
			+ "<tr><td class='left'><span id='CommentContentLabel'><b>Comment:</b></span><p class='fineprint'>(Maximum <span id='CommentMax'>" + window.commentLimit + "</span> Characters)<br/>You have <span id='CommentCountdown'>" + window.commentLimit + "</span> characters left.<br/><br/>Login with Facebook and use your Facebook name to get 2000 characters.</p></td><td class='right'><textarea name='comment' id='CommentContent' rows='10' wrap='soft' onkeydown=\"limitCommentText(this.form.comment,'CommentCountdown');\" onkeyup=\"limitCommentText(this.form.comment,'CommentCountdown');\" onmousedown=\"limitCommentText(this.form.comment,'CommentCountdown');\" onmouseup=\"limitCommentText(this.form.comment,'CommentCountdown');\" onblur=\"limitCommentText(this.form.comment,'CommentCountdown');\"></textarea></td></tr>"
			+ "</table><input class='cancel' type='button' onclick='closeMessageWindow();' value='Cancel' /> <input class='submit' type='submit' value='Post Comment' /></form>"
            + "<b>Bold</b> Text Denotes Required Fields<br/><a target='blank' href='http://www.oakpark.com/Home/Comment_Policy' style='font-size:12px; margin-top:5px;'>Comment Policy</a><br/></div>";

		
		setTimeout("fade('messageContent', 1)", 250);
	}
}

function submitComment()
{
	//alert(window.location);
	
	var post = '';
	
	var Email = document.getElementById('CommentEmail');
	
	var Name = document.getElementById('CommentName');
	
	var City = document.getElementById('CommentCity');
	
	var Phone = document.getElementById('CommentPhone');
	
	var Comment = document.getElementById('CommentContent');
	
	var Valid = document.getElementById('ValidComment');
	
	var Rating = document.getElementById('CommentRating');
	
	var CommentMax = document.getElementById('MaxValidComment');
	
	if(Email != null && Name != null && City != null && Phone != null && Comment != null && Valid != null && Valid.value == 'valid' && CommentMax != null && parseInt(CommentMax.value) >= Comment.value.length)
	{
		if(Email.value != '' && Name.value != '' && Comment.value != '')
		{
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = '';
			}
			
			var EmailLabel = document.getElementById('CommentEmailLabel');
			
			if(EmailLabel != null)
			{
				EmailLabel.style.color = '#333';
			}
			
			var NameLabel = document.getElementById('CommentNameLabel');
			
			if(NameLabel != null)
			{
				NameLabel.style.color = '#333';
			}
			
			var CommentLabel = document.getElementById('CommentContentLabel');
			
			if(CommentLabel != null)
			{
				CommentLabel.style.color = '#333';
			}
			
			post += 'PostBackType=Comment&Email=' + escape(Email.value) + '&Name=' + escape(Name.value) + '&City=' + escape(City.value) + '&Phone=' + escape(Phone.value) + '&Comment=' + escape(Comment.value) + '&Valid=' + escape(Valid.value);
			
			if(Rating != null)
			{
				post += '&Rating=' + escape(Rating.value);
			}
			
			//alert(post);
			
			CommentBox = document.getElementById('PostCommentBox');
			
			if(CommentBox != null)
			{
				CommentBox.innerHTML = "<p class='Title'>Posting Comment</p><p id='CommentLoader'></p>Please wait while your comment is posted.<br/><br/><input class='cancel' type='button' value='Close Window' onclick='closeMessageWindow();' /><br/>";
				
				xmlHttp = GetXmlHttpObject();
				
				if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request");
					return;
				}
				
				//xmlHttp.onreadystatechange = stateChangedSpin('CommentLoader');
				
				xmlHttp.onreadystatechange = function(){ stateChangedSpin('CommentLoader'); };
				
				xmlHttp.open("POST",window.location,true);
				
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				
				xmlHttp.send(post);
			}
			
			
		}
		else
		{
			var EmailLabel = document.getElementById('CommentEmailLabel');
			
			if(EmailLabel != null)
			{
				if(Email.value == '')
				{
					EmailLabel.style.color = '#F00';
				}
				else
				{
					EmailLabel.style.color = '#333';
				}
			}
			
			var NameLabel = document.getElementById('CommentNameLabel');
			
			if(NameLabel != null)
			{
				if(Name.value == '')
				{
					NameLabel.style.color = '#F00';
				}
				else
				{
					NameLabel.style.color = '#333';
				}
			}
			
			var CommentLabel = document.getElementById('CommentContentLabel');
			
			if(CommentLabel != null)
			{
				if(Comment.value == '')
				{
					CommentLabel.style.color = '#F00';
				}
				else
				{
					CommentLabel.style.color = '#333';
				}
			}
			
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = 'Please Fill Out ALL <b>Required</b> Fields!';
			}
		}
		
	}
	else if(Comment != null && CommentMax != null && parseInt(CommentMax.value) < Comment.value.length)
	{
		alert("Your comment is more than the maximum charaters allowed. Please shorten your comment or our servers will truncate it to the maximum length.");
	}
	else if(Valid != null && Valid.value != 'valid')
	{
		closeMessageWindow();
	}
	else
	{
		alert("An Error Has Occured. Please Refresh This Page and Try Again. We Apologize For Any Inconvenience.");
	}
	
	return (false);
}


function displayEmailMessage(name, section)
{
	windowSize();
	
	name = unescape(name);
	
	//name = name.replace('+', ' ');
	
	//name = name.replace(/'+'/g,' ')
	
	if(window.MessageWindowDisplayed === false)
	{
		window.MessageWindowDisplayed = true;
		fade('messageBackground', '.5');
		
		if(window.commentEmail == null)
		{
			window.commentEmail = '';
		}
		
		if(window.commentName == null)
		{
			window.commentName = '';
		}
		
		if(window.commentCity == null)
		{
			window.commentCity = '';
		}
		
		
		
		if(window.location.hostname.indexOf("riverforest") != -1)
		{
			var domain = "RiverForest.com";
		}
		else
		{
			var domain = "OakPark.com";
		}
		
		
		
		//var phone = '';
		/*
		 FB.getLoginStatus(function(response) {
		 if (response.session) {
		 // logged in and connected user, someone you know
		 FB.api('/me', function(response) {
		 
		 // alert(response.name);
		 
		 //window.commentName = response.name;
		 
		 //window.commentEmail = response.email;
		 
		 //window.commentCity = response.locale;
		 
		 });
		 
		 } else {
		 // no user session available, someone you dont know
		 }
		 });
		 
		 */
		//alert(window.pageYOffset);
		
		
		//document.getElementById('messageContent').style.top = (window.pageYOffset + 100) + 'px';
		
		//document.getElementById('messageContent').innerHTML = "<div class='" + section + "CommentBox'><p class='Title'>Add " + name + " Comment</p><a onclick='closeMessageWindow();'>Close</a><br/><br/></div>";
		
		document.getElementById('messageContent').innerHTML = "<div id='PostCommentBox' class='" + section + "CommentBox'><p class='Title'>Email: " + name + "</p>"
		+ "<form method='POST' onsubmit='submitEmail(); return false;'><input type='hidden' id='ValidComment' value='valid' /><span id='CommentErrorText'></span><table>"
		+ "<tr><td class='left'><span id='FromEmailLabel'><b>From Email:</b></span></td><td class='right'><input class='text' type='text' id='FromEmail' value=\"" + window.commentEmail + "\" /></td></tr>"
		+ "<tr><td class='left'><span id='FromNameLabel'><b>From Name:</b></span></td><td class='right'><input class='text' type='text' id='FromName' value=\"" + window.commentName + "\" /></td></tr>"
		+ "<tr><td class='left'><span id='ToEmailLabel'><b>To Email:</b></span></td><td class='right'><input class='text' type='text' id='ToEmail' value='' /></td></tr>"
		+ "<tr><td class='left'><span id='ToNameLabel'><b>To Name:</b></span></td><td class='right'><input class='text' type='text' id='ToName' value='' /></td></tr>"
		+ "<tr><td class='left'><span id='MessageContentLabel'><b>Message:</b></span><p class='fineprint'>(Maximum 500 Characters)<br/>You Have <span id='MessageCountdown'>500</span> characters left.</p></td><td class='right'><textarea name='message' id='MessageContent' rows='10' wrap='soft' onkeydown=\"limitText(this.form.message,'MessageCountdown',500);\" onkeyup=\"limitText(this.form.comment,'CommentCountdown',500);\">Check out this page on " + domain + "!</textarea></td></tr>"
		+ "</table><input class='cancel' type='button' onclick='closeMessageWindow();' value='Cancel' /> <input class='submit' type='submit' value='Send Email' /></form>"
		+ "<b>Bold</b> Text Denotes Required Fields<br/></div>";
		
		
		setTimeout("fade('messageContent', 1)", 250);
	}
}



function submitEmail()
{
	//alert(window.location);
	
	var post = '';
	
	var FromEmail = document.getElementById('FromEmail');
	
	var FromName = document.getElementById('FromName');
	
	var ToEmail = document.getElementById('ToEmail');
	
	var ToName = document.getElementById('ToName');
	
	var Message = document.getElementById('MessageContent');
	
	var Valid = document.getElementById('ValidComment');
	
	if(FromEmail != null && FromName != null && ToEmail != null && ToName != null && Message != null && Valid != null && Valid.value == 'valid')
	{
		if(FromEmail.value != '' && FromName.value != '' && ToEmail.value != '' && ToName.value != '' && Comment.value != '')
		{
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = '';
			}
			
			var FromEmailLabel = document.getElementById('FromEmailLabel');
			
			if(FromEmailLabel != null)
			{
				FromEmailLabel.style.color = '#333';
			}
			
			var FromNameLabel = document.getElementById('FromNameLabel');
			
			if(FromNameLabel != null)
			{
				FromNameLabel.style.color = '#333';
			}
			
			var ToEmailLabel = document.getElementById('ToEmailLabel');
			
			if(ToEmailLabel != null)
			{
				ToEmailLabel.style.color = '#333';
			}
			
			var ToNameLabel = document.getElementById('ToNameLabel');
			
			if(ToNameLabel != null)
			{
				ToNameLabel.style.color = '#333';
			}
			
			var MessageLabel = document.getElementById('MessageContentLabel');
			
			if(MessageLabel != null)
			{
				MessageLabel.style.color = '#333';
			}
			
			post += 'PostBackType=Email&FromEmail=' + escape(FromEmail.value) + '&FromName=' + escape(FromName.value) + '&ToEmail=' + escape(ToEmail.value) + '&ToName=' + escape(ToName.value) + '&Message=' + escape(Message.value) + '&Valid=' + escape(Valid.value);
			
			//alert(post);
			
			CommentBox = document.getElementById('PostCommentBox');
			
			if(CommentBox != null)
			{
				CommentBox.innerHTML = "<p class='Title'>Sending Email</p><p id='CommentLoader'></p>Please wait while your Email is sent.<br/><br/><input class='cancel' type='button' value='Close Window' onclick='closeMessageWindow();' /><br/>";
				
				xmlHttp = GetXmlHttpObject();
				
				if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request");
					return;
				}
				
				//xmlHttp.onreadystatechange = stateChangedSpin('CommentLoader');
				
				xmlHttp.onreadystatechange = function(){ stateChangedSpin('CommentLoader'); };
				
				xmlHttp.open("POST",window.location,true);
				
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				
				xmlHttp.send(post);
			}
			
			
		}
		else
		{
			var FromEmailLabel = document.getElementById('FromEmailLabel');
			
			if(FromEmailLabel != null)
			{
				if(FromEmail.value == '')
				{
					FromEmailLabel.style.color = '#F00';
				}
				else
				{
					FromEmailLabel.style.color = '#333';
				}
			}
			
			var FromNameLabel = document.getElementById('FromNameLabel');
			
			if(FromNameLabel != null)
			{
				if(FromName.value == '')
				{
					FromNameLabel.style.color = '#F00';
				}
				else
				{
					FromNameLabel.style.color = '#333';
				}
			}
			
			var ToEmailLabel = document.getElementById('ToEmailLabel');
			
			if(ToEmailLabel != null)
			{
				if(ToEmail.value == '')
				{
					ToEmailLabel.style.color = '#F00';
				}
				else
				{
					ToEmailLabel.style.color = '#333';
				}
			}
			
			var ToNameLabel = document.getElementById('ToNameLabel');
			
			if(ToNameLabel != null)
			{
				if(ToName.value == '')
				{
					ToNameLabel.style.color = '#F00';
				}
				else
				{
					ToNameLabel.style.color = '#333';
				}
			}
			
			var MessageLabel = document.getElementById('MessageContentLabel');
			
			if(MessageLabel != null)
			{
				if(Message.value == '')
				{
					MessageLabel.style.color = '#F00';
				}
				else
				{
					MessageLabel.style.color = '#333';
				}
			}
			
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = 'Please Fill Out ALL <b>Required</b> Fields!';
			}
		}
		
	}
	else if(Valid != null && Valid.value != 'valid')
	{
		closeMessageWindow();
	}
	else
	{
		alert("An Error Has Occured. Please Refresh This Page and Try Again. We Apologize For Any Inconvenience.");
	}
	
	return (false);
}

function displayLetterMessage(section)
{
	windowSize();
	
	name = unescape(name);
	
	//name = name.replace('+', ' ');
	
	//name = name.replace(/'+'/g,' ')
	
	if(window.MessageWindowDisplayed === false)
	{
		window.MessageWindowDisplayed = true;
		fade('messageBackground', '.5');
		
		if(window.commentEmail == null)
		{
			window.commentEmail = '';
		}
		
		if(window.commentName == null)
		{
			window.commentName = '';
		}
		
		if(window.commentCity == null)
		{
			window.commentCity = '';
		}
		
		
		
		if(window.location.hostname.indexOf("riverforest") != -1)
		{
			var domain = "RiverForest.com";
		}
		else
		{
			var domain = "OakPark.com";
		}
		
		
		
		//var phone = '';
		/*
		 FB.getLoginStatus(function(response) {
		 if (response.session) {
		 // logged in and connected user, someone you know
		 FB.api('/me', function(response) {
		 
		 // alert(response.name);
		 
		 //window.commentName = response.name;
		 
		 //window.commentEmail = response.email;
		 
		 //window.commentCity = response.locale;
		 
		 });
		 
		 } else {
		 // no user session available, someone you dont know
		 }
		 });
		 
		 */
		//alert(window.pageYOffset);
		
		
		//document.getElementById('messageContent').style.top = (window.pageYOffset + 100) + 'px';
		
		//document.getElementById('messageContent').innerHTML = "<div class='" + section + "CommentBox'><p class='Title'>Add " + name + " Comment</p><a onclick='closeMessageWindow();'>Close</a><br/><br/></div>";
		
		document.getElementById('messageContent').innerHTML = "<div id='PostCommentBox' class='" + section + "CommentBox'><p class='Title'>Submit Letter To The Editor</p>"
		+ "<form method='POST' onsubmit='submitLetter(); return false;'><input type='hidden' id='ValidComment' value='valid' /><span id='CommentErrorText'></span><table>"
		+ "<tr><td class='letterLeft'><span id='NameLabel'><b>Name:</b></span></td><td class='letterRight'><input class='text' type='text' id='Name' value=\"" + window.commentName + "\" /></td></tr>"
		+ "<tr><td class='letterLeft'><span id='EmailLabel'><b>Email:</b></span></td><td class='letterRight'><input class='text' type='text' id='Email' value=\"" + window.commentEmail + "\" /></td></tr>"
		+ "<tr><td class='letterLeft'><span id='PhoneLabel'><b>Phone:</b></span></td><td class='letterRight'><input class='text' type='text' id='Phone' value='' /></td></tr>"
		+ "<tr><td class='letterLeft'><span id='CityLabel'><b>City:</b></span></td><td class='letterRight'><input class='text' type='text' id='City' value=\"" + window.commentCity + "\"/></td></tr>"
		+ "<tr><td class='letterLeft'><span id='LetterContentLabel'><b>Letter:</b></span></td><td class='letterRight'><textarea name='message' id='LetterContent' rows='20' wrap='soft'></textarea></td></tr>"
		+ "</table><input class='cancel' type='button' onclick='closeMessageWindow();' value='Cancel' /> <input class='submit' type='submit' value='Submit Letter' /></form>"
		+ "<b>Bold</b> Text Denotes Required Fields<br/></div>";
		
		
		setTimeout("fade('messageContent', 1)", 250);
	}
}

function submitLetter()
{
	//alert(window.location);
	
	var post = '';
	
	var Email = document.getElementById('Email');
	
	var Name = document.getElementById('Name');
	
	var Phone = document.getElementById('Phone');
	
	var City = document.getElementById('City');
	
	var Letter = document.getElementById('LetterContent');
	
	var Valid = document.getElementById('ValidComment');
	
	if(Email != null && Name != null && Phone != null && City != null && Letter != null && Valid != null && Valid.value == 'valid')
	{
		if(Email.value != '' && Name.value != '' && Phone.value != '' && City.value != '' && Letter.value != '')
		{
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = '';
			}
			
			var EmailLabel = document.getElementById('EmailLabel');
			
			if(EmailLabel != null)
			{
				EmailLabel.style.color = '#333';
			}
			
			var NameLabel = document.getElementById('NameLabel');
			
			if(NameLabel != null)
			{
				NameLabel.style.color = '#333';
			}
			
			var PhoneLabel = document.getElementById('Phone');
			
			if(PhoneLabel != null)
			{
				PhoneLabel.style.color = '#333';
			}
			
			var CityLabel = document.getElementById('CityLabel');
			
			if(CityLabel != null)
			{
				CityLabel.style.color = '#333';
			}
			
			var LetterLabel = document.getElementById('LetterContentLabel');
			
			if(LetterLabel != null)
			{
				LetterLabel.style.color = '#333';
			}
			
			post += 'PostBackType=Letter&Email=' + escape(Email.value) + '&Name=' + escape(Name.value) + '&Phone=' + escape(Phone.value) + '&City=' + escape(City.value) + '&Letter=' + escape(Letter.value) + '&Valid=' + escape(Valid.value);
			
			//alert(post);
			
			CommentBox = document.getElementById('PostCommentBox');
			
			if(CommentBox != null)
			{
				CommentBox.innerHTML = "<p class='Title'>Sending Letter</p><p id='CommentLoader'></p>Please wait while your letter is sent to our editor.<br/><br/><input class='cancel' type='button' value='Close Window' onclick='closeMessageWindow();' /><br/>";
				
				xmlHttp = GetXmlHttpObject();
				
				if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request");
					return;
				}
				
				//xmlHttp.onreadystatechange = stateChangedSpin('CommentLoader');
				
				xmlHttp.onreadystatechange = function(){ stateChangedSpin('CommentLoader'); };
				
				xmlHttp.open("POST",window.location,true);
				
				xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				
				xmlHttp.send(post);
			}
			
			
		}
		else
		{
			var EmailLabel = document.getElementById('EmailLabel');
			
			if(EmailLabel != null)
			{
				if(Email.value == '')
				{
					EmailLabel.style.color = '#F00';
				}
				else
				{
					EmailLabel.style.color = '#333';
				}
			}
			
			var NameLabel = document.getElementById('NameLabel');
			
			if(NameLabel != null)
			{
				if(Name.value == '')
				{
					NameLabel.style.color = '#F00';
				}
				else
				{
					NameLabel.style.color = '#333';
				}
			}
			
			var PhoneLabel = document.getElementById('PhoneLabel');
			
			if(PhoneLabel != null)
			{
				if(Phone.value == '')
				{
					PhoneLabel.style.color = '#F00';
				}
				else
				{
					PhoneLabel.style.color = '#333';
				}
			}
			
			var CityLabel = document.getElementById('CityLabel');
			
			if(CityLabel != null)
			{
				if(City.value == '')
				{
					CityLabel.style.color = '#F00';
				}
				else
				{
					CityLabel.style.color = '#333';
				}
			}
			
			var LetterLabel = document.getElementById('LetterContentLabel');
			
			if(LetterLabel != null)
			{
				if(Letter.value == '')
				{
					LetterLabel.style.color = '#F00';
				}
				else
				{
					LetterLabel.style.color = '#333';
				}
			}
			
			var ErrorText = document.getElementById('CommentErrorText');
			
			if(ErrorText != null)
			{
				ErrorText.innerHTML = 'Please Fill Out ALL <b>Required</b> Fields!';
			}
		}
		
	}
	else if(Valid != null && Valid.value != 'valid')
	{
		closeMessageWindow();
	}
	else
	{
		alert("An Error Has Occured. Please Refresh This Page and Try Again. We Apologize For Any Inconvenience.");
	}
	
	return (false);
}

function limitCommentText(limitField, limitCountId)
{
	var limitCount = document.getElementById(limitCountId);
	
	limitNum = parseInt(limitField.form.characters.value);
	
	if(limitCount != null && limitNum > 0)
	{
		if (limitField.value.length > limitNum)
		{
			limitField.value = limitField.value.substring(0, limitNum);
			
		}
		
		limitCount.innerHTML = limitNum - limitField.value.length;
		
	}
	
	
}

function limitText(limitField, limitCountId, limitNum)
{
	var limitCount = document.getElementById(limitCountId);
	
	if(limitCount != null)
	{
		if (limitField.value.length > limitNum)
		{
			limitField.value = limitField.value.substring(0, limitNum);
		}
		else
		{
			limitCount.innerHTML = limitNum - limitField.value.length;
		}
	}
	
	
}

function checkName(nameField, facebookId)
{
	var facebookField = document.getElementById('CommentNameFacebookLabel');

	if(facebookField != null && nameField != null)
	{
		if(nameField.value != '' && window.commentName == nameField.value)
		{
			facebookField.innerHTML = "<img src='/FacebookVerified.jpg' style='margin-bottom:-2px; height:14px; width:14px;' /> Facebook Verified";
			
			nameField.form.characters.value = '2000';
			
			document.getElementById('CommentMax').innerHTML = '2000';
			
			limitCommentText(nameField.form.comment, 'CommentCountdown');
		}
		else
		{
			facebookField.innerHTML = "";
			
			nameField.form.characters.value = '500';
			
			document.getElementById('CommentMax').innerHTML = '500';
			
			limitCommentText(nameField.form.comment, 'CommentCountdown');
		}
	}
}


function closeMessageWindow()
{
	if(window.MessageWindowDisplayed == true)
	{
		window.MessageWindowDisplayed = false;
		
		fade('messageContent', 1);
		
		setTimeout("fade('messageBackground', '.5')", 250);
	}
}

function moveMessage()
{
	if (window.BrowserDetect.browser == "Explorer")
	{
		//var position = document.body.scrollTop;
		var position = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	else {
		var position = window.pageYOffset;
	}
	
	document.getElementById('messageContent').style.top = (position + 50) + 'px';
}

var set=false;
var v=0;
var a;
function loadStars(src1, src2)
{
	a = 0;
	v = 0;
	set = false;
	star1 = new Image();
	//star1.src = "http://www.dinethevillage.com/star3.gif";
	star1.src = src1;
	star2 = new Image();
	//star2.src= "http://www.dinethevillage.com/star4.gif";
	star2.src= src2;
	//var start = document.getElementById('rating').value;
	//if(start > 0)
	//{
	//	setStar(start);
	//}
}

function highlight(x)
{
	//if (set==false)
    //{
    y=x*1+1
    switch(x)
	{
        case "1": document.getElementById(x).src= star2.src;
			//document.getElementById('vote').innerHTML="one star";
			break;
        case "2":for (i=1;i<y;i++)
        {
			document.getElementById(i).src= star2.src;
        }
			//document.getElementById('vote').innerHTML="two stars"
			break;
        case "3":for (i=1;i<y;i++)
        {
			document.getElementById(i).src= star2.src;
        }
			//document.getElementById('vote').innerHTML="three stars"
			break;
        case "4":for (i=1;i<y;i++)
        {
			document.getElementById(i).src= star2.src;
        }
			//document.getElementById('vote').innerHTML="four stars"
			break;
        case "5":for (i=1;i<y;i++)
        {
			document.getElementById(i).src= star2.src;
        }
			//document.getElementById('vote').innerHTML="five stars"
			break;
	}
    //}
}
function losehighlight(x)
{
	//if (set==false)
    //{
    
    
	for (i=1;i<6;i++)
	{
        document.getElementById(i).src=star1.src;
        //document.getElementById('vote').innerHTML=""
	}
	if(a > 0)
	{
		highlight(a);
	}
    
    //}
}
function setStar(x)
{
	y=x*1+1
	//if (set==false)
    //{
    v=0;
    switch(x)
	{
        case "1": a="1" 
			flash(a);
			break;
        case "2": a="2" 
			flash(a);
			break;
        case "3": a="3" 
			flash(a);
			break;
        case "4":a="4" 
			flash(a);
			break;
        case "5":a="5" 
			flash(a);
			break;
	}
    set=true;
    document.getElementById('CommentRating').value=a
    //} 
}
function flash()
{
	y=a*1+1
	switch(v)
    {
		case 0:
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star1.src;
			}
			v=1
			setTimeout(flash,200)
			break;
		case 1: 
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star2.src;
			}
			v=2
			setTimeout(flash,200)
			break;
		case 2:
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star1.src;
			}
			v=3
			setTimeout(flash,200)
			break;
		case 3:
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star2.src;
			}
			v=4
			setTimeout(flash,200)
			break;
		case 4:
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star1.src;
			}
			v=5
			setTimeout(flash,200)
			break;
		case 5:
			for (i=1;i<y;i++)   
			{
				document.getElementById(i).src= star2.src;
			}
			v=6
			setTimeout(flash,200)
			break;
    }
}


function stateChangedSpin(id) 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		eval(xmlHttp.responseText);
		
	}
	else
	{
		document.getElementById(id).innerHTML = "<center><img src='http://www.oakpark.com/ajax-loader.gif' /></center>";
	}
	
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function NewWindow(mypage,myname,w,h,pos,infocus){
    if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
    else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
    settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
    win.focus();
}


//start();
