function show_office_photo(label, office_id) {
	if ($(label).hasClass('switched')) {
		$(label).removeClass('switched');
		$("#office_photo_"+office_id).css("display", "none");
	}
	else {
		$(label).addClass('switched');
		$("#office_photo_"+office_id).css("display", "block");
	}
}

function competition_vote(item_id) {
    $.ajax({
      type: 'POST',
      url: '/competition/vote/',
      data: {'item_id':item_id},
      dataType: 'json',
      success: function(data) {
        alert(data.message);
      }

    });

}

function find_user_info()
{
    $.getJSON(
        '/user/get_user_info',
        {
            user_id: $("#search_by_fistname").val()
        },
        function(obj)
        {
            if (obj._Fld6836) $("#search_by_lastname").attr('value', obj._Fld6836);
            if (obj._Fld6839) $("#search_by_department").attr('value', obj._Fld6839);
            if (obj._Fld5616)
            {
                $("#search_by_phone").attr('value', obj._Fld5616);
            }
            else
            {
                $("#search_by_phone").attr('value', '');
            }
        }
    );
}

$(document).ready(function(){
    $(".slidebar").jCarouselLite({
			btnNext: ".slidebar_next",
			btnPrev: ".slidebar_prev",
			mouseWheel:true,
			circular:false,
            vertical: true
		});
        
    $(".slidebar_horiz").jCarouselLite({
			btnNext: ".slidebar_next",
			btnPrev: ".slidebar_prev",
			mouseWheel:true,
			circular:false
		});
        
    $(".show_big_photo").click(function(){
        var str = $(this).attr('src');
        str = str.replace("small", "big");
        $("#current_photo_view").attr('src', str);
        $("#photo_description").html($(this).attr('title'));
        $("#photo_date_create").html($(this).attr('name'));
    });
    /*
    $(".main_menu").click(function(){
        $(".header_second_menu").attr('class', 'header_second_menu_hidden');
        $("#parent_"+$(this).attr('name')).attr('class', 'header_second_menu');

    });
    */
    $("#search_text_click").click(function(){
        var form = $("#form_search");
        if($("#search_by_fistname").val())
        {
            window.location = '/user/'+($("#search_by_fistname").val());
        }
		else
        {
            form.submit();
        }

    });

    $(".main_menu").click(function(){
        window.location = $(this).attr('title');
    });
    
    $(".birthday_name").click(function(){
        window.location = '/user/'+($(this).attr('name'));
    });
    
    $("#birth_text_click").click(function(){
        window.location = $(this).attr('name');
    });
    
    $(".user_search_img").click(function(){
        if($(this).attr('name'))
        {
            window.location = '/user/'+($(this).attr('name'));
        }
    });
    $("#search_by_fistname").select_autocomplete();
    //$("#search_by_fistname").show();
    
    $(".ac_input").focus();
    
    $("#search_by_fistname").change(function() {
        var str = $("#search_by_fistname  option:selected").text();
        //alert(str);
        str = str.replace(/^\s*|\s(?=\s)|\s*$/g, ""); 
        //return;
        $(".ac_input").val(str);
        find_user_info();
	});
    
    $('.office_photo_click').click(function(){
        $('#big_office_photo').attr('src',"/images/office/big/"+$(this).attr('name'));
        $('#office_photo_descr').html($(this).attr('alt'));
    });
    
});
function  myTags(mytags){
    mytags=mytags.replace(/<A/g, '<a')
        .replace(/\/A>/g, "/a>")
        .replace(/(target=_)(\w*)/g, 'target="_$2"')
        .replace(/(class=)(?!")(\w*)/g, 'class="$2"')
        .replace(/(name=)(?!")(\w*)/g, 'name="$2"')
        .replace(/(id=)(?!")(\w*)/g, 'id="$2"');
    mytags=encodeURIComponent(mytags).replace(/!/g, '%21')
        .replace(/'/g, '%27').replace(/\(/g, '%28')
        .replace(/\)/g, '%29').replace(/\*/g, '%2A');
    var rnumber = Math.floor(Math.random()*9999999);
    var flashvars = {
        tcolor:"0x95090C",
        tcolor2:"0xD6787A",
        hicolor:"0x000000",
        tspeed:"110",
        distr:"true",
        mode:"tags",
        tagcloud:mytags
    };
    var params = {
        allowScriptAccess:"always",
        bgcolor:'#ffffff'
    };
    var attributes = {
        id:"flash_cloud"
    };
    swfobject.embedSWF("/js/libs/tagcloud.swf?r="+rnumber,
                       "tags", "220", "350", "9.0.0",
                       "expressInstall.swf", flashvars,
                       params, attributes);
};

window.onload=function(){ 
    var mytags="<tags>"
    +document.getElementById('tags').innerHTML
    +"</tags>";
    myTags(mytags);
};
