/*
function showMyVideos(data) {
  var feed = data.feed;
  var entries = feed.entry || [];
  var html = ['<ul>'];
  for (var i = 0; i < entries.length; i++) {
    var entry = entries[i];
    var title = entry.title.$t;
	//var id = entry.id.$t;
	var id = entry.link('src');
    html.push('<li>', title, '</li><li>', id, '</li>');

  }



html.push('</ul>');
  document.getElementById('videos').innerHTML = html.join('');
}

*/


function loadVideo(playerUrl, autoplay, title, description, author, listNum) {
  swfobject.embedSWF(
      playerUrl + '&rel=0&border=0&showinfo=0&autohide=1&fs=1&autoplay=' + 
      (autoplay?1:0), 'player', '700', '394', '9.0.0', false, 
      false, {allowfullscreen: 'true', wmode: 'opaque'});
	  //$(this).addClass('active');
	var title = unescape(title);
	
	var description = unescape(description);
	$("h2.title").html(title);
	$("p.description").html(description);
	$("p.author").html("<span style='font-weight:bold;'>Author: </span>"+author);

	if (listNum == 1) {
		
	$activeUrl = playerUrl;
	$urlSplit1 = $activeUrl.split('v/');
	$urlSplit1 = $urlSplit1[1];
	$urlSplit2 = $urlSplit1.split('?f');

	$vID = $urlSplit2[0];
	$vID = $vID.split("?version");
	$vID = $vID[0];
	
	$relFeed = "http://gdata.youtube.com/feeds/api/videos/"+$vID+"/related?v=2&&alt=json-in-script&callback=showMyVideos3";
	
	//$("#playerContainer").attr('rel', $relFeed);
	
	$.getScript($relFeed);
//$(".related_feed").attr('src', $relFeed);

	}
	else {
		
		}
	/*$activeUrl = $(".active").attr('rel');
	if ($activeUrl == null) {
		$activeUrl = playerUrl;
	} 
	*/
	
}


function showMyVideos2(data) {
  var feed = data.feed;
  var entries = feed.entry || [];
  var html = ['<ul class="videos">'];
  for (var i = 0; i < entries.length; i++) {
    var entry = entries[i];
    var title = entry.title.$t;

	if (entry.title.$t.length > 60) {
		var dots = "...";
	}
	else {
		var dots = "";
	}
    var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
    var playerUrl = entries[i].media$group.media$content[0].url;
	var description = entries[i].media$group.media$description['$t'];
	var author = entries[i].author[0].name.$t;


	var titleClean = title.toString();
	
	var titleClean = escape(title);
	
	var descriptionClean = description.toString();
	
	
	var descriptionClean = escape(description);
	var listNum = 1;
	
	//var descriptionClean = description.replace("'", "").replace("", "");
	
   //html.push('<li onclick="loadVideo(\'', playerUrl, '\', true, \'title\', \'description\')">',
   html.push('<li rel="\'',playerUrl,'\'" onclick="loadVideo(\'', playerUrl, '\', true, \'', titleClean, '\', \'', descriptionClean, '\', \'', author, '\', \'',listNum, '\')">',

              '<img src="', 
              thumbnailUrl, '" width="163" height="119"/>', '<br /><p class="litenxbrodtext">', title.substr(0, 60), '', dots, '</p></li>');
  }
  html.push('</ul><br style="clear: left;"/>');
  document.getElementById('videos2').innerHTML = html.join('');
  if (entries.length > 0) {
    loadVideo(entries[0].media$group.media$content[0].url, false, entries[0].title.$t, entries[0].media$group.media$description['$t'], entries[0].author[0].name.$t, 1);
  }
}

