	var user = '';
	var ajax = new Array();
	var clip_id = '';
	var cat_film = '';
	var cur_page_comments = 1;
	var comments_nr;
	var comments_pages_nr;
	var x = new Array();
	var comment = new Array();
	var nr_comments;
	var ajaxResponse = new Array();
	var ajax_total = 0;

	function adaugaVot(id_film, vot)
	{   
		if (user !== '0')
		{
			 var index = ajax.length;
			 ajax[index] = new sack();
			 ajax[index].requestFile = 'detalii_video_.php?vid='+id_film+'&action=ajaxAddVote&nota='+vot;	// Specifying which file to get
			 ajax[index].onCompletion = function()
			 { 	
			 	  document.getElementById('current_rating').style.width = (vot*20)+'%';
				  document.getElementById('vot_i').style.visibility = 'hidden';
				  document.getElementById('vot_i').style.display = 'none';
				  document.getElementById('vot_d').style.visibility = 'visible';
				  document.getElementById('vot_d').style.display = 'block';
				  document.getElementById("acorda_vot_img_append").setAttribute("src","img/video_details/allready_voted.jpg");
				  eval(ajax[index].response);
					  
			 };	// Specify function that will be executed after file has been found
			 ajax[index].runAJAX();		// Execute AJAX function
		}
	  
	}
	
	function adaugaVotImagine(id_film, cat_film, vot)
	{   
		if (user !== '0')
		{
			 var index = ajax.length;
			 ajax[index] = new sack();
			 ajax[index].requestFile = 'adauga_vot.php?clip='+id_film+'&nota='+vot;	// Specifying which file to get
			 ajax[index].onCompletion = function()
			 { 	
			 	  document.getElementById('current_rating').style.width = (vot*20)+'%';
				  document.getElementById('vot_i').style.visibility = 'hidden';
				  document.getElementById('vot_i').style.display = 'none';
				  document.getElementById('vot_d').style.visibility = 'visible';
				  document.getElementById('vot_d').style.display = 'block';
				  
				  eval(ajax[index].response);
					  
			 };	// Specify function that will be executed after file has been found
			 ajax[index].runAJAX();		// Execute AJAX function
		}
	  
	}
	
	function hideElement(obj)
	{
		document.getElementById(obj).style.display = 'none';
	}
	
	function showElement(obj)
	{
		document.getElementById(obj).style.display = 'block';
	}
	
	function loadComments()
	{
		
		hideElement('addResponse');
		hideElement('userVideosLoading');
		hideElement('responses');
		showElement('commentsMain');
		ajaxGetContentTotal('ajaxCommentsTotal', function () { initPagination("commentButtonFunc"); });
		getComments(1);
		showElement('pagination');
		
	}
	
	function loadVideoResponses()
	{
		hideElement('userVideosLoading');
		hideElement('commentsMain');
		hideElement('addResponse');
		hideElement('pagination');
		showElement('responses');
		
	}
	
	function loadUserVideos()
	{
		
		hideElement('similarVideos');
		showElement('userVideos');
		
	}
	
	function loadSimilarVideos()
	{
		
		hideElement('userVideos');
		showElement('similarVideos');
		
	}
	
	function toggleClaim()
	{
		obj = document.getElementById('claim');
		
		if (obj.style.display == "none")
		{
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	}
	
	function showEmbed()
	{
		
		hideElement('permLink');
		showElement('embed');
		
	}
	
	function showPermanentLink()
	{
		
		hideElement('embed');
		showElement('permLink');
		
	}
	
	function showAddResponse(auth)
	{
		hideElement('commentsLoading');
		hideElement('responses');
		hideElement('comments');
		showElement('addResponse');
		if (auth)
		{
			ajaxGetContentTotal('ajaxViewerVideosTotal', function () { initPagination("respButtonFunc"); });
			getUserResponses(1);
			showElement('pagination');
		}
	}
	
	function ajaxGetContent(action, page, prefix, execAfter)
    {
		ajaxResponse = new Array();
		ajax_total = 0;
		
    	var index = ajax.length;
    	ajax[index] = new sack();
    	ajax[index].requestFile = 'detalii_video_.php?vid='+clip_id+'&action='+action+'&pag='+page;	// Specifying which file to get
    	ajax[index].onCompletion = function()
    	{ 
			eval(ajax[index].response);
			if (typeof execAfter != 'string') 
				execAfter();
			else
				eval(execAfter);
        };	// Specify function that will be executed after file has been found
		
        ajax[index].runAJAX();		// Execute AJAX function
    }
	
	function ajaxGetContentTotal(action, execAfter)
	{
		ajaxResponse = new Array();
		ajax_total = 0;
		
    	var index = ajax.length;
    	ajax[index] = new sack();
    	ajax[index].requestFile = 'detalii_video_.php?vid='+clip_id+'&action='+action;	// Specifying which file to get
		
    	ajax[index].onCompletion = function()
    	{ 
			eval(ajax[index].response);
			
			if (typeof(execAfter) != 'string') 
			{
				execAfter();
			} else {
				eval(execAfter);
			}
			
        };	// Specify function that will be executed after file has been found
		
        ajax[index].runAJAX();		// Execute AJAX function
	}
	
	function _matchClassToChild(obj, className)
	{
		
		if (obj.hasChildNodes() == true)
		{
			for (var j = 0; j < obj.childNodes.length; j++)
			{
				if (obj.childNodes[j].className == className)
				{
					eval("obj.childNodes["+j+"]." + attribs[i] + " = ajaxResponse["+z+"]['"+vals[i]+"'];");
					return true;
				} else {
					if (obj.childNodes[j].hasChildNodes())
					{
						_matchClassToChild(obj.childNodes[j], className);
					}
				}
			}
		}		
	}
	
	function ajaxContentParse(prefix)
	{		
		for (z = 0; z < ajax_per_page; z++)
		{
			holderObj = document.getElementById(prefix + 'holder-' + z);
			if (z < ajaxResponse.length)
			{
				for (i = 0; i < tags_cls.length; i++)
				{
					if (holderObj !== null)
					{
						_matchClassToChild(holderObj, tags_cls[i]);
					}
				}
				holderObj.style.display = 'block';
			} else {
				holderObj.style.display = 'none';
			}
		}
	}
	
	function ajaxUserVideosTemplate() 
	{
		tags_cls = new Array('thumbbrdr', 'clip-link', 'clip-link', 'user-link', 'current-rating');
		attribs = new Array('src', 'href', 'innerHTML', 'innerHTML', 'style.width');
		vals = new Array('thumbflv', 'link', 'titlu', 'views', 'rating');
	}
	
	
	function getUserVideos(page)
	{
		if (clip_id != 0)
		{
			hideElement('userVideos');
			showElement('userVideosLoading');
			ajaxUserVideosTemplate();
			ajax_per_page = 9;
			ajaxGetContent('ajaxUserVideos', page, 'usr-', function () 
														{ 
														  if (ajax_total > 0) 
														  		ajaxContentParse('usr-');
														  
														  hideElement('userVideosLoading');
														  showElement('userVideos'); 
														});
		}
	}
	
	function ajaxSimilarVideosTemplate() 
	{
		tags_cls = new Array('thumbbrdr', 'clip-link', 'clip-link', 'user-link', 'user-link', 'current-rating');
		attribs = new Array('src', 'href', 'innerHTML', 'href', 'innerHTML', 'style.width');
		vals = new Array('thumbflv', 'link', 'titlu', 'user_link', 'username', 'rating');
	}
	
	function getSimilarVideos(page)
	{
		if (clip_id != 0)
		{
			trigger = document.getElementById('similarVideoNext');
			hideElement('similarVideos');
			showElement('similarLoading');
			ajaxSimilarVideosTemplate();
			ajax_per_page = 10;
			ajaxGetContent('ajaxSimilarVideos', page, 'sim-', function () 
														{ 
														  if (ajax_total > 0) 
														  		ajaxContentParse('sim-');
														  
														  hideElement('similarLoading');
														  showElement('similarVideos'); 
														  if (ajax_total > ((page+1)*10)) {
														  		trigger.innerHTML = 'Vezi urmatoarele 10!'; trigger.onclick = function () { getSimilarVideos(page+1); };
														  } else { 
														  		trigger.innerHTML = 'Vezi precedentele 10!'; trigger.onclick = function () { getSimilarVideos(page-1); };
														  }
														});
		}
	}
	
	function ajaxCommentsTemplate() 
	{
		tags_cls = new Array('com-user-img', 'com-user-link', 'com-user-link', 'video_comment_text2', 'video_comment_text3');
		attribs = new Array('src', 'href', 'innerHTML', 'innerHTML', 'innerHTML');
		vals = new Array('pic', 'link', 'user_name', 'data', 'comment_txt');
	}
	
	function getComments(page)
	{
		if (clip_id != 0)
		{
			hideElement('comments');
			showElement('commentsLoading');
			ajaxCommentsTemplate();
			ajax_per_page = 10;
			ajaxGetContent('ajaxComments', page, 'com-', function () 
														{ 
														  if (ajax_total > 0) 
														  		ajaxContentParse('com-');
														  
														  initPagination("commentButtonFunc");
														  hideElement('commentsLoading');
														  showElement('comments'); 
														});
		}
	}
	
	function commentButtonFunc(j) 
	{
		ajax_total = 0;
		ajax_per_page = 10;
		ajaxGetContentTotal('ajaxCommentsTotal', function () { initPagination("commentButtonFunc"); });
		getComments(j);
		cur_page_comments = j;
	}
	
	function ajaxUserResponsesTemplate() 
	{
		tags_cls = new Array('resp-user-img', 'resp-user-vlink', 'durata clockDiv', 'video_text1');
		attribs = new Array('src', 'href', 'innerHTML', 'innerHTML');
		vals = new Array('thumbflv', 'link', 'durata', 'titlu');
	}
	
	function getUserResponses(page)
	{
		if (clip_id != 0)
		{
			hideElement('addResponse');
			showElement('userResponsesLoading');
			ajaxUserResponsesTemplate();
			ajax_per_page = 9;
			ajaxGetContent('ajaxViewerVideos', page, 'resp-user-', function () 
														{ 
														  if (ajax_total > 0) {
														  		ajaxContentParse('resp-user-');
																initPagination("respButtonFunc");
														  		hideElement('userResponsesLoading');
														  		showElement('addResponse'); 
														  } else {
															  	hideElement('userResponsesLoading');
																showElement('addResponse');
																showElement('viewerNoVideos');  
														  }
														  
														});
		}
	}
	
	function respButtonFunc(j) 
	{
		
		ajax_total = 0;
		ajax_per_page = 9;
		ajaxGetContentTotal('ajaxViewerVideosTotal', function () { initPagination("respButtonFunc"); });
		getUserResponses(j);
		cur_page_comments = j;
	}
	
	function initPagination(butFunc)  // target is comments by default
    {
		comments_pages_nr = Math.floor(ajax_total/ajax_per_page);
		if (Math.floor(ajax_total/ajax_per_page) != ajax_total/ajax_per_page) { comments_pages_nr++; }
		
		if (comments_pages_nr > 6)
		{
			if (cur_page_comments <= 3)
			{
				for (i=1; i<=6; i++)
				{
					obj = document.getElementById('pg_pos'+i);		
					obj.innerHTML = i;
					if (i==cur_page_comments) 
					{
						obj.style.textDecoration = 'underline';
						obj.style.color = '#FF0000';
					} else {
						obj.style.textDecoration = 'none';
						obj.style.color = '#000000';
					}
					obj.style.cursor = 'pointer';
					obj.onclick = new Function(butFunc+"("+i+")");
				}
			}
			if (cur_page_comments > 3 && cur_page_comments < (comments_pages_nr-2))
			{
				j = 1;
				for (i=(cur_page_comments-2); i<=(cur_page_comments+3); i++)
				{
					obj = document.getElementById('pg_pos'+j);		
					obj.innerHTML = i;
					if (i==cur_page_comments) 
					{
						obj.style.textDecoration = 'underline';
						obj.style.color = '#FF0000';
					} else {
						obj.style.textDecoration = 'none';
						obj.style.color = '#000000';
					}
					obj.style.cursor = 'pointer';
					obj.onclick = new Function(butFunc+"("+i+")");
					j++;
				}
			}
			if (cur_page_comments >= (comments_pages_nr-2))
			{
				j = 1;
				for (i=(comments_pages_nr-5); i<=comments_pages_nr; i++)
				{
					obj = document.getElementById('pg_pos'+j);		
					obj.innerHTML = i;
					if (i==cur_page_comments) 
					{
						obj.style.textDecoration = 'underline';
						obj.style.color = '#FF0000';
					} else {
						obj.style.textDecoration = 'none';
						obj.style.color = '#000000';
					}
					obj.style.cursor = 'pointer';
					obj.onclick = new Function(butFunc+"("+i+")");
					j++;
				}
			}
		} else {
			for (i=1; i<=6; i++)
			{
				obj = document.getElementById('pg_pos'+i);	
				
				// its magic - oh yeah!
				if (i<=comments_pages_nr) 
					obj.innerHTML = i;
				else
					obj.innerHTML = "";
					
				if (i==cur_page_comments) 
					{
						obj.style.textDecoration = 'underline';
						obj.style.color = '#FF0000';
					} else {
						obj.style.textDecoration = 'none';
						obj.style.color = '#000000';
					}
				obj.style.cursor = 'pointer';
				obj.onclick = new Function(butFunc+"("+i+")");
			}
		}
    }
			
	function bookmarksite(title,url)
	{ 
		if (window.sidebar) window.sidebar.addPanel(title, url, ""); 
		else if(window.opera && window.print)
		{	
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else if(document.all)// ie
			window.external.AddFavorite(url, title);
	}
	
			