var MainShow = 0;
var CkEditor = 0 ; 
/*
var Buttons = new Array();
Buttons[0] = new Image();
Buttons[1] = new Image();
Buttons[2] = new Image();
Buttons[3] = new Image();
Buttons[4] = new Image();
Buttons[0].src = '/img/menu_button.jpg';
Buttons[1].src = '/img/menu_button_over.jpg';
Buttons[2].src = '/img/31.jpg';
Buttons[3].src = '/img/search_button_over.jpg';
Buttons[4].src = '/img/menu2_bg.jpg';

Buttons[5] = new Image();
Buttons[5].src = '/img/menu_button1a.gif';
Buttons[6] = new Image();
Buttons[6].src = '/img/menu_button2a.gif';
Buttons[7] = new Image();
Buttons[7].src = '/img/menu_button3a.gif';
Buttons[8] = new Image();
Buttons[8].src = '/img/menu_button4a.gif';
Buttons[9] = new Image();
Buttons[9].src = '/img/menu_button5a.gif';
Buttons[10] = new Image();
Buttons[10].src = '/img/menu_button6a.gif';
Buttons[11] = new Image();
Buttons[11].src = '/img/menu_button7a.gif';
Buttons[12] = new Image();
Buttons[12].src = '/img/menu_button8a.gif';

var btn_over_start = new Image();
btn_over_start.src = '/img/layout/buttons/button_over.gif';

var sub_login_img1 = new Image();
sub_login_img1.src = "/img/registration/ok_1.gif";

var sub_login_img2 = new Image();
sub_login_img2.src = "/img/registration/ok_2.gif";

*/
function Registration()
{
    open('/user/create', '', 'status=1, toolbar=0, resizable=0, scrollbars=1, width=1024, height=800');
    return false;
}

function Login()
{
    open('/account/login/', '', 'status=1, toolbar=0, resizable=0, scrollbars=1, width=800, height=650');
    return false;
}

function ShowProgress(target)
{
	$(target).html('<br><img src="/img/progress.gif" style="vertical-align:middle;">\
		<span class="progress">Запрос обрабатывается...</span>');
}

//url, form id
function AJFormSubmit(u, f)
{
	ShowProgress("#content");
    $.ajax({
	    type: "POST",
	    url: u,
	    data: $("#" + f).serialize(),
	    success: function(html){
		$("#content").html(html);
	    }
	    });
}

function AJFormSubmit2(u, f)
{
//	ShowProgress("#content");
    $.ajax({
	    type: "POST",
	    url: u,
	    data: $("#" + f).serialize()
	
	    });
}








//url, target, params, type
function AJQuery(u, target, params, t)
{
    $.ajax({
	    type: t,
	    url: u,
	    data: params,
	    success: function(html){
		$("#"+target).html(html);
	    }
	    });
}

$.fn.clearForm = function()
{
    return this.each(function()
    {
	var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
        return $(':input',this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
    	    this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
        });
};

$.fn.toggleHint = function(hint)
{
    if (!$(hint)) return false;
    
    if (!this.attr('itemHint'))
	this.attr('itemHint', 'hidden');
    if (this.attr('itemHint') == 'hidden')
    {
		var offset = this.offset();
		offset.left = offset.left + 30; 
		offset.top = offset.top - $(hint).height() - 20;
		$(hint).css('left', offset.left+'px');
		$(hint).css('top', offset.top+'px');
		this.attr('itemHint', 'visible');
    }
    else this.attr('itemHint', 'hidden');
    
    $(hint).css('visibility', this.attr('itemHint'));
}
    function is_object( mixed_var ){  
     
       if(mixed_var instanceof Array) {  
           return false;  
       } else {  
           return (mixed_var !== null) && (typeof( mixed_var ) == 'object');  
      }  
   }  

function resetDropDown(id)
{
    $("#"+id+"_child a.selected").removeClass("selected");
    $("#"+id+"_msa_0").addClass("selected");
    $("#"+id+"_titletext").html($("#"+id+"_msa_0").html());
}

function OnClearLibraryForm()
{
	$('#lib_search').clearForm();
	resetDropDown('search_type');
	$('#content').html('');
	return false;
}
function ChangeInfo(id, type_id)
{
  if (CkEditor == 0)
  {
	CkEditor =1;
	var bit  = id.split('_'); 
	//url, target, params, type
	AJQuery('/admin/ajax', id, {'id': bit[1], 'type_id': type_id}, 'post'); 
  }
}

function box() {
	this.top = 0;
	this.left = 0;
	this.height = 0;
	this.width = 0;
}

function getBox(elem) {
	c = new box();
	c.width = elem.offsetWidth;
	c.height = elem.offsetHeight;
	while (elem) {
		c.top += elem.offsetTop;
		c.left += elem.offsetLeft;
		elem = elem.offsetParent;
	}
	return c;
}

function getBoxById(id) {
	if (document.getElementById(id))
		return getBox(document.getElementById(id));
	else
		return false;
}

function append_img() {
	if (width > 1024) {
		$("#left_part").css('background-image', 'url(/img/vizitka2/madam1.jpg)');
		$("#left_part").css('width', '128px');
		$("#left_part").css('background-repeat', 'no-repeat');
		$("#left_part").html('<div style="width: 129px;"></div>');
		$("#right_part").css('background-image', 'url(/img/vizitka2/man2.jpg)');
		$("#right_part").css('width', '128px');
		$("#right_part").css('background-repeat', 'no-repeat');
		$("#right_part").css('background-position', 'left');
		//$("#right_part").html('<div style="width: 129px;"></div>');
		$("#inner_man").css('width', '258px');
	}
}

function append_img2() {
	if (width > 1024) {
		var left_part = '<img src="/img/layout/left_side.jpg" width="128" alt="1" />';
		var right_part = '<img src="/img/layout/right_side.jpg" alt="1" width="128" />';
		$("#left_part2").html(left_part);
		$("#right_part2").html(right_part);
	}
}

function split_flash() {
	/*if ($("object").css("width") != "1px") {
		$("object").css("width", "1px");
		$("object").css("height", "1px");
	} else*/ {
		$("#video_control").html("");	
		$("#rolik").css("width", "499px");
		$("#rolik").css("height", "297px");
		$("#ajax").css("display", "none");
		start_rolik();
	}
}