 

if (!adminpanel) 
	{
		truesize(); 
		if ( ie6 ) { $('body').attr('id','ie6'); }
		if ( ie7 ) { $('body').attr('id','ie7'); }
		if ( ie8 ) { $('body').attr('id','ie8'); }
	}

 var clearident=false;

//browser.display.focus_ring_width = 0 ;

$('#footer').append('<div id="preload" ><div class="ms1"><div class="ov"><div class="hmset1-la"></div><div class="hmset1-ls"></div><div class="hmset1-s"></div><div class="s1-t"></div><div class="s2-t"></div></div></div></div>');


//, 

$("#nav li, #hmenu li, #left .m2-L,#left .m3-L,#left .m4-L,#left .m5-L,#right .m2-L,#right .m3-L,#right .m4-L,#right .m5-L, #cmenu .cmenu-L, #cmenu .dalee-L, #left ul.MenuBarVertical li").hover(  function () 

			{
    		$(this).addClass("ov");
  			},

  			function () 
			{
    		$(this).removeClass("ov");
  			}

							);





$(window).click(function () 

			{

    		$('#maintab .admenu .incontext').fadeOut('fast');

  			});
			

$('body').mousemove(function (e)
	{
		curX= e.pageX;
      	curY = e.pageY;
		//$("#coord").text("( e.pageX, e.pageY ) - " + pageCoords);
      	$("#coord").html("<br>X: " + e.pageX + " <br> Y: " + e.pageY + " <br> H: " + (e.pageY-usY)+ " <br> W: " + (e.pageX-usX) );
		$("#coord").css('top',e.pageY+1).css('left',e.pageX+1);
	});

$(document).keyup(function(event)
	{ 
        $("#coord").html('');
		//alert();
		prekey=0;
    });
	
var prekey,usX,usY,curX,curY;
$(document).keydown(function(event)
	{
        $("#coord").html("<br>"+event.keyCode); 
		if (prekey==17 & event.keyCode==32)
			{
				//alert('rere');
				usX=curX;
				usY=curY;	
				//alert(usX);	
			}
			else
			{
				prekey=event.keyCode;
			}
		
		//alert();
    });

function setcheckval()
	{
		$('form input[type=checkbox]').change(function()
		{
		checkval($(this).attr('id'));
		}).each(function(){
		checkval($(this).attr('id'));
		});
	}

function checkval (varname)
	{
		if ($('#'+varname).attr('checked') )
			{
				$('form .'+varname).slideDown("fast");
				$('form .un'+varname).slideUp("fast");
			}
			else
			{
				$('form .'+varname).slideUp("fast");
				$('form .un'+varname).slideDown("fast");
			}
		
	}	
	
function screenHeight(){

return $.browser.opera? window.innerHeight : $(window).height();

}

function screenWidth(){

return $.browser.opera? window.innerWidth : $(window).width();

}


// isset(window, "globalValue") - можно 
function isset () {
	    // +   original by: Kevin van Zonneveld 
	    // +   improved by: FremyCompany
	    // +   improved by: Onno Marsman
	    // *     example 1: isset( undefined, true);
	    // *     returns 1: false
	    // *     example 2: isset( 'Kevin van Zonneveld' );
	    // *     returns 2: true
	     
	    var a=arguments, l=a.length, i=0;
     
	    if (l===0) {
	        throw new Error('Empty isset'); 
	    }
	     
	    while (i!==l) {
	        if (typeof(a[i])=='undefined' || a[i]===null) { 
	            return false; 
	        } else { 
	            i++; 
	        }
	    }
	    return true;
	}



function chreg(reg)
	{
		curid=$('#adcont input[name=id]').val();
		curmode=$('#adcont input[name=mode]').val();
		location.replace('http://excluse.ru/myadmin.php?id='+curid+'&mode='+curmode+'&chreg='+reg);
	}


function ajaxform()
	{
		
		$('.ajaxform').ajaxForm({
								 //target:        '#output1',
								 beforeSubmit: beforeSubmitPost,								 
						        success: successPost
								
								});
	}
function beforeSubmitPost ()
	{
		$('#adcont').fadeTo(0,0.1);
	}

function getVarValueFromURL(url, varName) {
	var query = url.substring(url.indexOf('?') + 1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == varName) {
			return pair[1];
		}
	}
	return null;
} 	
	
