jQuery(document).ready(function() {

var rot1_count = $(".frames-rotation").length;

if(rot1_count > 0){
    //alert("* * *");
    $(".frames-rotation").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 8,
        mouseWheel: true
    });
}


$(".postToggle").click(
function() {
    var oldshow = $(".toggleDown").attr("show");
    var show = $(this).attr("show");

    $(".postToggle").removeClass("toggleDown");
    $(".postBox:visible").slideUp();

//alert( oldshow +" -- "+show);

if(oldshow != show){
    $(this).addClass("toggleDown");
    $("#"+show).slideDown("slow");
    }
    }
);


//$(".expedMap-inner").hide();

$(".slideBox").click(
function() {
    var show = $(this).attr("show");

    if($(this).hasClass("slideDown")){
        $("."+show).slideUp();
        $(this).removeClass("slideDown");
    }
    else{
        $("."+show).slideDown();
        $(this).addClass("slideDown");
        if($(this).attr("id")== "mapSlider"){
           google.maps.event.trigger(map, 'resize');
            map.fitBounds(bounds);
        }
    }
});

$(".slideBox").blur(
function() {
    //var show = $(this).attr("show");
    //$("."+show).slideUp();
    //$(this).removeClass("slideDown");
}
);


$(".showBox").click(
function() {
    $(".multyblock .box,.hideShowBoxes .box").hide();
    $(".showBox").removeClass("li-current");
    $(this).addClass("li-current");
    var show = $(this).attr("id");
    //alert("show: "+show);
    $("."+show).show();

});

$(".f-input input").each(function (k,m) {
    //alert(k);
     get_val(m);
});

$(".f-input textarea").each(function (k,m) {
     get_val(m);
});

$(".f-input input").click(
function() {
    save_val($(this));
    $(this).addClass("blackText");
 });

$(".f-input input").blur(
function() {
    var val = $(this).val();
    if(val == '' || val == ' '){
        get_val($(this));
        $(this).removeClass("blackText");
    }
});

$(".f-input textarea").click(
function() {
    save_val($(this));
    $(this).addClass("blackText");
 });

$(".f-input textarea").blur(
function() {
    var val = $(this).val();
    if(val == '' || val == ' '){
        get_val($(this));
        $(this).removeClass("blackText");
    }
});

function get_val(obj){
    var inputs = [
    ["your-name","Имя"],
    ["your-email","E-mail"],
    ["your-subject","Тема"],
    ["your-message","Сообщение"]
];

    var name = $(obj).attr("name");

    //alert(name);

    if(name != '' && name != null && name != 0){
        $(inputs).each(function (l,n){
            //var name2 = $(l).attr("name");
            //alert(name +" - - "+n[0]);
            if(name == n[0]){
                $(obj).val(n[1]);
                $(this).removeClass("blackText");
            }
        });
    }
}

function save_val(obj){
    var inputs = [
    ["your-name","Имя"],
    ["your-email","E-mail"],
    ["your-subject","Тема"],
    ["your-message","Сообщение"]
];

    var name = $(obj).attr("name");
    var val = $(obj).val();
    if(name != '' && name != null && name != 0){
        $(inputs).each(function (g,t){
            if(val == t[1]){
                $(obj).val("");
                $(this).removeClass("blackText");
            }
        });
    }
}


//-----------------------------------------------------------------------
$(".parts-switcher li span").click(
function() {

    if($(this).hasClass("current")){
        $(".meta-box").hide();
        $(".parts-switcher li span").removeClass("current");
    }
    else{

    $(".meta-box").hide();
    $(".parts-switcher li span").removeClass("current");
    var show = $(this).attr("id");

        $(this).addClass("current");
        $("."+show+":hidden").show();

    }

    return false;
});

  $(".parts-switcher li").hover(
  function () {
    $(this).addClass("li-hover");
  },
  function () {
    $(this).removeClass("li-hover");
  }

  );
//-----------------------------------------------------------------------

$(function() {

if($("#alpha table")){ // begin
    $("#alpha table").each(function (num_t,obj_t) {
    var tab_id = $(obj_t).attr('id');
    if(!$(obj_t).hasClass('No-niceTable') && tab_id != "vkshare0"){
        // #
        $(obj_t).addClass("niceTable");
        $("tr",obj_t).each(function (k,m) {
            var classTd = "tdFirst"
                $("td:first",m).addClass(classTd);
            });
            if(!$("tr:first",obj_t).hasClass('No-coltop')){
                $("tr:first",obj_t).addClass("coltop");
            }
            else{
                $("tr:first",obj_t).addClass("trFirst");
            }
        $(".niceTable tr:nth-child(odd)").addClass("rowB");
    }
    });
} // end
});

if($("#catAll")){
    $("#catAll").addClass("current");
    $("#catNavi span").click(
        function() {
            var cat = $(this).attr("id");

            $("#catNavi span").removeClass("current");
            $(this).addClass("current");
            //alert(cat);
            if(cat == "catAll"){
                $(".galBox").show();
            }
            else{
                $(".galBox").hide();
                //$(".galBox").removeClass("r15");
                $("."+cat).show();
                $(".galBox:visible").each(function (a,b) {
                    //$(b).removeClass("r10");
                    });
            }
        });
}
// moved by JuliaHtml. 
// These strings block work of previous functions (foto rotation, for example).

	if ( $('#toSiteButton').length > 0 ) {
		clip = new ZeroClipboard.Client();
		clip.setText( $('#clipContainer').html() );
		clip.glue( 'toSiteButton' );
		clip.addEventListener('complete',function(){RGO.Popup.openPopup('toSite');});
	}
        
});

// --------------- Склонение существительных с числительными

function DeclensionForm($n, $form1, $form2, $form5) {
$n = Math.abs($n) % 100;
$n1 = $n % 10;
if ($n > 10 && $n < 20)
return $form5;
if ($n1 > 1 && $n1 < 5)
return $form2;
if ($n1 == 1)
return $form1;
return $form5;
}
