// JavaScript Document

var private_chat_start = function(prm) 
{
	prm = $.extend({ln:'en',host_user_id:0, guest_user_id:0}, prm);
	private_chat_window({ln:prm.ln, mode:'chat_invite',obj_id:prm.guest_user_id});
	// pwin = window.open('/'+prm.ln+'/chat_invite/'+prm.guest_user_id+'.html', "pwin","location=0,status=0,scrollbars=0,resizable=0, width=600,height=500");
	// pwin.moveTo(150,100);
	// pwin.focus();
}// private_chat_start

var private_chat_accept = function(prm) 
{
	prm = $.extend({ln:'en',host_user_id:0, guest_user_id:0, room_id:0, message_id:0}, prm);
	if (!prm.room_id) {
		prm.room_id = $("input[@name=room_id]", "#message_cont").val();
	};
	$.ajax({
		type: 'POST',
		url: '/'+webroot+prm.ln+'/ajax.html',
		data: 'act=private_chat_accept_invite&user_id='+prm.host_user_id+'&room_id='+prm.room_id+'&msg_id='+prm.message_id,
		dataType: 'html',
		success: function(msg) {
			if(msg=='ok'){
				private_chat_window({ln:prm.ln,mode:'private_chat',obj_id:prm.room_id});
				// pwin = window.open('/'+prm.ln+'/private_chat/'+prm.room_id+'.html', "pwin","location=0,status=0,scrollbars=0,resizable=0, width=600,height=500");
				// pwin.moveTo(150,100);
				// pwin.focus();
				refreshMessages();
			}
		}
	});
	
}// private_chat_accept

var private_chat_window = function(prm)
{
	prm = $.extend({ln:'en', mode:'chat_invite', obj_id:0}, prm);
    //alert('/'+prm.ln+'/'+prm.mode+'/'+prm.obj_id+'.html');
    //alert("pwin"+prm.obj_id);
    //alert("location=0,status=0,scrollbars=0,resizable=0, width=600,height=500");
	window['pwin'+prm.obj_id] = window.open('/'+webroot+prm.ln+'/'+prm.mode+'/'+prm.obj_id+'.html', "pwin"+prm.obj_id,"location=0,status=0,scrollbars=0,resizable=0, width=600,height=500");
	if ( typeof(window['pwin'+prm.obj_id]) != "undefined" && window['pwin'+prm.obj_id] != null ) {
		window['pwin'+prm.obj_id].moveTo(150,100);
		window['pwin'+prm.obj_id].focus();
	}
	else {
		$("#center_block").prepend('<div class="info_message">'+popup_blocked_message+'<br /><a href="/'+webroot+prm.ln+'/'+prm.mode+'/'+prm.obj_id+'.html" onclick="$(\'.info_message\').remove();" target="_blank">'+popup_blocked_link+'</a> '+popup_blocked_link_text+'</div>');
	}
}// private_chat_window