function successPost(responseText, statusText, xhr)
	{
		$('#adcont').fadeTo(250,1);
		dt=responseText.split('[adminmenu]');
		res=responseText.split('<div></div>');
		//alert(res[0]);
		$('#response').html(res[1]);
		
		selector='#ss'+dt[2];
		//alert (selector);
		$(selector).remove();
		$(selector).remove();
		$(selector).remove();
		
		
		
		$('#'+dt[2]).prepend(dt[1]);
		newevent(dt[2]);
		$('#'+dt[2]).attr('class','t-'+dt[3]);
		$('#'+dt[2]).attr('class','t-'+dt[3]);
		$('#'+dt[2]).attr('class','t-'+dt[3]);
		
		$('#adcont input[name=ident]').val(dt[4]);
		$('#adcont input[name=url]').val('');
		
		mode=$('#adcont input[name=mode]').val();
		if ( (mode=='0') && (dt[5]!=='') )
			{
				$('.inadm').html('');
				$('.inadm').html('');
				$('.inadm').html('');
				$('.inadm').append(dt[5]);
				setajax();

			}
		
	}
	


function imgOn(obj) {
obj.className='xx_ov';
}

function chn(id)
{
document.getElementById(id).style.display = "block"; 
}

function sh(id)
	{
	ids="#"+id;
	$(ids).toggleClass("hidem");
	}
	
function setajax(inid)
	{
	if (inid)
		{zapr='#'+inid+' div';}
		else
		{zapr='.adm div';}
	$(zapr).each(function() 
			{
			id=$(this).attr('id');			
			newevent(id);
			
			
			}); 
	
	}



function newevent(id)
	{
		$('#e'+id).click( function() 
				{
					chpage (id,1);
					return false;					
				});
			
		$('#c'+id).click(function(e)
				{
					$('.admenu .incontext').remove();
					ancorhr=$('#ss'+id+' .ancor a').attr('href');			
					ancorname=$('#ss'+id+' .ancor a').text();
					//alert(ancor);		
					appen='<ul class="incontext" ><li><a target="_blank" href="myadmin.php?prev='+id+'">Просмотр</a></li><li><a href="myadmin.php?up='+id+'&id='+id+'">Переместить ВВЕРХ</a></li><li><a href="myadmin.php?down='+id+'&id='+id+'">Переместить ВНИЗ</a></li><li><a href="javascript:setp(\'add\','+id+')">Добавить после</a></li><li>	<a href="javascript:setp(\'addd\','+id+')">Добавить подпункт</a></li><br><li>Анкор: <a href="' + ancorhr + '">' + ancorname + '</a></li><br><li class="lidel" >Удалить - 	<a href="javascript:setp(\'del\','+id+')"><img src="/jscripts/tpladmin/spacer.gif"></a></li></div> ';					
					$(".admenu").append(appen);
					yy=e.pageY-15;
					
					if (yy>(screenHeight()-170 ))
						{
							yy=screenHeight()-170;
						}
					$('.incontext').css('top',(yy)+'px').css('left',e.pageX+'px');
					return false;
					
				});
		//$('#r'+id).click( function() 
				//{
				//	chpage (id,2);
					//return false;					
				//});
	}


function setp(ev,id)
	{
		//alert(1);
		$(".inadcont").remove();
		$('.admenu .incontext').remove();
		$('#adcont').append('<div class="ajax" ></div>');
		
		$.get( 'myadmin.php?ajax='+ev+'&id='+id, 
					function(data)
						{ 
							dt=data.split('[str]');
							clearident=true;
							if (ev=='add')
								{
								$("#"+id).after(dt[0]);
								chpage (dt[1],1);
								newevent(dt[1]);
								
								}
							else if (ev=='addd')
								{
								$("#"+id).append(dt[0]);
								chpage (dt[1],1);
								newevent(dt[1]);
								
								
								}
							else if (ev='del')
								{
									$("#"+id).remove();
									chpage (dt[1],1);								
								}
							
							
						}
					);				
			
	}

function chpage (id,mode)
	{		
		var href=$('#e'+id).attr('href');
		$(".inadcont").remove();
		$('.admenu .incontext').remove();
		$('#adcont').append('<div class="ajax" ></div>');
		$.get( '?&ajax=1&id='+id+'&mode='+mode, 
				function(data)
					{ 
					var oldid=$('#adcont').attr('rel');
					//alert(oldid);
					$('.adm .act').removeClass('act');
					$('.adm .act').removeClass('act');
					
					$('#ss'+id).addClass('act');
					$('#adcont').attr('rel',id);
			
					$('#adcont .ajax').remove();
					$(".inadcont").remove();								
					$('#adcont').append('<div class="inadcont"></div>');
					$(".inadcont").append(data);
					ancor1=$('#ss'+id+' .ancor a').text();
					//ancor2=$('#ss'+id+' .ancor a').attr('href');
					$('title').text(': '+ancor1);
					truesize();	
					colorpick();	
					ajaxform();					
					setuploader();
					$("input:text,input:checkbox").change( function() {
						setuploader();
						});
					setcheckval();
					setcheckident();
					if (clearident) { $("#ident").val(''); clearident=false; }
					}
				);
		return false;
		
	}

