//------------------------------------------------
function loadBlock(my_link,my_content) {
	jQuery(function(){
		$('#load_procces').show();
		$.ajax({
		contentType: "windows-1251",
		url: my_link,   
		cache: false,
		dataType: "html",
		success: function(html){   
			$(my_content).html(html); 
			$('#load_procces').hide(); }   
});});};
//------------------------------------------------
function closeW(name) {
	jQuery(function() {
		$(name).animate({opacity: "hide"},"fast");
	});
};
//------------------------------------------------
$(document).ready(function(){
	$(".top_but").hover(
		function(){
			$(this).animate({"background-color":"#94735a","color":"#FFF"},200);
			return false;
		},
		function(){
			color=this.style.backgroundColor;
			if(color!="#fe7917"){
				$(this).animate({"background-color":"#FFF","color":"#141414"},100);
				return false;
			}
		return false;
	});
	$(".to_top_but").hover(
		function(){
			$(this).animate({"background-color":"#FF6C00"},300);
			return false;
		},
		function(){
			$(this).animate({"background-color":"#979797"},300);
			return false;
	});
	return false;
});
function blockOpen(id){
	el=document.getElementById(id).style.display;
	if(el=='none'){$('#'+id).slideDown(200);}
	if(id!='mmsc_colors'){
		if(el=='block'){$('#'+id).slideUp(200);}
	}
	return false;
}
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
	function xy(e,v) { return(v?(agent('msie')?event.clientY+document.body.scrollTop:e.pageY):(agent('msie')?event.clientX+document.body.scrollTop:e.pageX)); }
	function dragOBJ(d,e) {
		function drag(e) { if(!stop) { d.style.top=(tX=xy(e,1)+oY-eY+'px'); d.style.left=(tY=xy(e)+oX-eX+'px'); } }
		var oX=parseInt(d.style.left),oY=parseInt(d.style.top),eX=xy(e),eY=xy(e,1),tX,tY,stop;
		document.onmousemove=drag; document.onmouseup=function(){ stop=1; document.onmousemove=''; document.onmouseup=''; };
	}
	