function showLeftFast (what) {
	$('#left_block').show();
	$("#center_block").css("width","56%");
	$("#center_block_inner").css("margin","0px 12px");
    switch(what){
        case 'messages':
            $("#message_cont_wrapper").show();
            $("#message_cont_wrapper").prev("#msg_message_title").show();
            $("#message_cont_wrapper").next(".h12").show();
            $("#main_message_cont_wrapper").show();
            $("#main_message_cont_wrapper").prev("#msg_main_message_title").show();
            $("#main_message_cont_wrapper").next(".h12").show();
            break;
        case 'offers':
            $("#main_friend_offer_cont_wrapper").show();
            $("#main_friend_offer_cont_wrapper").prev("#msg_friend_offer_title").show();
            break;
    }
}
function showLeft (what) {
	$('#left_block').slideDown("slow");
	$("#center_block").css("width","56%");
	$("#center_block_inner").css("margin","0px 12px");
    switch(what){
        case 'messages':
            $("#message_cont_wrapper").show();
            $("#message_cont_wrapper").prev("#msg_message_title").show();
            $("#message_cont_wrapper").next(".h12").show();
            $("#main_message_cont_wrapper").show();
            $("#main_message_cont_wrapper").prev("#msg_main_message_title").show();
            $("#main_message_cont_wrapper").next(".h12").show();
            break;
        case 'offers':
            $("#main_friend_offer_cont_wrapper").show();
            $("#main_friend_offer_cont_wrapper").prev("#msg_friend_offer_title").show();
            break;
    }
}
function hideLeft (all) {
    $("#big_message").val('0');
    $("#message_cont_wrapper").hide();
    $("#message_cont_wrapper").prev("#msg_message_title").hide();
    $("#message_cont_wrapper").next(".h12").hide();
    $("#main_message_cont_wrapper").hide();
    $("#main_message_cont_wrapper").prev("#msg_main_message_title").hide();
    $("#main_message_cont_wrapper").next(".h12").hide();
    $("#main_friend_offer_cont_wrapper").hide();
    $("#main_friend_offer_cont_wrapper").prev("#msg_friend_offer_title").hide();
    if(all == 1){
        $('#left_block').fadeOut("fast", function() {
        $("#center_block").css("width","78%");
        $("#center_block_inner").css("margin","0px 12px 0px 0px");
        } );
    	new_message_notify_stop();
    }
}

function addPicture(loading, id, file, descr, show_cb, rel, avg, cnt){
	var next_image = parseInt($("#next_image").val());
	var row = parseInt($("#photo_table_row").val());
	var col = parseInt($("#photo_table_col").val());
	var table = $("#photo_table");
	
	
	if(col>=3){ 
		col=0;
		row++;
	}
	
	if(col==0) $("#photo_table").append('<tr id="row_'+row+'"></tr>');
	
	var chk_box = '';
	
	if(loading==1){
		$("#row_"+row).append('<td><div id="foto_'+next_image+'" class="photo"><img src="/'+webroot+'img/loading.gif" /></div></td>');
	} else {
		if(show_cb==1){
			chk_box = '<br /><input type="checkbox" value="'+id+'" class="checked_fotos">';
		} else {
			chk_box = '';	
		}
		$("#row_"+row).append('<td><div id="foto_'+next_image+'" class="photo">'+avg+' / '+cnt+'<br><a href="/'+webroot+'usrimg/big/'+file+'" class="thickbox" rel="'+rel+'" title="'+descr+'"><img src="/'+webroot+'usrimg/small/'+file+'" alt="'+descr+'" /></a>'+chk_box+'<br />'+descr+'</div></td>');
	}
	
	$("#photo_table_col").val(col+1);
	$("#photo_table_row").val(row);
	$("#next_image").val(++next_image);
	
}

function addMovie(loading, id, file, descr, show_cb, rel, avg, cnt, admin_user){
	var next_video = parseInt($("#next_video").val());
	var row = parseInt($("#video_table_row").val());
	var col = parseInt($("#video_table_col").val());
	var table = $("#video_table");


	if(col>=3){
		col=0;
		row++;
	}

	if(col==0) $("#video_table").append('<tr id="row_'+row+'"></tr>');

	var chk_box = '';

	if(loading==1){
		$("#row_"+row).append('<td><div id="video_'+next_video+'" class="video"><img src="/'+webroot+'img/loading.gif" /></div></td>');
	} else {
		if(show_cb==1){
			chk_box = '<br /><input type="checkbox" value="'+id+'" class="checked_videos">';
		} else {
			chk_box = '';
		}
		$("#row_"+row).append('<td><div id="video_'+next_video+'" class="video">'+avg+((avg&&cnt)?' / ':'')+cnt+'<br><a href="/'+webroot+ln+'/video.html?movie='+id+'" rel="'+rel+'" title="'+descr+'"><img src="/'+webroot+'img/video.png" alt="'+descr+'" /></a>'+chk_box+'<br />'+descr+'');
        if(admin_user){
            $("#row_"+row).append('&nbsp;<a style="position:relative;left:-95px;bottom:-20px;" href="/'+webroot+'ru/" onclick="deleteVideo('+id+'); return false;"><img src="/'+webroot+'img/buttons/icon_forum_delete.jpg"></a>');
        }
        $("#row_"+row).append('</div></td>');
	}

	$("#video_table_col").val(col+1);
	$("#video_table_row").val(row);
	$("#next_video").val(++next_video);

}