function setcheckident()
	{
		
		$('input').hover(  function () 

			{
    		checkident($(this).attr('id'));
  			},

  			function () 
			{
    		checkident($(this).attr('id'));
  			}

							);
		
		
		/*$('body').drag({
			start:function(elem){
				$('title').text('куку');
			}, stop:function(elem){
				alert('Блок отпущен');
		}});
		*/
	}


(function($){
	$.fn.drag = function(o){
		var o = $.extend({
			start:function(){},   // при начале перетаскивания
			stop:function(){} // при завершении перетаскивания
		}, o);
		return $(this).each(function(){
		    var d = $(this); // получаем текущий элемент
		    d.mousedown(function(e){ // при удерживании мыши
                            $(document).unbind('mouseup'); // очищаем событие при отпускании мыши
			    o.start(d); // выполнение пользовательской функции
			    d.css('position','absolute');
			    var f = d.offset(), // находим позицию курсора относительно элемента
			    x = e.pageX - f.left,  // слева
			    y = e.pageY - f.top;  // и сверху
                            $(document).mousemove(function(a){ // при перемещении мыши
			        d.css({'top' : a.pageY - y + 'px','left' : a.pageX - x + 'px'}); // двигаем блок
			    });
			    return false;
		    });
		    $(document).mouseup(function(){  // когда мышь отпущена
			$(document).unbind('mousemove'); // убираем событие при перемещении мыши
			o.stop(d); // выполнение пользовательской функции
		    });
              });
	}
})(jQuery);




function checkident(id)
	{
		inp=$('#'+id);		
		inp.val( str_replace(inp.val(),'http://excluse.ru/',' ') );
	}

function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}

function func_get_arg (num) {
    
	if (!arguments.callee.caller) {
        try {
            throw new Error('Either you are using this in a browser which does not support the "caller" property or you are calling this from a global context');
            //return false;
        } catch (e){            return false;
        }
    }
 
    if (num > arguments.callee.caller.arguments.length - 1) {        try {
            throw new Error('Argument number is greater than the number of arguments actually passed');
            //return false;
        } catch (e2){
            return false;        }
    }
 
    return arguments.callee.caller.arguments[num];
}
	
function adm (id,ur,lim)
	{
		if (id<0){subid=$("#lim"+(-1)*id+'-'+lim+" div").width();}
		else{subid=$("#"+id+" div").width();}	
		
		if (subid < 1)
			{			
			$("#"+id).append('<div class="ajax"></div');
			
			if (id>0) 
				{
				$.get('myadmin.php?list=adm&id='+id+'&ur='+ur, 
					function(data)
						{ 
						$('.ajax').remove();
						$("#"+id).append(data);
						setajax(id);
						$.cookie("openid["+id+"]", "1");
						
						}
					);
				}
				else
				{ 
				$("#lim"+(-1)*id+'-'+lim).append('<div class="ajax"></div');
				$.get('myadmin.php?list=adm&id='+id+'&ur='+ur+'&lim='+lim , 
					function(data)
						{ 
						$('.ajax').remove();
						$("#lim"+(-1)*id+'-'+lim).append(data);
						setajax("lim"+(-1)*id+'-'+lim);
						
						}
					);
				}
			
			
			
			}
		else
			{
			
			if (id<0){subid=$("#lim"+(-1)*id+'-'+lim+" div").remove();}			
			else{subid=$("#"+id+" div").remove()}
			$.cookie("openid["+id+"]", null);
			
			}
		
		
	}

function addate()
	{
	var currentTime = new Date();
	$("#adcont [name=data]").val(currentTime.getDate()+'.'+(currentTime.getMonth()+1)+'.'+currentTime.getFullYear() );
	}

function imgOff(obj) {

	obj.className='xx';

}



