﻿
function loadTabContent(clickedTab,clickType)
{
    var divToUpdate="videoDiv";
    var loadingDivToUpdate="";
    if(clickType=="videos")
    {
        divToUpdate="videosProfileDiv";
        loadingDivToUpdate="loadingDivVideos";
        $("#videosProfileLatest_Tab").removeClass("active");
        $("#videosProfileMostViewed_Tab").removeClass("active");
        $("#videosProfileFriends_Tab").removeClass("active");
        document.getElementById(loadingDivToUpdate).style.display="block";
    }
    else if(clickType=="blogs")
    {
        divToUpdate="blogsProfileDiv";
         loadingDivToUpdate="loadingDivBlogs";
        $("#blogsProfileLatest_Tab").removeClass("active");
        $("#blogsProfilePopular_Tab").removeClass("active");
        $("#blogsProfileFriend_Tab").removeClass("active");
        document.getElementById(loadingDivToUpdate).style.display="block";
    }
    else if(clickType=="albums")
    {
     divToUpdate="albumsProfileDiv";
     loadingDivToUpdate="loadingDivAlbums";
     $("#albumsProfileLatest_Tab").removeClass("active");
     $("#albumsProfileMostViewed_Tab").removeClass("active");
     document.getElementById(loadingDivToUpdate).style.display="block";
    
    }
    
    var feedUrl="/ajax/content.aspx";
    var tabID=clickedTab.id;
    var index = tabID.indexOf("_");
    contentType = tabID.substring(0,index);
    
    //set active tabs
    clickedTab.className = "active";
    clickedTab.setAttribute("class","active");
    var username=document.getElementById("hdnUsername").value;
   
    
	$.ajax({
	   type: "POST",
	   url: feedUrl,
	   data: "feedType="+contentType+"&username="+username,
	   success: function(msg)
	   {

	        document.getElementById(loadingDivToUpdate).style.display="none";
	        
	        var videoDiv=document.getElementById(divToUpdate);
	        var bigDescription="<ul>";
	     
	        var item_message_nodes = msg.getElementsByTagName("item");
	        message_nodes=item_message_nodes[0].getElementsByTagName("description");
	     
            var n_messages = item_message_nodes.length;
            var message_nodes="";
          
	        for (i = 0;i < n_messages;i++)
	        {
	            message_nodes=item_message_nodes[i].getElementsByTagName("description");
	             for(j = 0;j < message_nodes[0].childNodes.length;j++)
	             {
                description = message_nodes[0].childNodes[j].nodeValue;
                description = description.replace(/&lt;/g, '<').replace(/&gt;/g, ">").replace(/&amp;/g, "&");
                bigDescription+=description; 
                }    
            }
            
	       bigDescription+="</ul>";
	       videoDiv.innerHTML=bigDescription;
	   } 
	 });
}

$(document).ready(function() {

	    $('a.comment_video').bind('click', toggleContentVideo);
        $('a.comment_image').bind('click', toggleContentImage);
		
		if (loggedInUser == document.getElementById("hdnUsername").value)
		{
		    $('div.movable1').Sortable(
			    {
				    accept: 'containerb',
				    helperclass: 'sortHelper',
				    handle: 'div.alpha',
				    tolerance: 'intersect',
			        axis: 'vertically',
				    revert: true,
				    onChange : function(ser)
				    {
				    },
				    onStart : function()
				    {
					    $.iAutoscroller.start(this, document.getElementsByTagName('body'));
				    },
				    onStop : function()
				    {
					    $.iAutoscroller.stop();
					    serialize(['colm2', 'colm3']); return false;
				    }
			    }
		    );
    		
		    $('div.movable2').Sortable(
			    {
				    accept: 'containerc',
				    helperclass: 'sortHelper',
				    handle: 'div.alpha',
				    tolerance: 'intersect',
			        axis: 'vertically',
				    revert: true,
				    onChange : function(ser)
				    {
				    },
				    onStart : function()
				    {
					    $.iAutoscroller.start(this, document.getElementsByTagName('body'));
				    },
				    onStop : function()
				    {
					    $.iAutoscroller.stop();
					    serialize(['colm2', 'colm3']); return false;
				    }
			    }
		    );
		}
	}
);

function serialize(s)
{
	serial = $.SortSerialize(s);
 	$.ajax({
	   type: "POST",
	   url: "/ajax/userHandler.ashx?type=sortprofile",
	   data: (serial.hash),
	   success: function(msg){
		 //alert( "Data Saved: " + msg );
	   }
	 });


};
var toggleContentVideo = function(e)
{
	var targetContent = $('div.comment_video_popup');
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
		$(this).html('Hide Video Attach');
	} else {
		targetContent.slideUp(300);
		$(this).html('Attach Video');
		$('div.comment_video_form textarea').attr("value","");
	}
	return false;
};

var toggleContentImage = function(e)
{
	var targetContent = $('div.comment_image_popup');
	if (targetContent.css('display') == 'none') {
		targetContent.slideDown(300);
		$(this).html('Hide Image Attach');
	} else {
		targetContent.slideUp(300);
		$(this).html('Attach Image');
		$('div.comment_image_form input').attr("value","");
	}
	return false;
};