function addPictureRate(id, file, descr){
	var next_image = parseInt($("#next_image").val());
	var row = parseInt($("#photo_table_row").val());
	var col = parseInt($("#photo_table_col").val());
	var table = $("#photo_table");
	
	
	if(col>=3){ 
		col=0;
		row++;
	}
	
	if(col==0) $("#photo_table").append('<tr id="row_'+row+'"></tr>');
	
	$("#row_"+row).append('<td><div id="foto_'+next_image+'" class="photo"><a href="/'+webroot+ln+'/show_foto.html?id='+id+'" class="foto_raiting" rel="'+id+'" title="'+descr+'"><img src="/'+webroot+'usrimg/small/'+file+'" alt="'+descr+'" class="photo_gallery_img" onclick="showRateFoto('+id+'); return false;" /></a><br />'+descr+'</div></td>');

	
	$("#photo_table_col").val(col+1);
	$("#photo_table_row").val(row);
	$("#next_image").val(++next_image);
	
}

function showRateFoto(id){	
	window.open('/'+webroot+ln+'/show_foto.html?id='+id, 'photo', 'width=400,height=400,left=100,top=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,resizable=0,status=0,fullscreen=0');
}

var clickButton = function(){
	$("#refreshButton").click();	
}

var refreshMessages = function(){

	getUnreadedMessages(0);
}

/*
function __getUnreadedMessages(startTimer){
	$.ajax({
		type: 'GET',
		url: '/'+webroot+ln+'/ajax.html',
		data: 'act=get_new_messages&unreaded',
		dataType: 'script',
		success: function(opres) {
			if(result=='new_messages'){
				if(startTimer==0){
					$("#big_message").val('0');
					$("#message_cont").empty();
					$("#main_message_cont").empty();
				}
				showLeftFast();
				addMessages(res);
			} else {
				hideLeft();	
				$("#big_message").val('0');
				$("#message_cont").empty();
				$("#main_message_cont").empty();
			}
		}
	});
	if(startTimer==1){
		setTimeout('getNewMessages()', 30000);
	}
}
*/

function getNewMessages(){
	$.ajax({
		type: 'GET',
		url: '/'+webroot+ln+'/ajax.html',
		data: 'act=get_new_messages',
		dataType: 'script',
		success: function(opres) {
			if(result=='new_messages'){
				addMessages(res);
			}
			else {
				refreshMessages();
			}
		}
	});
	setTimeout('getNewMessages()', 60000);   
}

function addMessages(res){
	showLeft('messages');
	for(var i=0; i<res.length; i++){
		$("#main_message_cont").append('<div class="small_message cursor_ph" onclick="showMessage(\'small_message_'+res[i]['id']+'\');" id="small_message_'+res[i]['id']+'"><span class="like_link">'+res[i]['name']+'</span><br><img src="/'+webroot+'img/empty.gif" height="2px"><br><span class="short_message">'+res[i]['short_msg']+'</span><input type="hidden" name="id" class="id" value="'+res[i]['id']+'"><input type="hidden" name="uid" class="uid" value="'+res[i]['uid']+'"><input type="hidden" name="user_id" class="user_id" value="'+res[i]['user_id']+'"><input type="hidden" name="name" class="name" value="'+res[i]['name']+'"><input type="hidden" name="login" class="login" value="'+res[i]['login']+'"><input type="hidden" name="foto" class="foto" value="'+res[i]['foto']+'"><input type="hidden" name="msg" class="msg" value="'+res[i]['msg']+'"><input type="hidden" name="data" class="data" value="'+res[i]['data']+'"><input type="hidden" name="f_system" class="f_system" value="'+res[i]['f_system']+'"><input type="hidden" name="gift" class="gift" value="'+res[i]['gift']+'"></div>');
		if($("#big_message").val()==0){
			showMessage('small_message_'+res[i]['id']);	
			new_message_notify_init();
		}
	}
}

