function quicklist (action, vid) {
	jQuery.get ('/ajax/quicklist/'+action+'/'+vid+'/', {},
		function(data, status) {
			if (status == 'success') {
				$('#quickListContainer').html (data);
			}
		}, 
		'html'
	);
}

function cleanQuicklist () {
	jQuery.get ('/ajax/quicklist/clean/', {},
		function(data, status) {
			if (status == 'success') {
				$('#quickListContainer').html (data);
			}
		}, 
		'html'
	);
}

function friend (id, action) {
	jQuery.get ('/ajax/friend/'+action+'/'+id+'/', {},
		function(data, status) {
			if (status == 'success' && data.error == 0) {
				if (data.status == 1) {
					$('#myFriend').css ('display', '');
					$('#notMyFriend').css ('display', 'none');
				}
				else {
					$('#myFriend').css ('display', 'none');
					$('#notMyFriend').css ('display', '');
				}
			}
		}, 
		'json'
	);
	return false;
}

function ban (id, action) {
	jQuery.get ('/ajax/ban/'+action+'/'+id+'/', {},
		function(data, status) {
			if (status == 'success' && data.error == 0) {
				if (data.status == 1) {
					$('#banned').css ('display', '');
					$('#notBanned').css ('display', 'none');
				}
				else {
					$('#banned').css ('display', 'none');
					$('#notBanned').css ('display', '');
				}
			}
		}, 
		'json'
	);
	return false;
}

function bookmark (id, action) {
	jQuery.get ('/ajax/bookmark/'+action+'/'+id+'/', {},
		function(data, status) {
			if (status == 'success' && data.error == 0) {
				if (data.status == 1) {
					$('#bookmarked').css ('display', '');
					$('#notBookmarked').css ('display', 'none');
				}
				else {
					$('#bookmarked').css ('display', 'none');
					$('#notBookmarked').css ('display', '');
				}
			}
		}, 
		'json'
	);
	return false;
}

function sCatTabs (current) {
	if (current == 1) {
		$('#catgrL').attr ('class', 'bipagL  front');
		$('#catgrR').attr ('class', 'bipagR');
	}
	else {
		$('#catgrR').attr ('class', 'bipagR  front');
		$('#catgrL').attr ('class', 'bipagL');
	}
	return false;
}

function similarTabs (current) {
	if (current == 1) {
		$('#similar').attr ('class', 'bipagL  front');
		$('#authors').attr ('class', 'bipagR');
	}
	else {
		$('#authors').attr ('class', 'bipagR  front');
		$('#similar').attr ('class', 'bipagL');
	}
	return false;
}
/**
 * max_rand_num - set interval from 0 to (max_rand_num - 1)
 */
function get_random(max_rand_num) {
    var ranNum= Math.floor(Math.random() * max_rand_num);
    return ranNum;
}


function switchCodeTab (vid, title, num) {
	var array_extra_title = new Array();
	array_extra_title[0] = 'Кроме <a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a> на <b>video.tochka.net</b> можно посмотреть другое <a href="http://video.tochka.net/">видео онлайн</a>';
	array_extra_title[1] = '<a href="http://video.tochka.net/">Смотреть видео</a> на <b>video.tochka.net</b> - <a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a>';
	array_extra_title[2] = '<a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a>, а еще есть <a href="http://video.tochka.net/trailer/">трейлеры</a> на <b>video.tochka.net</b>';
	array_extra_title[3] = '<a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a> и еще смотреть самый новый <a href="http://video.tochka.net/fun/">прикол</a> на <b>video.tochka.net</b>';
	array_extra_title[4] = 'Лучшие <a href="http://video.tochka.net/fun/">видео приколы</a> на <b>video.tochka.net</b> - <a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a>';
	array_extra_title[5] = '<a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a>, а еще есть <a href="http://video.tochka.net/film/">мультфильмы</a> на <b>video.tochka.net</b>';
	array_extra_title[6] = '<a href="'+YA_MAIN_HTTP+'video/view/'+vid+'/">'+title+'</a>, а еще есть <a href="http://video.tochka.net/film/">мультфильмы онлайн</a> на <b>video.tochka.net</b>';
	var extra_title = array_extra_title[get_random(array_extra_title.length)];
	var codes = {
					1: YA_MAIN_HTTP+'video/view/'+vid+'/',
					2: '<OBJECT width="480" height="360"><PARAM name="movie" value="'+YA_STATIC_HTTP+'player/fplayer_embed.swf?&lang=ru&id='+vid+'&v=2"></PARAM><PARAM name="wmode" value="window"></PARAM><PARAM name="allowFullScreen" value="true"></PARAM><EMBED src="'+YA_STATIC_HTTP+'player/fplayer_embed.swf?lang=ru&id='+vid+'&v=2" type="application/x-shockwave-flash" wmode="window" width="480" height="360" allowFullScreen="true" ></EMBED></OBJECT><br />' + extra_title + '<br />',
					3: '<lj-embed><OBJECT width="480" height="360"><PARAM name="movie" value="'+YA_STATIC_HTTP+'player/fplayer_embed.swf?&lang=ru&id='+vid+'&v=2"></PARAM><PARAM name="wmode" value="window"></PARAM><PARAM name="allowFullScreen" value="true"></PARAM><EMBED src="'+YA_STATIC_HTTP+'player/fplayer_embed.swf?lang=ru&id='+vid+'&v=2" type="application/x-shockwave-flash" wmode="window" width="480" height="360" allowFullScreen="true" ></EMBED></OBJECT></lj-embed><br />' + extra_title + '<br />',
					4: '[flash=480,360,'+YA_STATIC_HTTP+'player/fplayer_embed.swf?lang=ru&id='+vid+'&v=2] <br />' + extra_title + '<br />'
				};
	for (i = 1; i <= 4; i++) {
		$('#tab'+i+'_'+vid).attr ('class', '');
	}
	$('#tab'+num+'_'+vid).attr ('class', 'pennon');
	$('#code_'+vid).attr ('value',codes [num]);
	return false;
}

