$().ready(function(){
/*
$("#reg_form").validate({
//    focusInvalid: false,
    focusCleanup: true,
rules : {
			login : {required : true, minlength: 2},
			passwd : {required : true, minlength: 4},
            passwd2: {equalTo : "#passwd"},
            mail: {email : true},
            chk: {required: true}

		},
messages : {
			login : {
				required : "Введите ваше имя",
				minlength : "Введите не менее 2 символов.",
				remote : "Это имя занято"
			},
			passwd : "Введите пароль",
            passwd2: "пароли не совпадают",
            mail : {
                required: "Нужно указать email адрес",
                email: "email адрес неверный"
            },
            chk: "!"
		}
	});
*/
$("#login_link").click(function(){
$("#login_slider").toggle("slow");
$("#why_reg_slider").hide("slow");
$("#reg_slider").hide("slow");
});

$("#login_close").click(function(){
$("#login_slider").hide("slow");
});

$("#reg_link").click(function(){
$("#reg_slider").toggle("slow");
$("#login_slider").hide("slow");
$("#why_reg_slider").hide("slow");
});

$("#reg_close").click(function(){
$("#reg_slider").hide("slow");
});

$("#why_reg_link").click(function(){
$("#why_reg_slider").toggle("slow");
$("#login_slider").hide("slow");
$("#reg_slider").hide("slow");
});

$("#why_reg_close").click(function(){
$("#why_reg_slider").hide("slow");
});

/*CHAT*/
function get_chat()
{
 var login = $("#chat_login").val();
 var hash = $("#chat_hash").val();
 //var t = new Date().getTime();
 var today=new Date();
 var s=today.getTime();
  $("#chat_container").empty();
 //$("#chat_container").load( 'ajax/get_chat_body.php?login='+login+'&hash='+hash + '&time='+new Date().getTime() ,chat_scroll() );
 $.ajax({
   url: "ajax/get_chat_body.php",
   data: {login:login, hash:hash,time:s },
   dataType: "html",
   cache: "false",
   /*async: "false",*/
   success: function(data){
       //alert(data);
       $("#chat_container").append(data);
       $("#chat_body").scrollTop(3000);
       },
    beforeSend: function(){
        // Handle the beforeSend event
        //$("#chat_body").css( {borderWidth:"5px", borderStyle:"solid"} )
        //$("#chat_form_button").css( {backgroundColor:"grey"} )
    },

    complete: function(){
        //$("#chat_container").append(data);
        //chat_scroll();
        //$("#chat_body").css( {borderWidth:"0px", borderStyle:"none"} )
        //$("#chat_body").css( {backgroundColor:"white"} )
        //$("#chat_form_button").css( {backgroundColor:"white"} )
    }
   });

}

function chat_scroll() {
$("#chat_body").oneTime("0.5s", function() {
$("#chat_body").scrollTop(3000);
});
}

$("#chat_body").everyTime(21321, function() {
get_chat();
});

$("#chat_form_button").click(function(){
 var login = $("#chat_login").val();
 var hash = $("#chat_hash").val();
 var text = $("#chat_form_input").val();
 var today=new Date();
 var s=today.getTime();
 $.ajax({
   url: "ajax/chat_send.php",
   data: {login:login, hash:hash, mess:text, secs:s},
   dataType: "html",
   type:"get",
   cache: "false",
   success: function(data){
       //alert(data);
       $("#chat_form_input").attr("value","");
       get_chat();
       //chat_scroll();
       },
    beforeSend: function(){
        // Handle the beforeSend event
        $("#chat_body").css( {borderWidth:"5px", borderStyle:"solid", borderColor: "#F36C22"} )
        //$("#chat_form_button").css( {backgroundColor:"grey"} )
    },
    
    complete: function(){
        $("#chat_body").css( {borderWidth:"0px", borderStyle:"none"} )
        //$("#chat_body").css( {backgroundColor:"white"} )
        //$("#chat_form_button").css( {backgroundColor:"white"} )
    }
   });
});

$("#chat_open").click(function(){
$("#second_line").hide();
$("#first_line_b").css({display:"block"});
get_chat();
});

$("#exit_chat").click(function(){
$("#first_line_b").hide();
$("#second_line").css({display:"block"});
});


$("#first_line_b").hide();
get_chat();
/* //CHAT */

/* billboard */

 $(".billboard_submenu2_element").bind("click", function(event){
 var item_id = $(this).attr("id");
 var today=new Date();
 var s=today.getTime();
 $("#billboard_submenu2 span").removeClass("billboard_submenu2_active");
 $("#billboard_submenu2 span").addClass("billboard_submenu2_element");
 $(this).removeClass("billboard_submenu2_element");
 $(this).addClass("billboard_submenu2_active");

 $.ajax({
   url: "/ajax/get_cinema_mov.php",
   data: { cin_id:item_id, type:"cin_data" },
   dataType: "html",
   cache: "false",
   success: function(data){
   alert(data);
        $("#billboard_box").html(data);
        $('#billboard_container').unblock();
       },
    beforeSend: function(){
        $('#billboard_container').block({
        message: "<h3>Идет загрузка...</h3>",
        css: { backgroundColor: "#6b6b6b",color: "#fff", opacity: .5 ,paddingTop: "70px", fontFamily: "Arial",left: "0", width: "405px" ,height: "80px" ,borderWidth: "0" },
        overlayCSS: { backgroundColor: "#c5c5c5"  }
        });
    },
    complete: function(data){
        //$("#chat_form_button").css( {backgroundColor:"white"} )
    }
   });

  });
  
/**/
});

function utf8_encode ( str_data ) {	// Encodes an ISO-8859-1 string to UTF-8
	// 
	// +   original by: Webtoolkit.info (http://www.webtoolkit.info/)

	str_data = str_data.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < str_data.length; n++) {
		var c = str_data.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		} else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		} else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}

	return utftext;
}

  	function updateAjaxTagSearch(search_str){
		if (search_str.length>1) {
			//search_str = utf8_encode(search_str);
			jQuery.get('address.php', { 
				ajax: 'true', 
				act: 'ajax_search_tag_links', 
				search: ( ( search_str ) )
			}, function(data){
				jQuery('#tag_result').show().html(data);
			});
			//alert(search_str);
		} else {
			jQuery('#tag_result').hide();
		}
	}