function getUnreadedMessages(startTimer){
    //var off_result=""; // prosjba ne dobavljatj etu stroku   R.O.
	$.ajax({
		type: 'GET',
		url: '/'+webroot+ln+'/ajax.html',
		data: 'act=get_new_friend_offers&unreaded',
		dataType: 'script',
		success: function(opres) {
            //alert(opres);
            eval(opres);
            var flag=false;
            /*$("#big_message").val('0');
            $("#message_cont_wrapper").hide();
            $("#message_cont_wrapper").prev("#msg_message_title").hide();
            $("#message_cont_wrapper").next(".h12").hide();
            $("#main_message_cont_wrapper").hide();
            $("#main_message_cont_wrapper").prev("#msg_main_message_title").hide();
            $("#main_message_cont_wrapper").next(".h12").hide();
            $("#main_friend_offer_cont_wrapper").hide();
            $("#main_friend_offer_cont_wrapper").prev("#msg_friend_offer_title").hide();*/
            if(startTimer==1){
                hideLeft(0);
            }
  			if(startTimer==0){
    			if(result=='new_messages'){
                    $("#big_message").val('0');
                    $("#message_cont").empty();
                    $("#main_message_cont").empty();
                    //$("#main_friend_offer_cont").empty();
                }
            }
			if(result=='new_messages'){
                flag=true;
				showLeftFast('messages');
				addMessages(res);
            }
			else {
				$("#big_message").val('0');
				$("#message_cont").empty();
				$("#main_message_cont").empty();
	            $("#message_cont_wrapper").hide();
	            $("#message_cont_wrapper").prev("#msg_message_title").hide();
	            $("#message_cont_wrapper").next(".h12").hide();
	            $("#main_message_cont_wrapper").hide();
	            $("#main_message_cont_wrapper").prev("#msg_main_message_title").hide();
	            $("#main_message_cont_wrapper").next(".h12").hide();
	            $("#main_friend_offer_cont_wrapper").hide();
	            $("#main_friend_offer_cont_wrapper").prev("#msg_friend_offer_title").hide();
			}
			
  			if(startTimer==0){
                if (off_result=='new_offers') {
                    //$("#big_message").val('0');
                    //$("#message_cont").empty();
                    //$("#main_message_cont").empty();
                    $("#main_friend_offer_cont").empty();
                }
            }
            if(off_result=='new_offers') {
                flag=true;
				showLeftFast('offers');
                addFriendOffers(off);
            }
            if (!flag) {
				hideLeft(1);
				$("#big_message").val('0');
				$("#message_cont").empty();
				$("#main_message_cont").empty();
				$("#main_friend_offer_cont").empty();
			}
        }
	});
	if(startTimer==1){
		setTimeout('getNewMessages()', 30000);
	}
}

function getNewFriendOffers(){
	$.ajax({
		type: 'GET',
		url: '/'+webroot+ln+'/ajax.html',
		data: 'act=get_new_friend_offers',
		dataType: 'script',
		success: function(opres) {
			/*if(result=='new_offers'){
				addFriendOffers(res);
			}*/
		}
	});
	setTimeout('getNewFriendOffers()', 60000);
}

function addFriendOffers(res){
	showLeft('offers');
    //alert(res[0]['name']);
	for(var i=0; i<res.length; i++){
		$("#main_friend_offer_cont").append(
        '<div class="small_message cursor_ph" '+
        'id="small_offer_'+res[i]['id']+'">'+
        '<a href="/'+webroot+ln+'/user/'+res[i]['login']+'.html">'+
        res[i]['name']+'</a>&nbsp;'+
        '<a style="color:grey;"'+
        'onclick="confirmFriends('+res[i]['id']+');return false;"'+
        '>'+uif_friend_agree+'</a>/'+
        '<a style="color:grey;"'+
        'onclick="removeFriendOffer('+res[i]['id']+');return false;"'+
        '>'+uif_friend_decline+'</a><br>'+
        '<input type="hidden" name="id" value="'+res[i]['id']+'">'+
        '<input type="hidden" name="user_id" value="'+res[i]['user_id']+'">'+
        '<input type="hidden" name="friend_id" value="'+res[i]['friend_id']+'">'+
        '<input type="hidden" name="confirmed" value="'+res[i]['confirmed']+'">'+
        '</div>');
		//if($("#big_message").val()==0){
			//showMessage('small_message_'+res[i]['id']);
			//new_message_notify_init();
		//}
	}
}

