// JavaScript Document


function GetVideoList(cat_id) 
	{

		var videolist_result = "";

			 $.post('/includes/api/video_server.php', 
							{
								request:"get_video_list",
								category:cat_id
							},
			
		
		function(res)
		{
			//alert(res);
			var videolist = $.json.deserialize(res); 
			//alert(videolist["response"]);
			var videolist_result = "";
			for(key in videolist)
				{
					
				//	alert(videolist[key].short_desc);
					if (videolist["response"] == 'no') {
						
					videolist_result += 'There are no videos';	
					}
					else {
					//alert(videolist[key].permissions);
					/* <div class="sec_video_box">
        <div style="height: 70px; padding-top: 9px;"><a href="#" ><img src="http://i2.cdn.turner.com/cnn/video/showbiz/2010/02/19/anderson.the.buzz.friday.cnn.124x70.jpg" alt="" border="0" width="125" height="70"></a></div>
        <div style="padding: 0px; height: 50px;" class="vid_play"><div style="margin: 0px; height: 36px; word-spacing: 0px;"><a href="#" >Buzz: Stars on probation</a><span class="vid_duration"> 1:37</span></div>
        </div> */
		permissions = videolist[key].permissions; 
			//alert(permissions.toString());
			var permission_icons = "";
			//alert(permissions.length);
			permissions = permissions.split(",");
			//alert(permissions);
			for(var i = 0; i < permissions.length; i++)
				{
					//alert(permissions[i]); 
				if (permissions[i] == 2){ permission_icons += "<img src=\"http://site-cdn.stirthewater.com/images/imd_16.gif\" alt=\"Dream Interpreter Subscription Required\" title=\"Dream Interpreter Subscription Required\" border=\"0\" width=\"16\" height=\"16\">"; }
							if (permissions[i] == 3){ permission_icons += "<img src=\"http://site-cdn.stirthewater.com/images/swirl_16.gif\" alt=\"Prophetic &amp; Seer Exercise Subscription Required\" title=\"Prophetic &amp; Seer Exercise Subscription Required\" border=\"0\" width=\"16\" height=\"16\">"; }
								//if (permissions[key] == 4){ permission_icons += "selected=selected"; }
					
				}
				//alert(permission_icons);
					videolist_result += '\n<div class="sec_video_box">';
					
					//var videolist_result = "";
					videolist_result += ' <div class="vid_img"><a href="/videos/' + videolist[key].slug + '" ><img src="' + videolist[key].img_thumb + '" alt="" border="0" width="145" style="max-height:80px;" ></a></div>';
					videolist_result += '<div class="vid_play"><a href="/videos/' + videolist[key].slug + '" >' + videolist[key].vid_name + '</a><br><span class="vid_duration">Recorded: '+ videolist[key].date_recorded +'</span></div>\n\n';
					videolist_result += '<div class="permission_icons"><span class="permission_icons">' + permission_icons + '</span></div></div>\n\n';
					
							
					} 
					
				}
			//alert(videolist[key].parent_id);
			
			if (videolist[key].parent_id){
				
				var parent_cat = videolist[key].parent_id;
				
				}
		else { parent_cat = cat_id;      }
			
			//alert(parent_cat);
			
			 var videolisting = "#vid-list-"+parent_cat;
			// alert(videolisting);
				$(videolisting).empty();
				
				
				$(videolisting).append(videolist_result);
				$('#tbody-videolist tr:odd').css("background-color", "#e1e7f3");
				$('#tbody-videolist tr:even').css("background-color", "#f3f6fa");
			
		});
	}
	
	
	function switch_category(category_id) {
		
		var divid = 'cat-';
			divid += category_id;
		
	
		
		$(".cnnSec_Cell_active").switchClass('cnnSec_Cell_active', 'cnnSec_Cell', 0);
		
		$("#"+divid).switchClass('cnnSec_Cell', 'cnnSec_Cell_active', 0);
		
		GetVideoList(category_id); 
		
	}
	