function truesize()

	{

		//wnead=831;
		w=$(window).width();
		if (!adminpanel)
			{			
			
			//h=$(window).height();
			pad= w/2 - Math.floor( w/2 )  ;
			//alert(w);
			if (pad)
				{
				$("html").width(w-1);
				$("body").width(w-1); 
				//$('#footer').append(w);
				}
				else
				{
				$("html").width(w);
				$("body").width(w); 
				}
			//$("html").height(h);
			blocktov_w=300 ;
			lm=404;
			num= Math.floor( (w-lm)/blocktov_w );
			pad= Math.floor ( ( (w-lm-blocktov_w*num)/(num*2) )-2 );
			$('#ct1.rezon #center .cll').remove();
			col=1;
			$('#ct1.rezon #center .mincart'). each (function() 		
				{
				if (col==num) 
					{
						$(this).after('<div class="cll"></div>');	
					}
					
				//pad=40;
				$(this).css('margin','0 '+pad+'px');
				col=col+1;
				if (col>num) 
					{
					col=1;
					}
				
				});				
				 
			
			}
		else
			{		
			
			popr=30; 			
			$('#outmenu').width(w-305);	
			$('.adm').height(screenHeight()-popr);
			$('#maintab').height(screenHeight()-20-popr);
			
			var nw=w-345;
			if (nw<595) {nw=558; }
			//ttl(nw);
			$('#adcont .inadcont').height(screenHeight()-35-popr).width(nw); 
			var hf=screenHeight()-220;
			$('#elm1_ifr').height(hf);
			$('.mceIframeContainer ').height(hf);
			$('#elm1_tbl').height('auto');
			
			}
			
		//$(''
		//alert(w);

	}

function ttl(t)
	{
		$('title').text(t);
	}

function minmax(minval,val,maxval)

	{

		if (val<minval)

			{

				return minval;

			}

		else if ( val>maxval)

			{

				return maxval;

			}

		else 

			{

				return val;

			}

	}
	
function colorpick()
	{
	$('.color input').ColorPicker({
					onSubmit: function(hsb, hex, rgb, el) {
						$(el).val(hex);
						$(el).ColorPickerHide();
					},

					onBeforeShow: function () {
						$(this).ColorPickerSetColor(this.value);
					}
				})

				.bind('keyup', function(){
					$(this).ColorPickerSetColor(this.value);
				});

	}


function parse1()
	{
		seleca=$('#parsform [name=seleca]').val();
		basehr=$('#parsform [name=name]').val();
		
		$('#parstable '+seleca).each( function() 		
				{                              
				href=basehr+$(this).attr('href')+$('#enter').text();
				$('#parsform [name=conturl]').append(href);				
				});
				
	}
	
function parse2()
	{
		
	enter=$('#parenter').text();
			tab=$('#partab').text()
			seleca=$('#parsform [name=seleca]').val();
			basehr=$('#parsform [name=name]').val();
			selecname=$('#parsform [name=selecname]').val();
			
			seln=selecname.split(enter);
			x=0;
	var sl=[];
	var dt=[];
	
	seln.forEach( function(item)
			{ 
			sel=item.split('==');
			//alert(sel[1] );
			sl[x]=sel[0];
			dt[x]=sel[1];
			$('#parsform [name=outpars]').append(sl[x]+tab);
                        //$('#parsform [name=outpars]').append('dsd');
			x++;
			});
	
			$('#parsform [name=outpars]').append(enter);
		
		
		
		
		x=0;
		$('#parstable .urls').each( function() 		
				{   
				x++;                           
				if (x<3)
					{
						href=$(this).text();
						//$('#parsform [name=conturl]').append(href);
						
						$.get( 'cont/'+href+'.htm', 
							function(data)
								{ 									
									$('#parstable').before('<div id="loaded">'+data+'</div>');	
									
									dt.forEach( function(d)
										{ 
										dat=$('#parstable '+d);
										$('#parsform [name=outpars]').append(dat+tab);
										
										});
									
								}
								);	
							
					}
				
							
				});
				
	}

function trim( str, charlist ) {
 
 charlist = !charlist ? ' \s ' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+$\^\:])/g, '$1');
 var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');
    return str.replace(re, '');
	}

$(document).ready(function()
//if (false)
	{
		
   		
		
		
		 
		
		
		$("#center a.group").fancybox( 

							  {

		'hideOnContentClick': false

			}

			);
		
		if (adminpanel )
			{
			colorpick();
			setajax();			
			ajaxform();
			setuploader();
				
			}
			
						
		$(window).resize( function()		
					{
						truesize(); 		
					});
							
		$("#center img.imgbox").each(function() 		
				{
				var largePath = $(this).attr("src");
				largePath2=largePath.split("cont/img").join("cont/img/big");
				$(this).wrap("<a class='imgbig' href='" + largePath2 + "'></a>");
				});						
		$("#center a.imgbig").fancybox(		
						{		
						'imageScale':		false,		
						'centerOnScroll': false 		
						}		
						);					
		
	
	
	
	//alert(1);
	
	truesize(); 
	
	setcheckval();
	setcheckident();
	
	setTimeout('truesize()',100);
	
	
				

	});





  

 



  

  



 