function confirmFriends(id){
    if (confirm(msg_friend_accept)) {
        $.post('/'+webroot+'ru/ajax.html', {
                act: "confirm_friends",
                friend_id: id
            },function(data){
                if(data=='ok'){
                    alert(msg_added_new_friend);
                    javascript:location.reload(true);
                }else {
                    alert('['+data+'] Sorry Can\'t add new friend');
                    javascript:location.reload(true);
                }
            });
	}else{
        removeFriendOffer(id);
    }
}

function offerFriend(id){
    if (confirm(are_you_sure)) {
        $.post('/'+webroot+'ru/ajax.html', {
                act: "offer_friend",
                id: id
            },function(data){
				if(data=='ok'){
					alert(msg_your_request_sent);
					javascript:location.reload(true);
				}else alert('Error');
            });
	}
}

function removeFriendOffer(fr_id){
    $.post('/'+webroot+'ru/ajax.html', {
			act: "del_friend_offer",
			friend_id: fr_id
		},function(data){
            javascript:location.reload(true);
			//self.location = '/<?=webroot.$ln?>/my_friends.html';
		});
}

function removeFriend(fr_id){
    $.post('/'+webroot+'ru/ajax.html', {
			act: "del_friend",
			friend_id: fr_id
		},function(data){
			javascript:location.reload(true);
		});
}

var _title = "";
var _nm_to = null;
var _tick = 0;
var new_message_notify_init = function() 
{
	if (_title != "") {
		return false; // We've already done this once
	};
	
	_title = document.title;
	new_message_notify();
}; // new_message_notify_init

var new_message_notify = function() 
{
	if (_title == "") {
		return false; // No new message notify
	};
	var _animation = [];
	var _i = 0;
	_animation[_i++] = "*";
	_animation[_i++] = "**";
	_animation[_i++] = "***";
	_animation[_i++] = "****";
	_animation[_i++] = "**  **";
	_animation[_i++] = "** N **";
	_animation[_i++] = "** Ne **";
	_animation[_i++] = "** New **";
	_animation[_i++] = "** New  **";
	_animation[_i++] = "** New m **";
	_animation[_i++] = "** New me **";
	_animation[_i++] = "** New mes **";
	_animation[_i++] = "** New mess **";
	_animation[_i++] = "** New messa **";
	_animation[_i++] = "** New messag **";
	_animation[_i++] = "** New message **";
	_animation[_i++] = "** New message **";
	_animation[_i++] = "** New message **";
	_animation[_i++] = "** New messag **";
	_animation[_i++] = "** New messa **";
	_animation[_i++] = "** New mess **";
	_animation[_i++] = "** New mes **";
	_animation[_i++] = "** New me **";
	_animation[_i++] = "** New m **";
	_animation[_i++] = "** New  **";
	_animation[_i++] = "** New **";
	_animation[_i++] = "** Ne **";
	_animation[_i++] = "** N **";
	_animation[_i++] = "**  **";
	_animation[_i++] = "****";
	_animation[_i++] = "***";
	_animation[_i++] = "**";
	
	if (_tick >= _animation.length) {
		_tick = 0;
	};
	document.title = _animation[_tick]+" "+_title;
	_tick++;
	_nm_to = setTimeout("new_message_notify()",250);
}; // new_message_notify

var new_message_notify_stop = function() 
{
	if (_title == "") {
		return false; // No new message notify
	};
	document.title = _title;
	_title = "";
	clearTimeout(_nm_to);
}; // new_message_notify_stop