function proccesShow(){
	jQuery(function(){ 
	$('#procces').animate({"top":"15px","opacity":"1"},500);
	$('#procces').animate({"top":"10px"},200);
	document.getElementById('procces3').innerHTML = "Loading...";
	});
};
function ProccesHide() {
	setTimeout(function(){
		jQuery(function() {
			jQuery('#procces').animate({"top":"20px"},300);
			jQuery('#procces').animate({"top":"-200px","opacity":"0.3"},500);
	
		});
	},2500);
};
function ProccesHide2() {
	jQuery(function() {
		jQuery('#procces').animate({"top":"20px"},300);
		jQuery('#procces').animate({"top":"-200px","opacity":"0.3"},500);

	});
};
//------------------------------------------------
function screenSize() {
      var w, h;
      w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
      h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
      return {w:w, h:h};
}
function WindowMiddle(wE,hE,con){
	w=screenSize().w;
	h=screenSize().h;
	top1=(h-hE)/2;
	top1=top1+'px';
	pos1=(w-wE)/2;
	pos1=pos1+'px';
	if(hE=="no"){
		$('#'+con).animate({"left":pos1},0);
	}else{
		$('#'+con).animate({"left":pos1,"top":top1},0);
	}
}
//----------------------------------------------//
function del_el(type,id,conf) {
	content=type+id;
	my_link = 'blocks/delete/del_element.php?type='+type+'&id='+id+'&conf='+conf;
		document.getElementById('box_'+content).style.display="none";
		document.getElementById('confirm_'+content).style.display="block";
		my_content = '#confirm_'+content;
	loadBlock(my_link,my_content);
}
//------------------------------------------------
function ImgPropShow(){
	jQuery(function(){ 
		$('.em').hover(function() {
			$(this).find("em").animate({opacity: "1.0"},0);
			$(this).find("em").animate({opacity: "show"}, "slow");
		}, function() {
			$(this).find("em").animate({opacity: "hide"}, "fast");
	});
}); };
//------------------------------------------------
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function doPublic(page,id,element,public){
	my_link = 'blocks/edit/public.php?page='+page+'&id='+id+'&element='+element+'&public='+public;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function showAddMenu(page){
	WindowMiddle(500,247,'window');
	my_link = 'blocks/load/new_menu.php?page='+page;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function showLogin(page){
	WindowMiddle(300,200,'window_login_content');
	my_link = 'blocks/load/login.php?page='+page;
	my_content = '#window_login_content';
	loadBlock(my_link,my_content);
};
function newBlock(page,to_id){
	if(to_id>0){y=480;}else{y=200;}
	WindowMiddle(500,y,'window');
	my_link = 'blocks/load/new_block.php?page='+page+'&to_id='+to_id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function editBlock(page,id,to_id){
	if(to_id>0){y=480;}else{y=200;}
	WindowMiddle(500,y,'window');
	my_link = 'blocks/edit/edit_block.php?page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function editMenu(page,id){
	WindowMiddle(500,247,'window');
	my_link = 'blocks/edit/edit_menu.php?page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function newImageBlock(page,id){
	WindowMiddle(500,165,'window');
	my_link = 'blocks/load/new_image_block.php?page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function showDelBlock(page,id){
	WindowMiddle(300,150,'window');
	my_link = 'blocks/load/del_block.php?page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function showDelMenu(page,id){
	WindowMiddle(300,150,'window');
	my_link = 'blocks/load/del_menu.php?page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function delBlock(page,id){
	proccesShow();
	my_link = 'blocks/delete/del_block.php?page='+page+'&id='+id;
	my_content = '#procces3';
	loadBlock(my_link,my_content);
};
function delMenu(page,id){
	proccesShow();
	my_link = 'blocks/delete/del_menu.php?page='+page+'&id='+id;
	my_content = '#procces3';
	loadBlock(my_link,my_content);
};
function showImgTittle(img_id,page,id){
	WindowMiddle(500,200,'window');
	my_link = 'blocks/load/img_tittle.php?img_id='+img_id+'&page='+page+'&id='+id;
	my_content = '#window';
	loadBlock(my_link,my_content);
};
function editPage(page){
	document.getElementById('main_edit_but').style.display='none';
	document.getElementById('main_preview_but').style.display='block';
	my_link = 'blocks/include/'+page+'_blocks.php?edit=yes';
	my_content = '#blocks_content';
	loadBlock(my_link,my_content);
	my_link = 'blocks/include/menu_left.php?edit=yes'+'&page='+page;
	my_content = '#left_menu';
	loadBlock(my_link,my_content);
}
function pagePreview(page){
	document.getElementById('main_edit_but').style.display='block';
	document.getElementById('main_preview_but').style.display='none';
	my_link = 'blocks/include/'+page+'_blocks.php?edit=no';
	my_content = '#blocks_content';
	loadBlock(my_link,my_content);
	my_link = 'blocks/include/menu_left.php?edit=no'+'&page='+page;
	my_content = '#left_menu';
	loadBlock(my_link,my_content);
}
function moveElement(page,id,to_id,element,type){
	if(element=='tonal_blocks'){id_e=id;}
	if(element=='tonal_img'){id_e=to_id;}
	if(element!='tonal_menu'){
		document.getElementById('block_load_status'+id_e).style.display="block";
}
	my_link = 'blocks/edit/move_element.php?page='+page+'&id='+id+'&to_id='+to_id+'&element='+element+'&type='+type;
	my_content = '#procces3';
	loadBlock(my_link,my_content);
}
function showExit(page){
	WindowMiddle(300,180,'window_login_content');
	my_link = 'blocks/load/exit.php?page='+page;
	my_content = '#window_login_content';
	loadBlock(my_link,my_content);
};
function doExit(page){
	proccesShow();
	my_link='blocks/include/exit.php?page='+page;
	my_content='#procces3';
	loadBlock(my_link,my_content);
	ProccesHide();
};
function showBlock(id){
	jQuery(function() {
		$('#blocks_content').find('.block').css({display: 'none'},0);
		$('#blocks_content').find('#block'+id).css({display: 'block'},0);
	});
};
function showBlockLoad(id,class1,class2,class3){
	jQuery(function() {
		$('#blocks_content').find('.block').css({display: 'none'},0);
		$('#blocks_content').find('#block'+id).css({display: 'block'},0);
		
		$('#'+class1).find('.'+class2).removeClass(class2).addClass(class3);
		$('#menu_left'+id).addClass(class2);
		$('#'+class1).find('.'+class2).removeClass(class3);
	});
};
function myFuncBut(class1,class2,class3){
	jQuery(function() {
		$('.'+class1).click(function(){
			$('#'+class1).find('.'+class2).removeClass(class2).addClass(class3);
			$(this).addClass(class2);
			$('#'+class1).find('.'+class2).removeClass(class3);
		});
	});
}
function goTop(acceleration, time) {  
    acceleration = acceleration || 0.1;  
    time = time || 12;  
    var dx = 0;  
    var dy = 0;  
    var bx = 0;  
    var by = 0;  
    var wx = 0;  
    var wy = 0;  
    if (document.documentElement) {  
        dx = document.documentElement.scrollLeft || 0;  
        dy = document.documentElement.scrollTop || 0;  
    }  
    if (document.body) {  
        bx = document.body.scrollLeft || 0;  
        by = document.body.scrollTop || 0;  
    }  
    var wx = window.scrollX || 0;  
    var wy = window.scrollY || 0;  
    var x = Math.max(wx, Math.max(bx, dx));  
    var y = Math.max(wy, Math.max(by, dy));  
    var speed = 1 + acceleration;  
    window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));  
    if(x > 0 || y > 0) {  
        var invokeFunction = "top.goTop(" + acceleration + ", " + time + ")"  
        window.setTimeout(invokeFunction, time);  
    }  
    return false;  
}
function getElementPosition(elemId)
{
    var elem=document.getElementById(elemId);
    var w=elem.offsetWidth;
    var h=elem.offsetHeight;
    var l=0;
    var t=0;
    while(elem){
        l+=elem.offsetLeft;
        t+=elem.offsetTop;
        elem=elem.offsetParent;
    }
    return {"left":l, "top":t, "width": w, "height":h};
}
//------------ Gallery -----------------------
function load_images(id,to_id){
	document.getElementById('bg_gall').style.display='block';
	WindowMiddle(800,640,'window_show_images');
	my_link = 'blocks/load/load_images.php?id='+id+'&to_id='+to_id;
	my_content = '#window_show_images';
	loadBlock(my_link,my_content);
};
function load_image(n,gal_name){
	my_link = 'blocks/load/load_image.php?n='+n+'&gal_name='+gal_name;
	my_content = '#gallery_window_con';
	loadBlock(my_link,my_content);
};
function CloseGallery(gal_name,folder) {
	document.getElementById('bg_gall').style.display='none';
	my_link = 'blocks/delete/del_gallery.php?gal_name='+gal_name+'&folder='+folder;
	my_content = '';
	loadBlock(my_link,my_content);
	closeW('#gallery_window_con');
	setTimeout(function(){
		document.getElementById('gallery_window_con').innerHTML='';
	},500);
	$e.stop();
};
//------------------------------------------------
$e.start();
function Buttons(){
	$e('esc').bind( function() {
		gal_name=document.getElementById('gal_name').innerHTML;
		closeW('#'+gal_name); CloseGallery(gal_name,'gallery');
		$e.stop();
	});
	$e('left').bind( function() {
		gal_name=document.getElementById('gal_name').innerHTML;
		p_img=document.getElementById('p_img').innerHTML;
		load_image(p_img,gal_name);
		$e.clear();
	});
	$e('right').bind( function() {
		gal_name=document.getElementById('gal_name').innerHTML;
		n_img=document.getElementById('n_img').innerHTML;
		load_image(n_img,gal_name);
		$e.clear();
	});
}
