function MyAppendData(what, where) {

	$("<span>"+what+"</span>").appendTo("#"+where);
}

function ToggleArchive()
{
	$("#calend").toggle();
}

function change_month($y, $m)
{
	var text = '';
	var mon = 'фыв';
	$.ajax
	({
			type: "POST",
			url: "change_month.php",
			data: "year="+$y+"&month="+$m,
			dataType:'json',
			success: function(msg)
			{
				text = '<table cellpadding="0" cellspacing="0" border="0"><tr class="month"><td><a href="javascript:change_month('+msg.prev_year+', '+msg.prev_month+');">««</a></td><td colspan="5">';
				switch (msg.month_text)
				{
					case 0:mon='Январь'; break;
					case 1:mon='Февраль'; break;
					case 2:mon='Март'; break;
					case 3:mon='Апрель'; break;
					case 4:mon='Май'; break;
					case 5:mon='Июнь'; break;
					case 6:mon='Июль'; break;
					case 7:mon='Август'; break;
					case 8:mon='Сентябрь'; break;
					case 9:mon='Октябрь'; break;
					case 10:mon='Ноябрь'; break;
					case 11:mon='Декабрь'; break;
				}
				text += mon;
				text += ' '+msg.year_text+'</td><td><a href="javascript:change_month('+msg.next_year+', '+msg.next_month+');">»»</a></td></tr><tr class="week"><td>П</td><td>В</td><td>С</td><td>Ч</td><td>П</td><td>С</td><td>В</td></tr>';
				var i = 0;
				var j = 0;
				for (i = 0; i < msg.week.length; i++)
				{
					text += '<tr>';
					for (j = 0; j < msg.week[i].length; j++)
					{
						if (msg.events[msg.week[i][j]])
						{
							text += '<td'+(msg.cur_day==msg.week[i][j] ? ' class="curent"' : '')+'><a href="index.php?date='+msg.week[i][j]+'.'+msg.cur_month+'.'+msg.cur_year+'">'+msg.week[i][j]+'</td>';
						}
						else
						{
							text += '<td'+(msg.cur_day==msg.week[i][j] ? ' class="curent"' : '')+'>'+msg.week[i][j]+'</td>';
						}
					}
					text += '</tr>';
				}
				text += '</table>';
				$('#calend').html(text);
			}
	});
}



function conf(location, mess)

	{

		if (window.confirm(mess) == false)

		{

		}

		else

		{

			window.location = location;

		}

	}

function AddNewSlide(divAdd) {

    $("#"+divAdd).slideDown(1000);
}

function ValidURL(url) {
	var reg = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/;
	if (reg.test(url)) return true;
	else return false;
}


function MyShowHide(handler_div) {

    if(document.getElementById(handler_div).style.display == 'none') ShowDiv(handler_div);
    else HideDiv(handler_div);
}

function MyShowHide2(handler_div) {

    if(document.getElementById(handler_div).style.display == 'none') {
    	$("#"+handler_div).show(500);
        document.getElementById('menu_link').className = 'all_vids activ_vids';
    }
    else {
    	$("#"+handler_div).hide(500);
        document.getElementById('menu_link').className = 'all_vids';
    }
}

function ShowHide(div_hide, div_show) {

    $("#"+div_hide).slideUp(60);
    $("#"+div_show).slideDown(600);
}
function ShowDiv(div_show) {

    $("#"+div_show).slideDown(100);
}
function HideDiv(div_hide) {

    $("#"+div_hide).slideUp(100);
}
function SetElFocus(id_field) {

    document.getElementById(id_field).select();
    document.getElementById(id_field).focus();
}

function ClearField(id_field) {
    document.getElementById(id_field).value = '';
}

function ShowPhoto(textik, photo) {
    $('#modal_text').empty();
    $("<span>"+textik+"</span>").appendTo("#modal_text");
    document.getElementById('modal_image').src = '/uploads/' + photo;
    $('#busy_layer').fadeIn();
    $('#modal_window').fadeIn();
}

function HidePhoto() {
    $('#busy_layer').fadeOut();
    $('#modal_window').fadeOut();
}

function ImageChange(id_res) {
    $('#image_place').empty();
    var what = $('#'+id_res).html();
    $("<span>"+what+"</span>").appendTo("#image_place");
}

$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 15;

	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars
	div.css({overflow: 'hidden'});

	//Find last image container
	var lastLi = ul.find('li:last-child');

	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