function showMessage(div_id){
	$("#big_message").val('1');
	$("#big_message_div_id").val(div_id);
	var id = $("#"+div_id+" .id").val();
	var uid = $("#"+div_id+" .uid").val();
	var user_id = $("#"+div_id+" .user_id").val();
	var name = $("#"+div_id+" .name").val();
	var login = $("#"+div_id+" .login").val();
	var foto = $("#"+div_id+" .foto").val();
	var msg = $("#"+div_id+" .msg").val();
	var data = $("#"+div_id+" .data").val();
	var f_system = $("#"+div_id+" .f_system").val();
	var gift = $("#"+div_id+" .gift").val();
	var answer_btn = "";
	if (f_system == 0) {
		answer_btn = '<td><a href="'+uid+'" title="'+id+'" class="write_answer green_button">'+wm_answer+'</a></td>';
	}
	else if (f_system == 1) {
		answer_btn = '<td><a href="#" onclick="private_chat_accept({host_user_id:'+uid+', guest_user_id:'+user_id+', message_id:'+id+'})" title="'+id+'" class="green_button">'+wm_answer+'</a></td>';
	}
	else if (f_system == 2) {
		var filename = msg.match(/\<input type\=\'hidden\' name\=\'fn\' value\=\'([^\']+)\' \/\>/i);
		if (filename.length > 1) {
			filename = filename[1];
		};
		// console.log(filename);
		answer_btn = '<td><a href="/'+webroot+ln+'/ajax.html?act=receive_file&sender_id='+uid+'&recipient_id='+user_id+'&msg_id='+id+'&fname='+filename+'" target="_blank" title="'+id+'" onclick="closeMessage('+id+');" class="green_button">'+wm_accept+'</a></td>';
	};
	$("#message_cont").html('<div class="info"><div class="image"><a href="/'+webroot+ln+'/user/'+login+'.html"><img src="'+webroot+foto+'"></a></div><a href="/'+webroot+ln+'/user/'+login+'.html">'+name+'</a><br><div class="data">'+data+'</div><div class="text">'+msg+'</div><div class="anwer"><table><tr>'+answer_btn+'<td><a href="#" onclick="closeMessage('+id+'); return false;" class="green_button">'+wm_close+'</a></td></tr></table></div><div style="text-align: center; padding-top: 6px; font-size: 10px;"><a href="#" onclick="if(confirm(\''+wm_block_user_confirm+'\')){block_user('+id+');} return false;">'+wm_block_user+'</a></div></div>');
	if (gift) {
		$(".image", "#message_cont").append('<div class="rose_gift2"><img src=/'+webroot+'img/tg_gift_'+gift+'.gif></div>');
	};
	createWriteMessage("write_answer");
	
	$(".small_message").removeClass("selectedMessage");
	$('#'+div_id).addClass('selectedMessage');
}

function createMenus(){
	$('.show_big_menu').each(function(itt){
		var id = $(this).find(".id").val();
		var name = $(this).find(".name").val();
		var login = $(this).find(".login").val();
		var foto = $(this).find(".foto").val();
		// $(this).append('<br><div class="pre_user_menu" id="big_menu_'+itt+'"><img src="/'+webroot+'img/empty.gif" width="154px" height="1px"><div class="user_menu"><p class="name">'+name+'</p><p class="foto"><img src="'+webroot+foto+'" /></p><p class="menu"><a href="'+id+'" class="write_message">'+menu_write_message+'</a><a href="/'+webroot+ln+'/user/'+login+'.html">'+menu_view_info+'</a></p></div></div>');
		if (id!=user_id) {
			$(this).append( '<br><div class="online pre_user_menu" id="big_menu_'+itt+'"><img src="/'+webroot+'img/empty.gif" width="154px" height="1px"><div class="user_menu"><p class="name">'+name+'</p><p class="foto"><img src="'+webroot+foto+'" /></p><p class="menu">'+
							'<a class="online write_message" href="'+id+'"><span style="color:black;text-decoration:underline;">'+menu_write_message+'</span></a>'+
							'<a class="online private_chat" onclick=\'private_chat_start({ln:"'+ln+'",host_user_id:'+user_id+',guest_user_id:'+id+'});return false;\' href="#"><span style="color:black;text-decoration:underline;">'+menu_chat_invite+'</span></a>'+
							'<a class="online view_messages" href="/'+webroot+ln+'/view_messages.html?user='+id+'"><span style="color:black;text-decoration:underline;">'+menu_view_messages+'</span></a>'+
							'<a class="online write_message_gift" href="'+id+'"><span style="color:black;text-decoration:underline;">'+menu_write_message_gift+'</span></a>'+
							// '<a onclick=\"toggleFriend("add", '+id+'); return false;\" class="add_friend" href="/'+webroot+ln+'/ajax.html">'+menu_add_friend+'</a>'+

							'<a class="online view_info" href="/'+webroot+ln+'/user/'+login+'.html"><span style="color:black;text-decoration:underline;">'+menu_view_info+'</span></a>'+
							'</p></div></div>');
		};
		$('#big_menu_'+itt).hide();
		$('#big_menu_'+itt).hover(function(){
			$('#big_menu_'+itt).show();
			$(this).addClass('big_menu_hover');
		},function(){
			$(this).removeClass('big_menu_hover');
			/*setTimeout(function(){
			$('#big_menu_'+itt).hide();
								}, 100);*/
		});
		$(this).hover(function(){
			$('#big_menu_'+itt).show();
			$(this).addClass('big_menu_hover');
		},function(){
			$(this).removeClass('big_menu_hover');
			setTimeout(function(){  
			$('#big_menu_'+itt).hide();
								}, 100);
		});
	});	
	
	$('.show_small_menu').each(function(itt){
		var id = $(this).find(".id").val();
		var name = $(this).find(".name").val();
		var login = $(this).find(".login").val();
		$(this).append('<br><div class="pre_user_menu" id="small_menu_'+itt+'">'+
            '<img src="/'+webroot+'img/empty.gif" width="154px" height="1px">'+
            '<div class="user_menu"><p class="name">'
            +name+'</p><p class="menu">'+
            '<a href="'+id+'" class="write_message"><span>'+menu_write_message+'</span></a>'+
            '<a href="#" class="private_chat" onclick="private_chat_start({ln:\''+ln+'\',host_user_id:'+id+',guest_user_id:55});'+
            'return false;"><span>'+menu_chat_invite+'</span></a>'+
            '<a href="/'+webroot+ln+'/view_messages.html?user='+id+'" class="view_messages"><span>'+menu_view_messages+'</span></a>'+
            '<a href="'+id+'" class="write_message_gift"><span>'+menu_write_message_gift+'</span></a>'+
            '<a class="view_info" href="/'+webroot+ln+'/user/'+login+'.html"><span>'+menu_view_info+'</span></a>'+
            '</p></div></div>');
		$('#small_menu_'+itt).hide();
		$('#small_menu_'+itt).hover(function(){
			$('#small_menu_'+itt).show();
			$(this).addClass('big_menu_hover');
		},function(){
			$(this).removeClass('big_menu_hover');
			setTimeout(function(){  
			$('#small_menu_'+itt).hide();
								}, 100);
		});
		$(this).hover(function(){
			$('#small_menu_'+itt).show();
			$(this).addClass('big_menu_hover');
		},function(){
			$(this).removeClass('big_menu_hover');
			setTimeout(function(){  
			$('#small_menu_'+itt).hide();
								}, 100);
		});
	});	
}

function createWriteMessage(clss) {
	$("a."+clss).each(function(){
	$(this).click(function(){   
	if($(this).attr("title") != ''){
		var add = '&answer='+$(this).attr("title");
	} else {
		var add = '';	
	}
messagewindow = window.open ('/'+webroot+ln+'/write_message.html?to='+$(this).attr("href")+add, "messagewindow","location=0,status=0,scrollbars=0, width=370,height=430");
messagewindow.moveTo(350,100);
messagewindow.focus();
	return false;
						   });
									   });
}

function createWriteMessageRose(clss) {
	$("a."+clss).each(function(){
	$(this).click(function(){   
	if(can_rose==0){
		alert(wm_no_roses);
	} else {
		if($(this).attr("title") != ''){
			var add = '&answer='+$(this).attr("title");
		} else {
			var add = '';	
		}
		messagewindow = window.open ('/'+webroot+ln+'/write_message.html?rose=1&to='+$(this).attr("href")+add, "messagewindow","location=0,status=0,scrollbars=0, width=370,height=430");
		messagewindow.moveTo(350,100);
		messagewindow.focus();
	}
		return false;
						   });
									   });
}

function createWriteMessageGift(clss) {
	$("a."+clss).each(function(){
		$(this).click(function(){   
			if(available_gifts==0){
				alert(wm_no_gifts);
			} else {
				if($(this).attr("title") != ''){
					var add = '&answer='+$(this).attr("title");
				} else {
					var add = '';	
				}
				messagewindow = window.open ('/'+webroot+ln+'/write_message.html?gift=1&to='+$(this).attr("href")+add, "messagewindow","location=0,status=0,scrollbars=0, width=370,height=430");
				messagewindow.moveTo(350,100);
				messagewindow.focus();
			}
			return false;
	   });
	});
}

function closeMessage(id){
	$.post('/'+webroot+'ru/ajax.html', {
			act: "close_message",
			msg_id: id
		},function(data){
			//if(data == 'ok'){
				refreshMessages();
			//}
		});
}

function block_user(id){
	//alert(id);
	$.post('/'+webroot+'ru/ajax.html', {
			act: "block_user",
			user_id: id
		},function(data){
			refreshMessages();
		});
	//location.reload(true);
}


function deleteMessages(){
	var to_del = '';
	$('.messages_to_delete:checked').each(
	  function() {
		to_del = to_del+','+$(this).val();
	  }
	);
	$.post('/'+webroot+'ru/ajax.html', {
			act: "delete_my_messages",
			mtd: to_del
		},function(data){
			javascript:location.reload(true);
		});
	
}

function deleteVisitors(){
	var to_del = '';
	$('.visitors_to_delete:checked').each(
	  function() {
		to_del = to_del+','+$(this).val();
	  }
	);
	$.post('/'+webroot+'ru/ajax.html', {
			act: "delete_my_visitors",
			mtd: to_del
		},function(data){
			javascript:location.reload(true);
		});

}

var ss=0;
function showSmiles(){
	if(ss==0){
		$('#smiles').show();
		ss=1;
	} else {
		$('#smiles').hide();
		ss=0;
	}
}
function insertEmotion(file_name, title) {


	var html = '<img src="/'+webroot+'img/smile/' + file_name + '" mce_src="/'+webroot+'img/smile/' + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';

	tinyMCE.execCommand('mceInsertContent', false, html);
}

var skin_select = function(prm) 
{
	prm = $.extend({ln:'en',user_id:0, skin_id:0}, prm);
	$.ajax({
		type: 'GET',
		url: '/'+webroot+prm.ln+'/ajax.html',
		data: 'act=skin_select&ln='+prm.ln+'&user_id='+prm.user_id+'&skin_id='+prm.skin_id,
		dataType: 'html',
		success: function(msg) {
			if(msg=='ok'){
				location.reload();
			}
		}
	});
}; // skin_select

function deleteTopPhoto(id,file){
    dat = id + ',' +file;
	if (confirm("Are you sure?")) {
        $.post('/'+webroot+'ru/ajax.html', {
                act: "delete_top_photo",
                mtd: dat
            },function(data){
                javascript:location.reload(true);
            });
    }
}

function deleteVideo(id){
    dat = id + ',' +" ";
	if (confirm("Are you sure?")) {
        $.post('/'+webroot+'ru/ajax.html', {
                act: "delete_video",
                mtd: dat
            },function(data){
                location.reload(true);
            });
    }
}

function confirmation(lnk)
{
	if (confirm("Are you sure?")) {
		location.href=lnk;
	}
} // confirm

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


