var vid;
  $(document).ready(function() {
  
	 var moddbSpace = $('.LatestImages').width();
		var moddbCount =  Math.floor(moddbSpace / 255);
				$('.moddbImage').each(function(i) 
					{
					if (i>moddbCount-1)
						//{$(this).css("display","inline");}
						{$(this).addClass("ui-helper-hidden");}
					else
						//{$(this).css("display","");}
						{$(this).removeClass("ui-helper-hidden");}
					});
			
  
	 $.ajax({
            type: "GET",
            url: "http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&author=BluehellProductions&orderby=published&max-results=1",
			async: true,
            cache: false,
            dataType:'jsonp',
            success: function(data){
                var newest = (data.data.items[0]);
				var newid = newest.id;
				
				var min=(newest.duration/60)|0;
				var sec=(newest.duration%60);
				
				$('.latestVideo img').attr('src',newest.thumbnail.hqDefault);
				$('.latestVideo a').attr('href',"http://youtu.be/"+newest.id);
				$('.latestVideo span').html('<b><a href="http://youtu.be/'+newest.id+'">'+newest.title+'</a></b><span style="float:left;"><i>Length</i>: '+min+'m'+sec+'sec</span> <span style="float:right;"><i>Views</i>: '+newest.viewCount+'</span>');

				 },
			error: function(data)
			{
			$('.latestVideo').prepend("<p>Failed to load data from YouTube</p>"+"<p class='ui-helper-hidden'>Real error for those interested: "+data.statusText+data.responseText +"</p>");
			}
			});
			
	
	 
	 $.ajax({
            type: "GET",
            url: "http://www.bluehellproductions.com/moddbImages.php",
			async: true,
            cache: false,
            dataType:'html',
            success: function(data){
                $(".LatestImages").html(data);
				$('.moddbImage').each(function(i) 
					{
					if (i>moddbCount-1)
						//{$(this).css("display","inline");}
						{$(this).addClass("ui-helper-hidden");}
					else
						//{$(this).css("display","");}
						{$(this).removeClass("ui-helper-hidden");}
					});
				
				 },
			error: function(data)
			{
				$(".LatestImages").prepend("<p>Failed to load images from ModDB</p>"+"<p class='ui-helper-hidden'>Real error for those interested: "+data.statusText+data.responseText +"</p>");
			}
			});
	



				$("#buttons").buttonset();
				$('.classymenu').each(function(){
				var ref = $(this).attr('href');
					$(this).classyMenu({
						content: $(ref).html(),		
						maxHeight: 280,
						maxWidth: 160,
						width:160,
						showSpeed: 300,
						positionOpts: {directionH: 'left',detectH:'false'}
						});
				});
				$('#CurrentUsers').tabs();
				
			    $('.someNews').each(function(i) 
					{
					if (i>10)
						{$(this).addClass('ui-helper-hidden');}
					});
  });
  
  function goIRC(){
	$('#IRC').dialog({
					autoOpen: false,
					width: 600,
					modal:true
				});
	$('#IRC').dialog("open");}
	
	function goNews(type){
	if (type=="all")
		{
			$('.siteNews').removeClass('ui-helper-hidden');
			$('.forumNews').removeClass('ui-helper-hidden');
			$('.apbNews').removeClass('ui-helper-hidden');
		}
	else if (type=="lawnchair")
		{
			$('.siteNews').addClass('ui-helper-hidden');
			$('.forumNews').addClass('ui-helper-hidden');
			$('.apbNews').removeClass('ui-helper-hidden');
		}
	else if (type=="forum")
		{
			$('.siteNews').addClass('ui-helper-hidden');
			$('.forumNews').removeClass('ui-helper-hidden');
			$('.apbNews').addClass('ui-helper-hidden');
		}
	else if (type=="site")
		{
			$('.siteNews').removeClass('ui-helper-hidden');
			$('.forumNews').addClass('ui-helper-hidden');
			$('.apbNews').addClass('ui-helper-hidden');
		}
	
	$('.someNews').each(function(i) 
		{
		if (i>10)
			{$(this).addClass('ui-helper-hidden');}
		});
	}
	
  function goTS3x(){
	$('#TS3c').dialog({
					autoOpen: false,
					width: 600,
					modal:true
				});
	$('#TS3c').dialog("open");}
	
	function goTreasureRoom(){
	$('#TreasureRoom').dialog({
					autoOpen: false,
					width: 600,
					modal:true
				});
	$('#TreasureRoom').dialog("open");}
	
	function goTWT(){document.location.href =("http://twitter.com/BHPTeam");}
	function goTWT2(){
	$('#TWT').dialog({
					autoOpen: false,
					width: 600,
					modal:true
				});
	$('#TWT').dialog("open");}
	
	function goFB(){document.location.href =("http://www.facebook.com/apathbeyond");}
	function goRSS(){document.location.href =("http://www.bluehellproductions.com/forum/ssi.php?a=out&f=8&show=10&type=rss");}
	
	function goYT2(){document.location.href =("http://www.youtube.com/user/BluehellProductions");}
	function goYT(){
	$(""+vid+"").dialog({
					autoOpen: true,
					width: 660,
					beforeClose: function(){$(".thevid").remove();},
					modal:true,
					resizable:false
				});
	}
	function goForum(){document.location.href =("http://www.bluehellproductions.com/forum");}
	
	$(window).resize(function() {
		var moddbSpace = $('.LatestImages').width();
		var moddbCount =  Math.floor(moddbSpace / 255);
				$('.moddbImage').each(function(i) 
					
					{
					if (i>moddbCount-1)
						//{$(this).css("display","inline");}
						{$(this).addClass("ui-helper-hidden");}
					else
						//{$(this).css("display","");}
						{$(this).removeClass("ui-helper-hidden");}
					});
			});