var Alex=new Object;
var ie = navigator.userAgent.indexOf("MSIE") >= 0;
var ie6 = navigator.userAgent.indexOf("MSIE 6") >= 0;
var ie7 = navigator.userAgent.indexOf("MSIE 7") >= 0;
var ie8 = navigator.userAgent.indexOf("MSIE 8") >= 0;
var opera = navigator.userAgent.indexOf("Opera") >= 0;

function magneto(_obj) {
//	alert(_obj.parentNode.parentNode.className);
 if (_obj.parentNode.parentNode.className == "galleri1" || _obj.parentNode.parentNode.className == "galleri1 tip2"){
  var obl=_obj.offsetParent.offsetLeft, obt=_obj.offsetParent.offsetTop, xPryg, yPryg, posx, posy;

  if (!ie6&!ie7){
  var alexT=_obj.parentNode.offsetTop-_obj.parentNode.parentNode.offsetTop;
  var alexB=_obj.parentNode.parentNode.offsetHeight - alexT;
  var alexL=_obj.parentNode.offsetLeft-_obj.parentNode.parentNode.offsetLeft;
  var alexR=_obj.parentNode.parentNode.offsetWidth - alexL;
  }

  _obj.offsetParent.style.zIndex="10";
  for (var i=0; i<_obj.childNodes.length; i++){
         if (_obj.childNodes[i].nodeType == 1){
                if (_obj.childNodes[i].tagName == "DIV") {Alex=_obj.childNodes[i]; break;}
                }
  }

  if (!ie6&!ie7){

  //alert("!ie");
  if ((alexT >0)&(alexR >171)) {Alex.className="galPopUp"; xPryg=0; yPryg=-78;}
  if ((alexT==0)&(alexR >171)) {Alex.className="galPopUp t152"; xPryg= 15;  yPryg= 0;}
  if ((alexT==0)&(alexR<=171)) {Alex.className="galPopUp t228"; xPryg=-155; yPryg= 0;}
  if ((alexT >0)&(alexR<=171)) {Alex.className="galPopUp t76";  xPryg=-155; yPryg=-78;}
  } else {xPryg=0; yPryg=-78};

  _obj.onmousemove= function (e) {
          if (_obj.parentNode.parentNode.className != "galleri1" && _obj.parentNode.parentNode.className != "galleri1 tip2") return; // for class "gallerie2"
          var mosx=0, mosy=0;
          if(!e) var e=window.event;
          // if(e.type=="onmousemove"){};
          if(e.pageX) {mosx=e.pageX-obl; mosy=e.pageY-obt;}
          else if(e.clientX) {
                  mosx=e.clientX - obl + document.body.scrollLeft + document.documentElement.scrollLeft;
                  mosy=e.clientY - obt + document.body.scrollTop + document.documentElement.scrollTop;
          }
          Alex.style.left=(mosx+xPryg)+"px"; Alex.style.top=(mosy+yPryg) + "px";
  }
  _obj.onmouseout= function (e) {
         if (!ie) _obj.onmousemove=false;
         else _obj.onmousemove=function() {return false};
         _obj.parentNode.style.zIndex="1";
         Alex.className="galPopUp";
         Alex.style.top="0px"; // Position for class "gallerie2"
         Alex.style.left="510px"; // Position for class "gallerie2"
  }
 }
}

// JavaScript Document
function playsStarted(vid) {
	jQuery.get ('/ajax/watched/'+vid+'/', {},
		function(data, status) {}, 
		'html'
	);
	return false;
}

function mediaIsEnd(vid) {
}

function setRate(vid, rate) {
	if (rate == 'hot')
		rate_value = 1;
	else
		rate_value = 0;
	jQuery.get ('/ajax/rate/'+vid+'/'+rate_value+'/', {},
		function(data, status) {}, 
		'html'
	);
	return false;
}

function abuse (vid) {
	jQuery.get ('/ajax/abuse/'+vid+'/', {},
		function(data, status) {
			if (status == 'success') {
				$('#sendAbuse').html (phrase ['player']['abuse_sent']);
			}
		}, 
		'html'
	);
}

function saveToBookmarks () {
	jQuery.get ('/ajax/save_quicklist/', {},
		function(data, status) {
			if (status == 'success') {
				$('#saveToBookmarks').html (phrase ['quicklist']['bookmarked']);
			}
		}, 
		'html'
	);
}

function emptyField (field) {
	field.value = '';
}

function restoreValue (field, value) {
	if (field.value == '') {
		field.value = value;
	}
}

function copyToClipboard (vid) {
	if (jQuery.browser.msie) {
		window.clipboardData.setData("Text", $('#code_'+vid).attr ('value'));
		alert (phrase ['player']['copied']);
	}
	else {
		alert (phrase ['player']['not_copied']);
		$('#code_'+vid).focus ();
		$('#code_'+vid).select ();
	}
}

function selectCode (vid) {
	$('#code_'+vid).select ();
}

function switchLanguage (lang) {
	return false;
	jQuery.get ('/ajax/lang/', {'lang' : lang},
		function(data, status) {
			window.location.reload (true);
		}, 
		'html'
	);
}