function showMyVideos3(data2) {
  var feed = data2.feed;
  var entries = feed.entry || [];
  var html = ['<ul class="videos2">'];
  var entryCount = null;
  for (var i = 0; i < entries.length; i++) {
	var entryCount = entryCount + 1;
	if (entryCount > 4) {
	}
	else {
    var entry = entries[i];
    var title = entry.title.$t.substr(0, 60);

	if (entry.title.$t.length > 60) {
		var dots = "...";
	}
	else {
		var dots = "";
	}
	
    var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
    var playerUrl = entries[i].media$group.media$content[0].url;
	var description = entries[i].media$group.media$description['$t'];
	var author = entries[i].author[0].name.$t;

	var titleClean = title.toString();
	var titleClean = escape(title);
	
	var descriptionClean = description.toString();
	var descriptionClean = escape(description);
	var listNum = 2;
	
	//var descriptionClean = description.replace("'", "").replace("", "");
	
   //html.push('<li onclick="loadVideo(\'', playerUrl, '\', true, \'title\', \'description\')">',
   html.push('<li onclick="loadVideo(\'', playerUrl, '\', true, \'', titleClean, '\', \'', descriptionClean, '\', \'', author, '\', \'',listNum, '\')">',

              '<img src="', 
              thumbnailUrl, '" width="163" height="119"/>', '<br /><p class="litenxbrodtext">', title, '', dots, '</p></li>');
  }
  }
  html.push('</ul><br style="clear: left;"/>');
  document.getElementById('videos3').innerHTML = html.join('');
  /*if (entries.length > 0) {
    loadVideo(entries[0].media$group.media$content[0].url, false, entries[0].title.$t, entries[0].media$group.media$description['$t']);
  }*/
}

function showPlaylists(data) { 

  var feed = data.feed;
  var entries = feed.entry || [];
  //var html = ['<ul class="playlists">'];
  $("#playlists").html('<ul class="hey"></ul>');
  for (var i = 0; i < entries.length; i++) {
    var entry = entries[i];
    var title = entry.title.$t;
	var playerUrl = entry.content.src;
	//$("#playlists ul.hey").html('<li>'+title+'</li>');
	//alert(playerUrl);
/*
	if (entry.title.$t.length > 60) {
		var dots = "...";
	}
	else {
		var dots = "";
	}
    var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
    var playerUrl = entries[i].media$group.media$content[0].url;
	var description = entries[i].media$group.media$description['$t'];
	var author = entries[i].author[0].name.$t;


	var titleClean = title.toString();
	
	var titleClean = escape(title);
	
	var descriptionClean = description.toString();
	
	
	var descriptionClean = escape(description);
	var listNum = 1;
	
	//var descriptionClean = description.replace("'", "").replace("", "");
	
   //html.push('<li onclick="loadVideo(\'', playerUrl, '\', true, \'title\', \'description\')">',
   
   html.push('<li rel="\'',playerUrl,'\'" onclick="loadVideo(\'', playerUrl, '\', true, \'', title, '\', \'', descriptionClean, '\', \'', author, '\', \'',listNum, '\')">',

              '<img src="', 
              thumbnailUrl, '" width="163" height="119"/>', '<br /><p class="litenxbrodtext">', title.substr(0, 60), '', dots, '</p></li>');
 */
  }
  /*
  html.push('</ul><br style="clear: left;"/>');
  document.getElementById('playlists').innerHTML = html.join('');
  
  if (entries.length > 0) {
    loadVideo(entries[0].media$group.media$content[0].url, false, entries[0].title.$t, entries[0].media$group.media$description['$t'], entries[0].author[0].name.$t, 1);
  }
*/
};



