/**
 * @author bookerm
 */
      jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);  
      };
		
		

		/*VIDEO DURATION FOR YOUTUBE IS RETURNE DIN SECONDS>>> 
		 * 
		 THIS FORMATS THE SECONDS TO  H:M:S*/
		var vDuration = "";
		function format_duration(fsecs) {
			vDuration = "";
			var num = fsecs;
			var hours = 0;
			var mins = 0;
			var secs = 0;
			while (num > 0) {
			  if (num < 60) {
			    secs += num;
			    num = 0;
			  }
			  else if (num < 3600) {
			    mins++;
			    num -= 60;
			  }
			  else if (num < 86400) {
			    hours++;
			    num -= 3600;
			  }
			}
			
			if (hours > 0){vDuration += hours+":";}
			if (mins > 0) {vDuration += mins+":";}else{vDuration +="0:";}
			if (secs > 0) {vDuration += secs;}
			
		}
		/*close rss*/
		function rrss(){
			$('#tagrssL').removeClass('current');
			$('#tagrssW').animate({height:"27px"},100);
			$('#tagrssL').css({ backgroundImage : "url(images/vert/img_tag_vert_acc_off_nxt-bottom.png)" }).animate({height:"27px"},100);
			$('#tagrssW').find('.accHdrCopy').show();
			$('#rsss').fadeOut('slow');
		}
		/*close youtube*/
		function ry(){
			$('#youtubeL').removeClass('current');
			$('#youtubeW').animate({height:"27px"},100);
			$('#youtubeL').css({ backgroundImage : "url(images/vert/img_tag_vert_acc_off_nxt-bottom.png)" }).animate({height:"27px"},100);
			$('#youtubeW').find('.accHdrCopy').show();
			$('#videos').fadeOut('slow');
		}
		/*close flickr*/
		function rf(){
			$('#flickrL').removeClass('current');
			$('#flickrW').animate({height:"27px"},100);
			$('#flickrL').css({ backgroundImage : "url(images/vert/img_tag_vert_acc_off_nxt-bottom.png)" }).animate({height:"27px"},100);
			$('#flickrW').find('.accHdrCopy').show();
			$('#flickpics').fadeOut('slow');
		}
		/*build you tube video list from JSON feed*/	
		function showMyVideos(data) {
		  var feed = data.feed;
		  var entries = feed.entry || [];
		  var html = [''];
		  for (var i = 0; i < entries.length; i++) {
		    var entry = entries[i];
		    
		    if (entry.title.$t.length >=25){
		    var title = entry.title.$t.substr(0, 25);
		    }else{var title = entry.title.$t;}
		    
		    if(entry.media$group.media$description.$t.length >= 61){
				var desc = entry.media$group.media$description.$t.substr(0, 60);
			}else{var desc = entry.media$group.media$description.$t;}
			
		    var thumbnailUrl = entries[i].media$group.media$thumbnail[0].url;
		    var type = 'application/x-shockwave-flash';
		    for (var j = 0, content; content = entry.media$group.media$content[j]; j++) {
			   if (content.type == type) {
			     var curl = content.url;
			     var dura = content.duration;
			     format_duration(dura);
			   }
			}
		    html.push(
		              '<div class="vWrap">',
						  '<div class="vthumb"><a href="',curl,'"><img src="', thumbnailUrl, '" width="60" height="37"/></a></div>',
						  '<div class="vlength">',vDuration,'</div>',
						  '<div class="vcont">',
							  '<span class="vtitle">',title,'...</span><br />',
							  '<span class="cDesc">',desc,'...</span>',
						  '</div>',	
					  '</div>');
		  
		    
		  document.getElementById('videos').innerHTML = html.join('');
		}
		}
		function doCarmelTwit(){$("#tweets").tweet({
				  join_text: "auto",
				  username: "TAGRecords",
				  avatar_size: 10,
				  count: 1,
				  auto_join_text_default: "TAG said,",
				  auto_join_text_ed: "TAG",
				  auto_join_text_ing: "TAG was",
				  auto_join_text_reply: "TAG replied",
				  auto_join_text_url: "TAG was checking out",
				  loading_text: "Follow us @TAGRecords"
				});}
			function doLudaTwit(){$("#tweets").tweet({
				  join_text: "auto",
				  username: "TAGRecords",
				  avatar_size: 10,
				  count: 1,
				  auto_join_text_default: "TAG said,",
				  auto_join_text_ed: "TAG",
				  auto_join_text_ing: "TAG was",
				  auto_join_text_reply: "TAG replied",
				  auto_join_text_url: "TAG was checking out",
				  loading_text: "Follow us @TAGRecords"
				});}
			
			function doRobTwit(){$("#tweets").tweet({
				  join_text: "auto",
				  username: "robdyrdek",
				  avatar_size: 10,
				  count: 1,
				  auto_join_text_default: "Rob said,",
				  auto_join_text_ed: "Rob",
				  auto_join_text_ing: "Rob was",
				  auto_join_text_reply: "Rob replied",
				  auto_join_text_url: "Rob was checking out",
				  loading_text: "Follow us @TAGRecords"
				});}
		$(document).ready(function() {
			/*$("#tweets").tweet({
				  join_text: "auto",
				  username: "Melo_15",
				  avatar_size: 24,
				  count: 1,
				  auto_join_text_default: "Melo said,",
				  auto_join_text_ed: "Melo",
				  auto_join_text_ing: "Melo was",
				  auto_join_text_reply: "Melo replied",
				  auto_join_text_url: "Melo was checking out",
				  loading_text: "Follow us @TAGRecords"
				});*/
			
	
			/*FORMAT FLICKR FEED FROM JSP*/
		
			var flickPicSize = $('#flickpics .flickPic').size();
			
			/*remove posted by test from flickr rss*/
			for(var u = 0; u < flickPicSize; u++)
			{
				$('.flickPic:eq('+u+') p:first').hide();
				var fstring = $('.flickPic:eq('+u+') p:last').html();
				fstring = fstring.substr(0,90);
				fstring = fstring+" ...more.";
				$('.flickPic:eq('+u+') p:last').html(fstring);
				$('.flickPic:eq('+u+') p:last').css("width","160px");
				$('.flickPic:eq('+u+') p:last').css("left","39px");
				if (u != 0) {
					$('.flickPic:eq(' + u + ')').css("top", "15px");
				}
			}	
			
			/*handle click for menu's and menu open close*/
			$('div#accordion a.heading').click(function() {
			
					var calledDiv = $(this).parent().attr("id");
					var calledItem = $(this).siblings('div').attr("id");
		
					/*close already open item*/
					if($(this).hasClass('current')){
						$(this).removeClass('current');
						$(this).parent().animate({height:"27px"},100);
						$(this).css({ backgroundImage : "url(images/vert/img_tag_vert_acc_off_nxt-bottom.png)" }).animate({height:"27px"},100);
						$(this).parent().find('.accHdrCopy').show();
						$(this).siblings('#'+calledItem).fadeOut(500);
					}else{
					/*Open Item*/
					$(this).parent().animate({height:"153px"},100);
					$(this).css({ backgroundImage : "url(images/vert/img_tag_vert_acc_open.png)" }).animate({height:"153px"},500);
					$(this).parent().find('.accHdrCopy').hide();
					$(this).siblings('#'+calledItem).fadeIn(500);
					$(this).addClass('current');
					
					/*close all other open*/
					switch(calledDiv)
					{
					case 'youtubeW':
						rrss();
						rf();
					  break;
					case 'tagrssW':
						rf();
						ry();
					  break;
					case 'flickrW':
						rrss();
						ry();
						break;
					default:
					  return;
					}
					
					}
					return false; 
			});});
