
	function VideoWall()
	{
		var self=this;
		var master=self;
		this.init=function()
		{
			self.merge_configs();
			self.container=JQ('div#'+self.config.container_div);
			
			//ui
			self.popup=new PopUp(self,'modal');
			
			//tunnels:
			self.ajax_tunnel=new AjaxTunnel();
			self.f4a_tunnel=new F4ATunnel(self);
			self.demand_tunnel=new DemandTunnel(self);
			
			//managers:
			self.video_manager=new VideoManager(self);
			self.comment_manager=new CommentManager(self);
			
			//front end:
			self.front_end=new VideoWallFrontEnd(self);
			self.preload_images();
			//init:
			self.handle_params();
		}
		this.merge_configs=function()
		{
			var default_config=
			{
				locale:'en_US',
				all_wall_channel_id:167,
				container_div:'video_wall',
				login_url:'#',
				video_player:
				{
					regionConfig:"/nikebasketball/us/en_US/xml/regVideoConfig.xml",
					siteConfig:"/nikebasketball/global/xml/videoSiteConfig.xml"
				},
				sub_channels:[],
				images:
				{
					prev_active:"/nikebasketball/global/images/video_wall/paging_last_active.gif",
					prev_inactive:"/nikebasketball/global/images/video_wall/paging_last_inactive.gif",
					next_active:"/nikebasketball/global/images/video_wall/paging_next_active.gif",
					next_inactive:"/nikebasketball/global/images/video_wall/paging_next_inactive.gif",
					comment_bg:"/nikebasketball/global/images/video_wall/post_bg_no_avatar.gif",
					comment_bottom:"/nikebasketball/global/images/video_wall/comment_no_avatar_bot.gif",
					comment_top:"/nikebasketball/global/images/video_wall/comment_no_avatar_top.gif",
					post_bg:"/nikebasketball/global/images/video_wall/post_bg_no_avatar.gif",
					pencil:"/nikebasketball/global/images/video_wall/pencil_icon.gif",
					star_active:"/nikeos/global/image/videowall/star_active.gif",
					star_inactive:"/nikeos/global/image/videowall/star_inactive.gif",
					star_half:"/nikeos/global/image/videowall/star_half.gif",
					thumbnail_overlay:"/nikebasketball/global/images/video_wall/thumbnail_play_overlay.png",
					abuse_img:"http://www.nike.com/g1/global/images/commenting/flag_on.gif",
					no_abuse_img:"http://www.nike.com/g1/global/images/commenting/flag_off.gif"
				},
				touts:[],
				translations:
				{
					write_a_comment:"WRITE A COMMENT",
					submit:"submit",
					cancel:"Cancel",
					added_a_comment:"added a comment",
					also_see:"Also See",
					related_videos:"Related Videos",
					channels:"Channels",
					videos:"Videos",
					episodes:"Episodes",
					add_comment:"ADD COMMENT",
					read:"VIEW",
					loading:"loading",
					newest:"NEWEST",
					no_video_found:"Nothing was found.",
					comments:"Comments",
					no_comments:"No comments have been made.",
					no_comment_entered:"no comment entered",
					comment_too_long:"comment is too long!",
					report_abuse:"Report Abuse",
					report_abuse_desc:"What is the primary reason you are reporting this message as abusive?"
				}
			};
			self.config=JQ.extend(true,{},default_config,VIDEOWALL_CONFIG);
			//determing correct blog domain:
			if(location.host.match(/env1-brand/i))	
			{
				self.config.blog_base_url="http://inside-staging.nike.com/";
				self.config.blog_community=self.config.staging_blog_community;
			}
			else if(location.host.match(/nike\.com/i))
			{
				self.config.blog_base_url="http://inside.nike.com/";
				self.config.blog_community=self.config.prod_blog_community;
			}
			else
			{
				self.config.blog_base_url="http://cs.ny.rga.com/";
				self.config.blog_community=self.config.dev_blog_community;
			}
			self.config.blog_base_url+="everywhere/780";
		}
		this.handle_params=function()
		{
			//-check hash param.
			var guid=getParam('guid','hash')||getParam('guid','query_string');
			if(guid.length>1)
			{
				self.initial_guid=guid;
				self.front_end.events.open_guid(guid);
			}
		}
		this.preload_images=function()
		{
			for(var p in self.config.images)
				self.container.append("<img src=\""+self.config.images[p]+"\" class=\"hidden\" />")
		}
		
		self.init();
	}
	
	//front end objects:
	function VideoWallFrontEnd(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			self.container=JQ('div#video_wall');
			self.container.addClass('right_background');
			
			self.video_player=new VideoPlayer(self);
			self.left_side=new WallLeftSide(self);
			self.right_side=new WallRightSide(self);
			
			self.mode='video';
			
			self.events=
			{
				open_video:function(video)
				{
					self.guid=video.guid;
					self.video_player.change_video(video);
					self.left_side.video_detail.change_video(video);
					JQ('html, body').animate({scrollTop:	JQ('div#wall_video_player').offset().top	}, 'slow');
					
					if(video.tags.length>0 && self.left_side.left_video_section.tabs.get_tab()!='episodes' && self.left_side.left_video_section.tabs.get_tab()!='related_videos')
						self.events.load_related_videos(video);
					else if(self.left_side.left_video_section.tabs.get_tab()!='related_videos')
						self.left_side.left_video_section.tabs.hide_tab('related_videos');
					
					//update right side:
					self.left_side.left_comment_section.change_video(video);
					self.right_side.right_info.video_changed(video);
				},
				open_channel_episodes:function(id)
				{
					self.left_side.left_video_section.tabs.hide_tab('related_videos');
					self.left_side.left_video_section.tabs.show_tab('episodes');
					self.left_side.left_video_section.tabs.open_tab('episodes');
					self.left_side.left_video_section.grids['episodes'].configure({type:'channel',channel_id:id});
				},
				load_related_videos:function(video)
				{
					self.left_side.left_video_section.tabs.hide_tab('episodes');
					self.left_side.left_video_section.grids['related_videos'].configure({type:'related_videos',tags:video.tags});
				},
				open_guid:function(guid)
				{
					parent.video_manager.load_guid(guid,function(data)
					{
						self.events.open_video(data.items[0]);
					});
				},
				toggle:function(add)
				{
					if(self.mode=='video')
						self.mode='comment';
					else
						self.mode='video';
					
					self.left_side.toggle(add);
					self.right_side.toggle();	
				}
			};
		}		
		self.init();
	}
	
	function VideoPlayer(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div id=\"wall_video_player\"></div>");
			self.container=JQ('div#wall_video_player');
			self.guid=null;
		}
		this.change_video=function(video)
		{
			if(!video || !video.guid)
				return;
			var player = new SWFObject("/nikeos/global/modules/video/v1/swf/video_player_v2_0.swf", "feature", "908", "510", "9.0.28", "#ffffff");
			player.addParam("scale", "noscale");
			player.addParam("allowScriptAccess", "always");
			player.addParam("allowFullScreen", "true");
			player.addParam("wmode", "transparent");
			player.addVariable("locale", parent.parent.config.locale);
			player.addVariable("guid", video.guid);
			player.addVariable("regionConfig",parent.parent.config.video_player.regionConfig);
			player.addVariable("siteConfig",parent.parent.config.video_player.siteConfig);
			player.addVariable("trackerObject", escape(JSON.stringify(nav_tracker_obj)));
			
			//autoplay:
			if(self.guid && self.guid!=null)
				player.addVariable("autoPlay", "true");
			
			var write=player.write("wall_video_player");
			if(!write)
				self.container.html("<div id=\"noflash\"><a href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\"><img src=\"/sportswear/global/images/no_flash.jpg\" border=\"0\"></a></div>");
			self.guid=video.guid;	
		}
		this.get_guid=function()
		{
			return self.guid;
		}
		self.init();
	}
	function VideoDetail(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div class=\"video_detail\"></div>");
			self.container=JQ('.video_detail');
			
			//dummy container for sizing shit
			parent.container.append("<div class=\"video_detail far_off\"></div>");
			self.dummy_container=JQ('.video_detail.far_off');
		}
		this.change_video=function(video)
		{
			var height=self.container.height();
			self.container.css({height:height}).animate({opacity:0},function(){	self.render_video(video)	});	
		}
		this.render_video=function(video)
		{
						
			var str ="<div class=\"active_text title border\">"+video.title+"</div>";
				str+="<div class=\"light_text under_title\" >";
				str+=date_str(video.date);
				str+=" - "+video.views+" views";
				str+="</div>";
				str+="<div class=\"standard_text description\">"+video.description+"</div>";
			self.dummy_container.html(str);
						
			var height=self.dummy_container.height();
			self.container.html(str).animate({height:height,opacity:1});
			
			
			if(video.description.length==0)
				self.container.find(".description").hide();
			else
				self.container.find(".description").show();	
		}
		self.init();
	}
	
	function WallLeftSide(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			self.mode='video';
			parent.container.append("<div id=\"wall_left_side\" class=\"left_background\" ><div id=\"wall_left_content\"></div></div>");
			self.container=JQ('div#wall_left_content');
		
			self.video_detail=new VideoDetail(self);
			self.left_video_section=new LeftVideoSection(self);
			self.left_comment_section=new LeftCommentSection(self);
		}
		this.toggle=function(add)
		{
			if(self.mode=='video')
			{
				self.left_video_section.hide();
				self.left_comment_section.show(add);
				self.mode='comments';
			}
			else
			{
				self.left_comment_section.hide();
				self.left_video_section.show();
				self.mode='video';
			}
		}
		self.init();
	}
	
	//--Video Section Objects - Left Side:
	function LeftVideoSection(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			parent.container.append("<div id=\"left_video_content\"></div>");
			self.container=JQ('#left_video_content');
			
			self.tabs=new VideoTabs(self);
			
			self.container.append("<div id=\"left_grid_content\"></div>");
			self.content=JQ('#left_grid_content');
			
			self.tabs.add_tab('related_videos',parent.parent.parent.config.translations.related_videos,{type:'related_videos'});
			self.tabs.add_tab('videos','Videos',{type:'channel',channel_id:parent.parent.parent.config.all_wall_channel_id});
			self.tabs.add_tab('channels',parent.parent.parent.config.translations.channels);
			self.tabs.add_tab('episodes',parent.parent.parent.config.translations.episodes,{type:'channel'});
			
			self.tabs.hide_tab('related_videos');
			self.tabs.hide_tab('episodes');

		}
		this.hide=function()
		{
			self.container.hide();
		}
		this.show=function()
		{
			self.container.show();
		}
		self.init();
	}	
	function VideoTabs(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div id=\"video_tabs_wrapper\"><div id=\"video_tabs\" class=\"border\" ></div></div>");
			self.container=JQ('#video_tabs');
			self.currently_active_tab=null;
			self.tabs={};
			self.tracking_go=false;
		}
		this.get_tabs=function()
		{
			return self.tabs;			
		}
		this.add_tab=function(id,label,config)
		{
			self.tabs[id]={id:id,label:label,total:0};
			
			var str="<div class=\"video_tab left_background light_text border\" id=\"tab_"+id+"\">"+label+"<span>(0)</span></div>";
			self.container.append(str);
			self.container.find('div.video_tab').click(	function(){	self.open_tab(JQ(this).attr('id').replace('tab_','') );	}	);
			self.container.find('div.video_tab').hover(function()
			{
				JQ(this).addClass('standard_text');
				JQ(this).find('span').addClass('light_text');
			},function()
			{
				if(!JQ(this).hasClass('active'))
					JQ(this).removeClass('standard_text');
			});
			
			parent.content.append("<div id=\"tab_content_"+id+"\" class=\"tab_content\" >"+label+"</div>");
			
			if(!parent.grids)
				parent.grids={};
			
			if(id!='channels')	
				parent.grids[id]=new VideoGrid(parent,id,config);
			else
				parent.grids[id]=new ChannelGrid(parent,id);	
		}
		this.set_total=function(id,total)
		{
			self.tabs[id].total=total;
			self.container.find('div#tab_'+id+' span').html('('+total+')');
		}
		this.open_tab=function(id)
		{
			var tab=self.container.find('div#tab_'+id);
			
			if(	tab.hasClass('active')	)
				return;
			
			//tracking fix:
			if(self.tracking_go)
				tracking.click({pageName:track_site+">media>video>"+id,prop18:"media",prop19:"video"});
			self.tracking_go=true;	
			
			var active_tab=self.container.find('div.video_tab.active');
			active_tab.removeClass('standard_text').removeClass('active');
			active_tab.find('span').removeClass('active_text');
			if(	active_tab.attr('id')	)
				parent.content.find('#tab_content_'+active_tab.attr('id').replace('tab_','')).removeClass('active');
			
			tab.show();
			tab.addClass('active');
			tab.addClass('standard_text');
			tab.find('span').addClass('active_text');
			parent.content.find('#tab_content_'+id).addClass('active');
			self.currently_active_tab=id;
		}
		this.get_tab=function()
		{
			return self.currently_active_tab;
		}
		this.show_tab=function(id)
		{
			self.container.find('div#tab_'+id).show();
		}
		this.hide_tab=function(id)
		{
			self.container.find('div#tab_'+id).hide();
			parent.content.find('div#tab_content_'+id).removeClass('active');
		}
		self.init();
	}	
	function VideoGrid(parent,id,config)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			self.container=JQ('#tab_content_'+id);
			self.container.empty();
			self.sort='date';
			self.sort_menu=new VideoGridSort(self);
			self.top_paging=new Paging(self);
			self.container.append("<div class=\"video_result_content\">CONTENT</div>");
			self.content=self.container.find('div.video_result_content');
			self.bot_paging=new Paging(self,true);
			self.configure(config);
		}
		this.configure=function(data)
		{
			self.configuration=data;
			self.page=1;
			
			if(id=='episodes')
				self.open=true;
				
			if((self.configuration.type=='channel' && self.configuration.channel_id)||(self.configuration.type=='related_videos'&&self.configuration.tags))
				self.set_page(1);
		}
		self.fetch_channel=function(channel_id,page,sort)
		{
			if(sort)
				self.sort=sort;
				
			self.container.css({opacity:0});
			parent.parent.parent.parent.video_manager.load_channel(channel_id,page,self.sort,self.fetched_channel);				
		}
		self.set_sort=function(sort)
		{
			self.sort=sort;
			self.page=1;
			self.fetch_channel(self.configuration.channel_id,1,sort);
		}
		self.set_channel_page=function(page)
		{
			self.page=page;
			self.fetch_channel(self.configuration.channel_id,page);
		}
		self.fetched_channel=function(data,related)
		{
			//set total:
			parent.tabs.set_total(id,data.total);
			
			if(related)
			{
				if(data.total>1)
					parent.tabs.show_tab('related_videos');
				else
					parent.tabs.hide_tab('related_videos');	
			}
			
			//sync up paging:
			if(data.totalPages>1)
			{
				self.top_paging.set_page(self.page,data.totalPages);
				self.bot_paging.set_page(self.page,data.totalPages);
				self.container.find('.paging').css('visibility','visible');				
			}
			else
			{
				self.container.find('.paging').css('visibility','hidden');
			}
			
			//render thumbnails:
			var str="";
			for(var p=0;p<data.items.length;p++)
			{
				str+="<div class=\"video_thumb";
					
				if(data.items[p].guid==parent.parent.parent.video_player.get_guid())
					str+=" active";
						
				str+="\" rel=\""+data.items[p].guid+"\">";
				str+="	<div class=\"thumb_wrapper\"><img src=\""+data.items[p].thumb+"\" class=\"border thumbnail_border\" /><div class=\"overlay\"></div></div>";
				str+="	<div class=\"title standard_text\">"+data.items[p].title+"</div>";
				str+="	<div class=\"date light_text\">"+date_str(data.items[p].date)+"</div>";
				str+="	<div class=\"views light_text\">"+data.items[p].views+" Views</div>";
				
				//--put rating star logic in here:
				var rating=data.items[p].rating;
				var rating_str="";
				var star_count=0;
				while(rating>=1)
				{
					rating_str+="<img src=\""+parent.parent.parent.parent.config.images.star_active+"\" />";
					star_count++;
					rating-=1;
				}
				if(rating>=0.5)
				{
					rating_str+="<img src=\""+parent.parent.parent.parent.config.images.star_half+"\" />";
					star_count++;
				}
				for(var i=0;i<(5-star_count);i++)
					rating_str+="<img src=\""+parent.parent.parent.parent.config.images.star_inactive+"\" />";
				
				str+="	<div class=\"views light_text\">"+rating_str+"</div>";
				
				str+="	<div class=\"hidden description\">"+data.items[p].description+"</div>";
				str+="</div>";
					
				if((p+1)%4==0 && p!=0)
					str+="<div class=\"clearme\"></div>";
			}
			
			self.content.html(str);
			
			//for redraw:
			self.content.find('.video_thumb.active .overlay').html("<img src=\""+parent.parent.parent.parent.config.images.thumbnail_overlay+"\" />").css({opacity:.8,visibility:'visible'});
			
			//thumbnail hover:
			self.content.find('.video_thumb').hover(function()
			{
				if(JQ(this).hasClass('active'))
					return;
				
				var desc=JQ(this).find('div.description').html();
				if(desc.length>0)
					desc="<div class=\"desc\">"+limit_string(desc,70)+"</div>";
				else
					desc="<img src=\""+parent.parent.parent.parent.config.images.thumbnail_overlay+"\" />";
				
				self.content.find('.video_thumb').not('.active').find('.overlay').hide();
				
				JQ(this).find('.overlay').html(desc).css({opacity:.8,visibility:'visible'}).show();
			},function()
			{
				if(JQ(this).hasClass('active'))
					return;
				JQ(this).find('.overlay').hide();
			});
			
			//on click:
			self.content.find('.video_thumb').click(function()
			{
				if(JQ(this).hasClass('active'))
					return;
				
				self.content.find('.video_thumb.active').removeClass('active').find('.overlay').hide();
				
				var guid=JQ(this).attr('rel');
				JQ(this).addClass('active');
				JQ(this).find('.overlay').html("<img src=\""+parent.parent.parent.parent.config.images.thumbnail_overlay+"\" />").css({visibility:'visible',opacity:0.8});
				
				var vid=parent.parent.parent.parent.video_manager.cached_vids[guid];
				parent.parent.parent.events.open_video(vid);
				
				location.href="#?guid="+guid;
			});
			
			if(id=='videos' && (!parent.parent.parent.video_player.guid || parent.parent.parent.parent.initial_guid))
			{
				parent.tabs.open_tab(id);
				
				if(!parent.parent.parent.parent.initial_guid)
					self.container.find('div.video_thumb:first').click();
			}
		
			self.container.animate({opacity:1},'fast');
			
			if(self.open)
			{
				parent.tabs.show_tab('episodes');
				parent.tabs.open_tab('episodes');
			}
		}
		self.set_page=function(page)
		{
			if(self.configuration.type=='channel')
				self.set_channel_page(page);
			else if(self.configuration.type=='related_videos')
				self.set_related_videos_page(page);
		}
		self.set_related_videos_page=function(page)
		{
			self.page=page;
			self.fetch_related_videos(self.configuration.tags,page);
		}
		self.fetch_related_videos=function(tags,page)
		{
			self.container.animate({opacity:0},'fast',function()
			{
				parent.parent.parent.parent.video_manager.load_tags(tags.replace(" ",","),page,'date',function(data)
				{
					self.fetched_channel(data,true);
				});
			});
		}
		self.init();
	}
	function ChannelGrid(parent,id)
	{
		var self=this;
		this.init=function()
		{
			self.container=JQ('#tab_content_'+id);
			var channels=parent.parent.parent.parent.config.sub_channels;
			parent.tabs.set_total(id,channels.length);
			
			self.total=channels.length;
			
			var channels_str="";
			for(var i=0;i<parent.parent.parent.parent.config.sub_channels.length;i++)
				channels_str+=parent.parent.parent.parent.config.sub_channels[i].id+",";
			
			var url="/nikeos/p/nikeos/en_US/video_wall/channel_totals?locale="+parent.parent.parent.parent.config.locale+"&channels="+channels_str;
			parent.parent.parent.parent.ajax_tunnel.issue(
				{
					u:url,
					data:{},
					c:function(data)
					{
						self.channel_totals=data;
						var str="";
						for(var i=0;i<channels.length;i++)
						{
							str+="<div class=\"channel_tout\" rel=\""+channels[i].id+"\">";
							str+="	<img src=\""+channels[i].img+"\"/>";
							str+="	<div class=\"bottom\">";
							str+="		<div class=\"title standard_text\">"+channels[i].title+"</div>";
							str+="		<div class=\"episodes light_text\"><span class=\"active_text\">"+self.channel_totals[channels[i].id]+"</span> "+parent.parent.parent.parent.config.translations.episodes.toLowerCase()+"</div>";
							str+="	</div>";
							str+="</div>";
						}
						self.container.html(str);
						self.container.find('.channel_tout').click(function()
						{
							tracking.click({pageName:track_site+">media>video>channels>"+JQ(this).find('.title').html(),prop18:"media",prop19:"video"});
							parent.parent.parent.events.open_channel_episodes(	JQ(this).attr('rel')	);
							parent.tabs.set_total('episodes',	JQ(this).find('div.episodes>span.active_text').html()	);
						});
					}
				});
		}
		this.redraw=function(){}
		self.init();
	}	
	function VideoGridSort(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div class=\"video_grid_sort\"></div>");
			self.container=parent.container.find('.video_grid_sort');
			self.build_sort();
		}
		this.build_sort=function()
		{
			var str="";
			str+="<div class=\"sort_by_videowall standard_text active\">SORT BY</div>";
			str+="<div class=\"sort_option light_text active_text active\" rel=\"date\" >NEWEST</div>";
			str+="<div class=\"sort_option light_text\" rel=\"views\" >VIEWS</div>";
			str+="<div class=\"sort_option light_text\" rel=\"rating\" >RATING</div>";
			self.container.html(str);
			
			//click on sort button
			self.container.find('.sort_option').click(function()
			{
				if(JQ(this).hasClass('active'))
					return;
				self.container.find('.sort_option.active').removeClass('active active_text');
				JQ(this).addClass('active active_text');
				
				parent.set_sort(	JQ(this).attr('rel')	);
			});
			
			//hover over sort button
			self.container.find('.sort_option').hover(function()
			{
				if(!JQ(this).hasClass('active'))
					JQ(this).addClass('standard_text');
			},function()
			{
				JQ(this).removeClass('standard_text');
			});
		}
		self.init();
	}
	
	//Comment Section Modules - Left Side:
	function LeftCommentSection(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			self.guid=false;
			self.page=0;
			self.per_page=8;
			parent.container.append("<div id=\"left_comment_section\"></div>");
			self.container=JQ('#left_comment_section');
			self.build_frame();
		}
		this.build_frame=function()
		{
			self.top_paging=new Paging(self);
			
			self.container.append("<div class=\"write_comment_btn write_top light_text\">"+parent.parent.parent.config.translations.write_a_comment+"<img src=\""+parent.parent.parent.config.images.pencil+"\" /></div>");
			self.post_form=new PostForm(self);
						
			self.container.append("<div class=\"comment_result_content\">CONTENT</div>");
			self.content=self.container.find('div.comment_result_content');
			self.bot_paging=new Paging(self,true);
			self.container.append("<div class=\"write_comment_btn write_bot light_text\">"+parent.parent.parent.config.translations.write_a_comment+"<img src=\""+parent.parent.parent.config.images.pencil+"\" /></div>");
			
			//--activate frame buttons:
			
			//--'write a 
			//--top 'write a comment' link
			self.container.find('div.write_comment_btn:first').click(self.post_form.toggle);
			//--bottom 'write a comment' link
			self.container.find('div.write_comment_btn:last').click(function()
			{
				JQ('html, body').animate({scrollTop:	JQ('div#left_comment_section').offset().top	}, 'slow');
				self.post_form.toggle();
			});
			//--hover
			self.container.find('div.write_comment_btn').each(function()
			{
				JQ(this).hover(function(){	JQ(this).addClass('standard_text');	},function(){	JQ(this).removeClass('standard_text');	});
			});
		}
		this.hide=function(){	self.container.hide();}
		this.change_video=function(video)
		{
			self.guid=video.guid;
			self.page=1;
		}
		this.show=function(add)
		{
			parent.parent.parent.comment_manager.load_thread(self.guid,function(data)
			{
				self.data=data;
				self.post_form.build_form();
				self.set_page();
				self.container.show();
				if(add==true)
					self.post_form.toggle(add);
			});
		}
		this.set_page=function(page)
		{
			if(page)
				self.page=page;
			if(!self.data.messages)
				self.data.messages=[];
			var total_pages=Math.ceil((self.data.messages.length)/self.per_page);
			self.top_paging.set_page(self.page,total_pages);
			self.bot_paging.set_page(self.page,total_pages);
			
			self.render();
		}
		this.render=function()
		{
			var str="";
			var messages=self.data.messages;
			var start=self.per_page*(self.page-1);
			var end=self.per_page*self.page;

			if(messages)
			{
				for(var i=0;i<messages.length;i++)
				{
					if(messages[i]!=null && i>=start && i<end )
					{
						str+="<div class=\"comment_wrapper no_avatar\" style=\"background:url("+parent.parent.parent.config.images.comment_bg+") repeat-y left top;\" >";
						str+="	<div class=\"comment_top\" style=\"background:url("+parent.parent.parent.config.images.comment_top+") no-repeat left top;\" ></div>";
						str+="	<div class=\"post_left\">";
						str+="		<div class=\"username comment_username\">"+messages[i].username+"</div>";
						str+="		<div class=\"date comment_date\">"+messages[i].date+"</div>";
						str+="	</div>";
						str+="	<div class=\"post_right\">";
						str+="		<div class=\"body comment_body\">";
						str+=			messages[i].body;

						if(!messages[i].abuse)
						{
							if(messages[i].message_id)
								str+="	<div class=\"flag_comment\" id=\"message_"+messages[i].message_id+"\"><a href=\"javascript:;\" class=\"flag\"><img src=\""+parent.parent.parent.config.images.no_abuse_img+"\" /></a></div>";
						}
						else
							str+="	<div class=\"flag_comment\" ><img src=\""+parent.parent.parent.config.images.abuse_img+"\" /></div>";
						
						str+=		"</div>";
						str+="	</div>";
						str+="	<div class=\"clearme\"></div>";
						str+="	<div class=\"comment_bottom_row\" style=\"background:url("+parent.parent.parent.config.images.comment_bottom+") no-repeat left top;\" ></div>";
						str+="</div>";
					}
				}
			}
			
			if(!messages || messages.length==0)
				str="<div class=\"no_comments_left light_text\">"+parent.parent.parent.config.translations.no_comments+"</div>";
				
			self.content.html(str);
			self.content.find('div.flag_comment>a.flag').click(function()
			{
				var message_id=JQ(this).parent().attr('id').replace('message_','');
				self.showForm(message_id);
			});
		}
		this.showForm=function(id)
		{
			var str="";
			
			str+="<div class=\"flag_form left_background\">";
			str+="	<div class=\"report_abuse_title active_text\">"+parent.parent.parent.config.translations.report_abuse+"</div>";
			str+="	<div class=\"report_abuse_desc standard_text\">"+parent.parent.parent.config.translations.report_abuse_desc+"</div>";
			str+="	<textarea id=\"comments\" class=\"report_abuse_textarea border\" ></textarea>"
			str+="	<div class=\"bot_row\">";
			str+="		<a href=\"javascript:;\" class=\"report_abuse_submit active_text\" >"+parent.parent.parent.config.translations.report_abuse+"</a>";
			str+="		<a href=\"javascript:;\" class=\"cancel light_text\" >"+parent.parent.parent.config.translations.cancel+"</a>";
			str+="	</div>";
			str+="</div>";
			
			parent.parent.parent.popup.set(str);
			parent.parent.parent.popup.show();
			
			
			JQ('div.flag_form a.report_abuse_submit').click(function()
			{
				parent.parent.parent.comment_manager.flagMessage(id, JQ('div.flag_form textarea').val(), self.hideForm);
				JQ('div.flag_form').html("<div class=\"loading standard_text\">loading</div>");
			});
			
			JQ('div.flag_form a.cancel').click(function()
			{
				parent.parent.parent.popup.close();
			});
		}
		this.hideForm=function()
		{
			//reload comments:
			self.set_page(1);
			self.show();
			parent.parent.parent.popup.close();
		}
		self.init();
	}
	
	function PostForm(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div id=\"post_comment_form_wrapper\"></div>");
			self.container=parent.container.find('div#post_comment_form_wrapper');
		}
		this.build_form=function()
		{
			var str="";
			str+="<div class=\"post_form no_avatar\">";
			str+="	<div class=\"no_avatar_wrapper\" style=\"background:url("+parent.parent.parent.parent.config.images.form_post_bg+") repeat-y left top;\">";
			str+="		<div class=\"post_form_top\" style=\"background:url("+parent.parent.parent.parent.config.images.form_comment_top+") no-repeat left top\" ></div>"
			str+="		<div class=\"post_left\">";
			str+="			<div class=\"username comment_username\">"+parent.data.username+"</div>";
			str+="		</div>";
			str+="		<div class=\"message\">";
			str+="			<div class=\"message_wrapper\">";
			str+="				<div class=\"message_input\"><textarea id=\"message\" class=\"comment_body\" ></textarea></div>";
			str+="			</div>";			
			str+="		</div>";
			str+="		<div class=\"clearme\"></div>";
			str+="		<div class=\"post_form_bot\"  style=\"background:url("+parent.parent.parent.parent.config.images.form_comment_bottom+") no-repeat left top\" ></div>";
			str+="	</div>";
			
			str+="	<div class=\"message_wrapper_options\">";
			str+="		<div class=\"remaining_chars light_text\">"+parent.data.chars_remaining+": <span>500</span></div>";				
			str+="		<a href=\"javascript:f();\" class=\"submit active_text\" >"+parent.parent.parent.parent.config.translations.submit+"</a>";
			str+="		<a href=\"javascript:f();\" class=\"cancel light_text\" >"+parent.parent.parent.parent.config.translations.cancel+"</a>";				
			str+="		<div class=\"clearme\"></div>";
			str+="	</div>";
			str+="	<div class=\"message_wrapper_status active_text\"></div>";
			str+="</div>";
			
			self.container.html(str);
			
			self.container.find('textarea').focus().keyup(function()
			{
				var max=500;
				var num=500-self.container.find('div.post_form textarea').val().length;
				self.container.find('div.post_form div.remaining_chars>span').html(	num	);
			});
			
			self.container.find('a.cancel').click(function()
			{
				self.container.find('textarea').val('');
				self.toggle();
				return false;
			});
			self.container.find('a.submit').click(function()
			{
				//check comment out:
				var comment=JQ.trim(self.container.find('textarea').val());
				self.container.find('div.message_wrapper_options').hide();
			
				if(comment.length==0)
				{
					self.container.find('div.message_wrapper_status').html(parent.parent.parent.parent.config.translations.no_comment_entered).css('opacity',0).show().animate({opacity:1},400,function()
					{
						setTimeout(function()
						{
							JQ('div.message_wrapper_status').animate({opacity:0},400,function()
							{
								JQ('div.message_wrapper_options').show();JQ(this).hide();	
							});
						},500);
					});
					return false;
				}
				else if(comment.length>500)
				{
					self.container.find('div.message_wrapper_status').html(parent.parent.parent.parent.config.translations.comment_too_long).css('opacity',0).show().animate({opacity:1},400,function()
					{
						setTimeout(function()
						{
							JQ('div.message_wrapper_status').animate({opacity:0},400,function()
							{
								JQ('div.message_wrapper_options').show();
								JQ(this).hide();
							});
						},500);
					});
					return false;		
				}
				self.container.find('div.message_wrapper_status').html('submitting').css('opacity',0).show().animate({opacity:1},400);
			
				comment=comment.replace(new RegExp( "\\n", "g" ),"<br />");
				comment=comment.replace(new RegExp( "\\r", "g" ),"<br />");

				parent.parent.parent.parent.comment_manager.post_comment(comment,parent.data,function(data)
				{
					parent.set_page(1);
					parent.show();
				});

			});
		}
		this.toggle=function(open)
		{
			//--check if not logged in and bounce user to login page:
			if(!parent.data.user_exists)
			{
				location.href=parent.parent.parent.parent.config.login_url+"&continueURL="+escape(location.href);
				return;
			}
			
			self.build_form();
			if(!open)
				self.container.toggle();
			else
				self.container.show();
				
			if(self.container.css('display')!='none')
			{
				self.container.find('textarea').focus();
				tracking.click({pageName:track_site+">media>video>comments>write",prop18:"media",prop19:"video"});
			}
		}
		self.init();
	}
	
	//--Reused Left Side Modules:
	function Paging(parent,border)
	{
		var self=this;
		this.init=function()
		{
			self.page=1;
			self.totalPages=0;
			
			//--#s to each side of active paging #
			self.numbers=1;
			
			self.id=Math.ceil(Math.random()*10000000000000000);
			var borderclass="paging";
			if(typeof border != 'undefined')
				borderclass+=" top_border border";
				
			parent.container.append("<div class=\""+borderclass+"\" id=\"paging_"+self.id+"\" ></div>");
			self.container=parent.container.find('div#paging_'+self.id);
		}
		this.render=function()
		{
			if(self.totalPages<=1)
				return self.hide();
			self.show();
			
			if(parent.constructor==VideoGrid)
				var config=parent.parent.parent.parent.parent.config;
			else
				var config=parent.parent.parent.parent.config;	
			
			self.container.empty();
			
			var str="";
			var start,end;

			if(self.page==1)
				str+="<a href=\"javascript:f();\" class=\"inactive\" ><img src=\""+config.images.prev_inactive+"\" /></a>";
			else
				str+="<a href=\"javascript:f();\" rel=\""+(self.page-1)+"\" ><img src=\""+config.images.prev_active+"\" /></a>";
			
			
			//get starting and ending # values:
			var j=self.totalPages;
			while(	j>(self.page-self.numbers)	&&	j>1 	)
				j--;
			start=j;
			
			end=start+2*self.numbers;
			if(end>self.totalPages)
				end=self.totalPages;
			
			while(start>1 && (end-start)<(2*self.numbers)	)
				start--;
			
			for(var i=start;i<=end;i++)
			{
				str+="<a href=\"javascript:f();\" ";
				if(self.page==i)
					str+="class=\"digit standard_text\"";
				else
					str+="class=\"digit light_text\"";
				str+="rel=\""+i+"\" >"+i+"</a>";
			}
			
			if(self.page==self.totalPages)
				str+="<a href=\"javascript:f();\" class=\"inactive\" ><img src=\""+config.images.next_inactive+"\" /></a>";
			else
				str+="<a href=\"javascript:f();\" rel=\""+(self.page+1)+"\" ><img src=\""+config.images.next_active+"\" /></a>";
			
			self.container.html(str);
			
			self.container.find('a').click(function(){return false;});
			self.container.find('a').not('.inactive').click(function(){	parent.set_page(	parseInt(JQ(this).attr('rel'))	);	});
			
		}
		this.set_page=function(page,total)
		{
			self.totalPages=total;
			self.page=page;
			self.render();
		}
		this.hide=function()
		{
			self.container.find('.paging').hide();
		}
		this.show=function()
		{
			self.container.find('.paging').show();
		}
		self.init();
	}	
	
	//-- Right Side Objects:
	
	function WallRightSide(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			parent.container.append("<div id=\"wall_right_side\" ><div id=\"wall_right_content\"></div></div>");
			self.container=JQ('div#wall_right_content');
			self.mode='video';
			
			self.right_info=new RightWallInfo(self);
			self.right_touts=new RightWallTouts(self);
		}
		this.toggle=function()
		{
			self.right_info.toggle();
		}
		self.init();
	}	
	
	function RightWallInfo(parent)
	{
		var self=this;
		this.init=function()
		{
			self.parent=parent;
			self.mode='video';
			parent.container.append("<div id=\"right_wall_info\"></div>");
			self.container=JQ('#right_wall_info');
			self.comments=new RightSideComments(self);
			self.videos=new RightSideVideos(self);
		}
		this.video_changed=function(video)
		{
			self.comments.video_changed(video);
		}
		this.toggle=function()
		{
			if(self.mode=='video')
			{
				self.mode='comment';
				self.comments.hide();
				self.videos.show();
			}
			else
			{
				self.mode='video';
				self.videos.hide();
				self.comments.show();
			}
		}
		self.init();
	}
	function RightSideVideos(parent)
	{
		var self=this;
		this.init=function()
		{
			parent.container.append("<div id=\"right_wall_videos\">HEY</div>");
			self.container=parent.container.find('#right_wall_videos');
			self.hide();
		}
		self.render=function()
		{
			var str="";
			str+="<div class=\"title border active_text\">"+parent.parent.parent.parent.config.translations.also_see+"</div>";
		
			var tabs=parent.parent.parent.left_side.left_video_section.tabs.get_tabs();
			for(var p in tabs)
			{
				if(tabs[p].total>0 &&	JQ('#tab_'+tabs[p].id).css('display')!='none'	)
					str+="<div class=\"tab_section standard_text\" id=\"tab_section_"+tabs[p].id+"\" ><img src=\""+parent.parent.parent.parent.config.images.next_inactive+"\" />"+tabs[p].label+" <span class=\"active_text\">("+tabs[p].total+")</span></div>";
			}
			self.container.html(str);
			self.container.find('.tab_section').click(function()
			{
				tracking.click({pageName:track_site+">media>video",prop18:"media",prop19:"video"});
				parent.parent.parent.events.toggle();
				parent.parent.parent.left_side.left_video_section.tabs.open_tab(	JQ(this).attr('id').replace('tab_section_','')	);
			});
			self.container.find('.tab_section').hover(function()
			{
				JQ(this).find('img').attr('src',parent.parent.parent.parent.config.images.next_active);
			},function()
			{
				JQ(this).find('img').attr('src',parent.parent.parent.parent.config.images.next_inactive);
			});
		}
		this.hide=function(){self.container.hide();}
		this.show=function(){self.render();self.container.show();}
		
		self.init();
	}
	function RightSideComments(parent)
	{
		var self=this;
		this.init=function()
		{
			self.guid=false;
			parent.container.append("<div id=\"right_wall_comments\"></div>");
			self.container=parent.container.find('#right_wall_comments');
		}
		this.video_changed=function(video)
		{
			//load comments based on this video and then render it out:
			parent.parent.parent.parent.comment_manager.load_thread(video.guid,function(data)
			{
				self.guid=video.guid;
				self.data=data;
				self.render();
			});
		}
		this.render=function()
		{
			var str="";
			str+="<div class=\"title active_text border\">"+self.data.messages_label+"</div>";
			
			if(self.data.messages && self.data.messages.length>0)
			{
				str+="<div class=\"date light_text\">"+self.data.messages[0].date+"</div>";
				str+="<div class=\"comment standard_text\">Last comment made by <span class=\"last_comment active_text\">"+self.data.messages[0].username+"</span></div>";
			}
			else
				str+="<div class=\"light_text no_comments standard_text\">"+parent.parent.parent.parent.config.translations.no_comments+"</div>";
			
			if(self.data.user_exists)
				str+="<div class=\"add light_text\">"+parent.parent.parent.parent.config.translations.add_comment+"</div>";
			str+="<div class=\"read light_text\">"+parent.parent.parent.parent.config.translations.read+"</div>";
			self.container.html(str);
			
			self.container.find('.add').click(function()
			{
				parent.parent.parent.events.toggle(true);
				tracking.click({pageName:track_site+">media>video>comments>write",prop18:"media",prop19:"video"});
			});
			
			self.container.find('.title, .read, .last_comment').click(function()
			{
				tracking.click({pageName:track_site+">media>video>comments",prop18:"media",prop19:"video"});
				parent.parent.parent.events.toggle();
			});
			self.container.find('.add, .read').hover(function()
			{
				JQ(this).addClass('standard_text');
			},function()
			{
				JQ(this).removeClass('standard_text');
			});
		}
		this.hide=function(){self.container.hide();}
		this.show=function()
		{
			parent.parent.parent.parent.comment_manager.load_thread(self.guid,function(data)
			{
				self.data=data;
				self.render();
				self.container.show();
			});
		}
		self.init();
	}
	
	
	function RightWallTouts(parent)
	{
		var self=this;
		this.init=function()
		{
			var str="<div id=\"right_wall_touts\">";
			var touts=parent.parent.parent.config.touts;
			
			for(var i=0;i<touts.length;i++)
				str+="<a href=\""+touts[i].url+"\"><img src=\""+touts[i].thumb+"\" /></a>";
			
			str+="</div>"	;
			parent.container.append(str);
		}
		self.init();
	}
	
	//managers:
	function VideoManager(parent)
	{
		var self=this;
		this.init=function()
		{
			self.cached_vids={};
			self.baseURL="/nikeos/p/nikeos/en_US/video_wall/odaptor?";
		}
		this.load=function(data,callback)
		{
			parent.ajax_tunnel.issue(
			{
				u:self.baseURL,
				d:data,
				c:self.loaded,
				callback:callback
			});
		}
		this.loaded=function(data, req)
		{
			if(data.error && data.error=='no_feed')
				return;
			
			for(var i=0;i<data.items.length;i++)
				self.cached_vids[data.items[i].guid]=data.items[i];
				
			data.totalPages=Math.ceil(data.total/data.pageSize);
			req.callback(data)
		}
		this.request=function(req)
		{
			var default_req=
			{
				pageSize:12,
				page:1,
				channelId:parent.config.all_wall_channel_id,
				locale:parent.config.locale,
				callback:function(data){}
			};
			req=JQ.extend(true,{},default_req,req);
			self.load(req,req.callback);
		}
		this.load_channel=function(channel,page,sort,callback)
		{
			self.request({	channelId:channel,page:page,sort_by:sort,callback:callback	});
		}
		this.load_guid=function(guid,callback)
		{
			self.request({guid:guid,callback:callback});
		}
		this.load_tags=function(tags,page,sort,callback)
		{
			self.request({tag_search:tags,page:page,sort_by:sort,callback:callback});
		}
		self.init();
	}
	function CommentManager(parent)
	{
		var self=this;
		this.init=function()
		{
			self.baseURL=parent.config.blog_base_url;
		}
		this.request=function(req)
		{
			var default_req=
			{
				courage:"true",
				locale:parent.config.locale,
				community:parent.config.blog_community,
				serviceFormat:"true",
				cacheBuster:Math.floor(Math.random()*1000000000)
			};
			var request=JQ.extend(true,{},default_req,req);
			request.callback="video_wall.demand_tunnel.response";
			self.load(request,req.callback);
		}
		this.load=function(data,callback)
		{
			var url=parent.config.blog_base_url+'?'+objToString(data);
			parent.demand_tunnel.add({	url:url,_callback:callback	});
		}
		this.load_thread=function(guid,callback)
		{
			self.request(
			{
				key:guid+'_'+parent.config.locale,
				callback:callback
			});
		}
		this.post_comment=function(comment,data,callback)
		{
			tracking.click({pageName:track_site+">media>video>comments>submit",prop18:"media",prop19:"video"});
			
			//clean comment data
			comment=escape(comment);
			
			if(	typeof data.threadID != 'undefined'	)
			{
				var params=
				{
					post:true,
					threadID:data.threadID,
					referrerURL:'',
					comment:comment
				};
			}
			else
			{
				var params=
				{
					post:true,
					key:data.key,
					communityID:data.communityID,
					referrerURL:'',
					title:parent.front_end.left_side.video_detail.container.find('div.title').html(),
					description:'description',
					comment:comment
				};
			}
			
			var req={};
			req.url=data.form_action;
			req.callback=callback;
			
			var data_string='';
			for(var p in params)
				data_string+=p+"="+params[p]+"&";
			req.data=data_string.substring(0,data_string.length-1);
			parent.f4a_tunnel.add(req);	
		}
		this.flagMessage=function(id, comment, callback)
		{
			var data=
			{
				referrerURL:escape(location.href),
				messageID:id,
				abuseType:0,//default to General Abuse
				comments:escape(comment)
			};
			var action=parent.config.blog_base_url.replace('/everywhere/780','')+"/ce-message-abuse.jspa";
			
			var data_str='';
			for(var p in data)
				data_str+=p+"="+data[p]+"&";
			var req={};
			req.url=action;
			req.data=data_str.substring(0,data_str.length-1);
			req.callback=callback;
			parent.f4a_tunnel.add(req);
		}
		self.init();
	}
	
	//tunnels:
	function AjaxTunnel()
	{
		var self=this;
		this.init=function()
		{
			self.requests=[];
			self.cached_requests={};
			self.request_running=false;
		}
		this.issue=function(request)
		{
			self.requests[self.requests.length]=request;
			if(!self.request_running)
			{
				self.request_running=true;
				self.run_requests();
			}
		}
		self.run_requests=function()
		{
			if(self.requests.length==0)
			{
				self.request_running=false;
				return;
			}
			if(!self.cached_requests[objToString(self.requests[0].d)])
			{
				JQ.get
				(
					self.requests[0].u, 
					JQ.extend(true,{},self.requests[0].d,{callback:false}),
					self.issue_done, "json"
				);
			}
			else
				self.issue_done(	self.cached_requests[objToString(self.requests[0].d)]	);
		}
		this.issue_done=function(data)
		{
			self.cached_requests[	objToString(self.requests[0].d)	]=data;
			self.requests[0].c(	data,self.requests[0]	);
			self.requests.shift();
		
			if(self.requests.length==0)
				self.request_running=false;
			else
				self.run_requests();
		}
		self.init();
	}	
	function DemandTunnel(parent)
	{
		var self=this;
		this.init=function()
		{		
			self.requests=[];
			self.isRunning=false;
		}
		this.add=function(obj)
		{
			self.requests[self.requests.length]=obj;
			if(!self.isRunning)
			{
				self.isRunning=true;
				self.run();
			}
		}
		this.run=function()
		{
			if(self.requests.length==0)
			{
				self.isRunning=false;
				return;
			}
			self.issue(self.requests[0]);
		}
		this.issue=function(obj)
		{
			var script=document.createElement('script');
			script.type = 'text/javascript';
			script.src = obj.url;
			document.body.appendChild(script);
		}
		this.response=function(data)
		{
			var url=self.requests[0].url;
			var callback=self.requests[0]._callback;
			self.requests.shift();
			self.run();
			
			//stringified output conversion:
			if(typeof data=='string')
				eval("var data="+data);
			callback(	cleanJson(data)	);
		}
		self.init();
	}
	function F4ATunnel(parent)
	{
		var self=this;
		this.init=function()
		{
			self.build_flash();
			self.requests=[];
			self.isRunning=false;	
		};
		this.build_flash=function()
		{
			var el_id='f4a_nike';
			var f4a_id='f4a_nike';
			self.f4a=new f4a_js_flash({'id':f4a_id,'swfname':'f4a.swf','swfuri':'/nikeos/global/swf/f4a/f4a.swf'});
			
			var e=document.createElement("div");
			e.id=el_id+'flashcontent';
			e.style.width='1px';
			e.style.height='1px';
			document.getElementsByTagName('body').item(0).appendChild(e);
			self.f4a.createSwfObject();
		}
		this.add=function(obj)
		{
			self.requests[self.requests.length]=obj;		
			if(!self.isRunning)
			{
				self.isRunning=true;
				self.run();
			}
		}
		this.run=function()
		{
			if(self.requests.length==0)
			{
				self.isRunning=false;
				return;
			}
			self.issue(self.requests[0]);
		}
		this.issue=function(obj)
		{			
			var default_req=
			{
				onready:self.response,
				meth:'POST',
				data:{}				
			}
			for(var p in obj)
			{
				if(p!='callback')
					default_req[p]=obj[p];
			}
			self.f4a.open(default_req);
		}
		this.response=function(data)
		{
			var callback=self.requests[0].callback;
			self.requests.shift();
			self.run();
			callback(	data	);
		}		
		self.init();
	}
	
	//utility functions:
	function objToString(obj)
	{
		var str="";
		for (var p in obj)
			if(typeof obj[p]!='object' && typeof obj[p]!='function')
				str+=p+"="+escape(obj[p])+"&";
		return str.substring(0,str.length-1);
	}
	function limit_string(text, maxlength)
	{
		if(text.length <= maxlength)
			return text;
		for(var i=maxlength;i>0;i--)
		{
			if(	text[i]==" "||text[i]=="#"||text[i]=="!"||text[i]=="\""||text[i]=="'"||text[i]==","||text[i]=="."||text[i]=="/"||text[i]==","||text[i]=="|")
			{
				if(text[i-1]==",")
					return text.substring(0,i-1)+"...";					
				else
					return text.substring(0,i)+"...";
			}
		}
		return text.substring(0,maxlength)+"...";
	}	//--gets param in query string. it its not in there, it pulls it from the hash.
	function getParam(x,location)
	{
		var url=window.location.href;
		if(location=='query_string')
			url=url.substring(0,url.indexOf('#'));
		else if(location=='hash')
			url=url.substring(url.indexOf('#'),url.length);
		x=x.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS="[\\?&]"+x+"=([^&#]*)";
		var regex=new RegExp(regexS);
		var results=regex.exec(url);
		if(results==null)
			return "";
		else
			return results[1];
	}
	//clears out dummy data from json responses:
	function cleanJson(obj)
	{
		var ret;
		if(obj.constructor==Array)
		{
			ret=[];
			for(var i=0;i<obj.length;i++)
			{
				if(obj[i]!=null && typeof obj[i]!='undefined')
				{
					if(typeof obj[p]=='object')
						ret[ret.length]=cleanJson(obj[i]);
					else
						ret[ret.length]=obj[i];
				}
			}
			return JQ.extend([],ret);
		}
		else
		{
			ret={};
			for(var p in obj)
			{
				if(p!='dummy' && obj[p]!=null)
				{
					if(typeof obj[p]=='object')
						ret[p]=cleanJson(obj[p]);
					else
						ret[p]=obj[p];	
				}
			}
			return JQ.extend({},ret);
		}
	}
	function date_str(date)
	{	
		var y=parseInt(date.substring(0,4),10);
		var m=parseInt(date.substring(5,7),10)-1;
		var d=parseInt(date.substring(8,10),10);
		var h=parseInt(date.substring(11,13),10);
		var mm=parseInt(date.substring(14,16),10);
		var s=parseInt(date.substring(17,19),10);
		
		var d=new Date(y,m,d,h,mm,s);
		var ed=d.getTime()/1000;
		
		var now=new Date();
		var now_epoch=now.getTime()/1000;
		
		var diff=Math.floor(now_epoch-ed);
		
		if(diff>31536000)
			return render_date_str(diff,31536000,"year");
		else if(diff>2592000)
			return render_date_str(diff,2592000,"month");
		else if(diff>86400)
			return render_date_str(diff,86400,"day");
		else if(diff>3600)
			return render_date_str(diff,3600,"hour");
		else
			return "1 second Ago";
	}
	function render_date_str(diff,time,label)
	{
		var x=Math.floor(diff/time);
		if(x==1)
			return x+" "+label+" ago";
		else
			return x+" "+label+"s ago";
	}
	
	function PopUp(master,id)
	{
		var self=this;
		this.init=function()
		{
			self.id='popup_'+id;
			JQ('body').append("<div id=\""+self.id+"\" class=\"jqmWindow\">asd</div>");
			self.dom=JQ('#'+self.id);
			self.dom.jqm(
			{
				onHide:self.hide
			});
			self.open=false;
			self.allow=false;
		}
		this.set=function(html)
		{
			self.dom.empty().append(html);
			return self;
		}
		this.show=function()
		{
			self.open=true;
			self.dom.jqmShow();
			return self;
		}
		this.allow_close=function()
		{
			self.allow=true;
			return self;
		}
		this.refuse_close=function()
		{
			self.allow=false;
			return self;
		}
		this.hide=function(popup)
		{
			if(self.allow)
			{
				self.dom.hide();
				JQ('.jqmOverlay').hide();
				self.open=false;
				self.allow=false;
				self.dom.jqmHide();
			}
			return self;
		}
		this.close=function()
		{
			self.allow_close();
			self.hide();
			self.refuse_close();
			return self;
		}
		this.status=function()
		{
			return self.open;
		}
		self.init();
	}

	function f(){}
	var video_wall;
	JQ(document).ready(function()
	{
		//start it up:
		video_wall=new VideoWall();
	});
	

//--MODAL
/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqmodal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * $Version: 07/06/2008 +r13
 */
(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery);
	