$(document).ready(function() {
	
	
	
	function thNext() {
		$(".thprev").fadeIn();
	$this = $('ul.videos').find('.stop:visible');
	$this.nextUntil('li:nth-child(6n)').show();
	$this.nextUntil('li:nth-child(6n)').next('li').show();
	$this.prevUntil().hide();
	$this.hide();

};

function thPrev() {
	$first = $('ul.videos').find('.first:visible');
	$this = $('ul.videos').find('.stop:visible');
	if ($this.length == 0) {
	$lastStop = $('ul.videos').find('.stop:last');
	$lastStop.show();		
	$lastStop.prevUntil('.stop').show();
	$lastStop.nextUntil().hide();
	}
	else if ($first.length == 1) {
	}
	else {
	//$this.prev('.stop:hidden').show();
	$prev6 = $this.prevUntil('.stop').prev('li');
	$prev6.show();
	$prev6.prevUntil('.stop').show();
	$this.prevUntil('.stop').hide();
	$this.hide();
	$first = $('ul.videos').find('.first:visible');
	if ($first.length == 1) {
		$(".thprev").fadeOut();
	}
	}

};

	
	$('.videos li:first').addClass('active');
	$('.videos li:first').addClass('first');
	$('.videos li:last').addClass('last');
	
	$('.videos li').click(function() {
		$('.videos li').removeClass('active');
		$(this).addClass('active');
		//updateNext();
	});
	$('.next1').click(function() {
		$this = $('.active');
		if ($this.hasClass('last')) {
		}
		else {
		$this.next('li').addClass('active');
		$this.removeClass('active');
		$nextVid = $this.next('li').attr('onclick');
		//alert($nextClick);
		$nextVid = $nextVid.toString();
		$nextVidSub = $nextVid.split('{');
		$nextVid = $nextVidSub[1];
		$nextVidSub2 = $nextVid.split('}');
		$nextVid = $nextVidSub2[0];
		$nextVid = jQuery.trim($nextVid);
		eval($nextVid);
		if ($('.active').is(':visible')) {
		}
		else {
			thNext();
		}
		}
	});
	
		$('.prev1').click(function() {
		$this = $('.active');
		if ($this.hasClass('first')) {
		}
		else {
		$activeIndex = $('li').index($this);

		if ($activeIndex != 0) {
		$this.prev('li').addClass('active');
		$this.removeClass('active');
		
		
		
		
		$prevVid = $this.prev('li').attr('onclick');
		$prevVid = $prevVid.toString();
		$prevVidSub = $prevVid.split('{');
		$prevVid = $prevVidSub[1];
		$prevVidSub2 = $prevVid.split('}');
		$prevVid = $prevVidSub2[0];
		$prevVid = jQuery.trim($prevVid);
		eval($prevVid);
		
				if ($('.active').is(':visible')) {
		}
		else {
			thPrev();
		}

		
		}
		}
		
	});

$("#navhover").bind({
	mouseenter: function() {
	
  $("#nav").show();
  $("#nav").bind({
	mouseover: function() {
	
  $("#nav").show();
	}
});
  		
},
mouseout: function() {
  $("#nav").hide();
}});


//Thumbs scroll

/*

$('ul.videos li:first').addClass('first');
$('ul.videos li:nth-child(6n)').addClass('stop');
$('ul.videos').find('.stop').nextUntil().hide();



$('.thnext').bind('click', function() {
	thNext();
});


$('.thprev').bind('click', function() {
	thPrev();
});

*/


	
});	  


function updateNext() {
	
	$nextVid = $(".active").next("li").attr('onclick');
	$nextVid = $nextVid.toString();
	$nextVidSub = $nextVid.split('{');
	$nextVid = $nextVidSub[1];
	$nextVidSub2 = $nextVid.split('}');
	$nextVid = $nextVidSub2[0];
	$(".next1").attr('onclick', $nextVid);

};




/*
function showMyVideos3(data) {
  var feed = data.feed;
  var entries = feed.entry || [];
  var html = ['<ul class="videos">'];
  for (var i = 0; i < entries.length; i++) {
    var entry = entries[i];
    var title = entry.author.$t.substr(0, 100);
    var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
    var playerUrl = entries[i].media$group.media$content[0].url;
    html.push('<li onclick="loadVideo(\'', playerUrl, '\', true)">',
              '<img src="', 
              thumbnailUrl, '" width="168" height="124"/>', '<br /><p class="litenxbrodtext">', title, '</p></li>');
  }
  html.push('</ul><br style="clear: left;"/>');
  document.getElementById('videos3').innerHTML = html.join('');
  if (entries.length > 0) {
    loadVideo(entries[0].media$group.media$content[0].url, false);
  }
  FB.Canvas.setSize();
}*/
