$(document).ready(
	function()
	{

		var td1='';
		
		var td3='';
		var i;
		
		if ($.cookie('main_td1') || $.cookie('main_td1')=='') td1 = $.cookie('main_td1');
			else td1='news_box|expert_box|map_box'; 
			
		/*if ($.cookie('main_td2')  || $.cookie('main_td2')=='') td2 = $.cookie('main_td2');
			else td2='news1_box|projects_box|voite_box';*/

        /*if ($.cookie('main_td1') || $.cookie('main_td1')=='') td1 = $.cookie('main_td1');
			else td1='|expert_box|map_box'; 
			
		if ($.cookie('main_td2')  || $.cookie('main_td2')=='') td2 = $.cookie('main_td2');
			else td2='|news_box|news1_box|projects_box|voite_box';*/

		if ($.cookie('main_td3')  || $.cookie('main_td3')=='') td3 = $.cookie('main_td3');
			else td3='|team_box|gallery_box|tt2';


		/*
		boxs = new Array('expert_box','map_box','news_box','news1_box','projects_box','voite_box','team_box','gallery_box','tt2');

		for (n in boxs)
		{

			if (td1.indexOf(boxs[n]) != -1) {$('#main_td1').append($('#div_'+boxs[n]).html());$('#div_'+boxs[n]).remove();}
			if (td2.indexOf(boxs[n]) != -1) {$('#main_td2').append($('#div_'+boxs[n]).html());$('#div_'+boxs[n]).remove();}
			if (td3.indexOf(boxs[n]) != -1) {$('#main_td3').append($('#div_'+boxs[n]).html());$('#div_'+boxs[n]).remove();}

		}
		*/
		
		var temp = td1.split('|');
		for (i=0; i<temp.length;i++) {$('#main_td1').append($('#div_'+temp[i]).html());$('#div_'+temp[i]).remove();} 
		
		
		
		var temp = td3.split('|');
		for (i=0; i<temp.length;i++) {$('#main_td3').append($('#div_'+temp[i]).html());$('#div_'+temp[i]).remove();} 
		
		//pikaruk projects block main page
		$("#projectsMinus").click(function () {

			$("#ul_projects/li:visible:last").hide();
		   });

		  $("#projectsPlus").click(function () {
			$("#ul_projects/li:hidden:first").show();

	  		 });
		$("#ul_projects/li").click(function () {

		 	$("#project_title").html($(this).children('a').html());
			$("#project_link").attr('href',($(this).children('span').get(0).innerHTML));
			$("#project_preview").html($(this).children('span').get(1).innerHTML);

			if ($(this).children('span').get(2).innerHTML !='')
			{
				$("#project_img").attr( { src: "/i/thumbs/"+$(this).children('span').get(2).innerHTML, width: $(this).children('span').get(3).innerHTML, height: $(this).children('span').get(4).innerHTML});
				$("#project_img").show();

			} else
			{

				$("#project_img").hide();
			}
		});

		function acronim2(){
		$('#content acronym').mouseover(
				function () 
				   {
					$(this).css("position","relative");
					$(this).append('<span><b class="b_top"></b><b class="b_center">'+$(this).attr('titleserega')+'</b><b class="b_bottom"></b></span>'); 
				   }
				).mouseout (
				function ()
					{
						$(this).css("position","inherit");	
					 $(this).find('span').css('display','none');		
					}	   
				)
		/*
		setTimeout("acronim()",1000);
		alert("test");*/
		} 
		
		//pikaruk news block main page
		$("#newsMinus").click(function () {
			$("#ul_news/li:visible:last").hide();
		   });

		  $("#newsPlus").click(function () {
			$("#ul_news/li:hidden:first").show();

	  		 });

		$("#ul_news/li").click(function () {

		 	$("#news_link").html($(this).children('a').html());
			$("#news_date").html($(this).children('span').get(0).innerHTML);
			$("#news_preview").html($(this).children('span').get(4).innerHTML);
			acronim2();
			$("#news_link").attr('href',($(this).children('span').get(1).innerHTML));
			$("#news_comments").attr('href',($(this).children('span').get(1).innerHTML+'#comments'));
			$("#news_comments_post").attr('href',($(this).children('span').get(1).innerHTML+'#post'));
			$("#news_comments_count").html($(this).children('span').get(2).innerHTML);
			$("#news_tags").html($(this).children('span').get(3).innerHTML);

			if ($(this).children('span').get(5).innerHTML !='')
			{
				$("#news_img").attr( { src: "/i/thumbs/"+$(this).children('span').get(5).innerHTML, width: $(this).children('span').get(6).innerHTML, height: $(this).children('span').get(7).innerHTML});
				$("#news_img").show();

			} else
			{

				$("#news_img").hide();
			}
		});

		//pikaruk news1 block main page
		$("#news1Minus").click(function () {

			$("#ul_news1/li:visible:last").hide();
		   });

		  $("#news1Plus").click(function () {
			$("#ul_news1/li:hidden:first").show();

	  		 });

		$("#ul_news1/li").click(function () {

		 	$("#news1_title").html($(this).children('a').html());
			$("#news1_preview").html($(this).children('span').get(1).innerHTML);
			$("#news1_link").attr('href',($(this).children('span').get(0).innerHTML));

			if ($(this).children('span').get(2).innerHTML !='')
			{
				$("#news1_img").attr( { src: "/i/thumbs/"+$(this).children('span').get(2).innerHTML, width: $(this).children('span').get(3).innerHTML, height: $(this).children('span').get(4).innerHTML});
				$("#news1_img").show();

			} else
			{

				$("#news1_img").hide();
			}

		});

		// banzalik map
		$("#banzalikMap").click(function() {
			banzalikMaps();
		});

		//pikaruk team block main page
		COUNT_TEAM_PHOTO = $("#team_imgs/a");
		NUMBER_TEAM_PHOTO= 1;

		 $("#team_left").click(function () {
			if (document.getElementById('team_link'+NUMBER_TEAM_PHOTO) && document.getElementById('team_link'+(NUMBER_TEAM_PHOTO+4)))
			{
				document.getElementById('team_link'+NUMBER_TEAM_PHOTO).style.display='none';
				document.getElementById('team_link'+(NUMBER_TEAM_PHOTO+4)).style.display='';
				NUMBER_TEAM_PHOTO++;
			}

		});
         $("#team_right").click(function () {
				if (document.getElementById('team_link'+(NUMBER_TEAM_PHOTO-1)) && document.getElementById('team_link'+(NUMBER_TEAM_PHOTO+3)))
				{
					document.getElementById('team_link'+(NUMBER_TEAM_PHOTO-1)).style.display='';
					document.getElementById('team_link'+(NUMBER_TEAM_PHOTO+3)).style.display='none';
					NUMBER_TEAM_PHOTO--;
				}
		});

		$("#team_imgs/a").mousemove(function () {

 			 var lang11 = $("#team_fio").attr('onclick').substr(17,3);
			 $("#team_fio").text($(this).children('span').children("span").get(0).innerHTML);
			 $("#team_fio").attr('onclick',"window.location='"+lang11+$(this).children('span').children("span").get(6).innerHTML+"'");
			 $("#team_post").html($(this).children('span').children("span").get(1).innerHTML);
			 acronim2();
			 $("#team_preview").html($(this).children('span').children("span").get(2).innerHTML);
			 
			if ($(this).children('span').children("span").get(3).innerHTML !='')
			{
				$("#team_img").attr( { src: "/i/thumbs/"+$(this).children('span').children("span").get(3).innerHTML, width: $(this).children('span').children("span").get(4).innerHTML, height: $(this).children('span').children("span").get(5).innerHTML});
				$("#team_img").attr('onclick',"window.location='"+lang11+$(this).children('span').children("span").get(6).innerHTML+"'");
				$("#team_img").show();
			} else $("#team_img").hide();


	   });



		//pikaruk photogallery block main page
		COUNT_GALLERY_PHOTO = $("#team_imgs/a");
		NUMBER_GALLERY_PHOTO= 1;

		 $("#gallery_left").click(function () {
			if (document.getElementById('gallery_link'+NUMBER_GALLERY_PHOTO) && document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO+4)))
			{
				document.getElementById('gallery_link'+NUMBER_GALLERY_PHOTO).style.display='none';
				document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO+4)).style.display='';
				NUMBER_GALLERY_PHOTO++;
			}

		});
         $("#gallery_right").click(function () {
				if (document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO-1)) && document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO+3)))
				{
					document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO-1)).style.display='';
					document.getElementById('gallery_link'+(NUMBER_GALLERY_PHOTO+3)).style.display='none';
					NUMBER_GALLERY_PHOTO--;
				}
		});

		$("#gallery_imgs/a").click(function () {


			 $("#gallery_title").html($(this).children('span').children("span").get(0).innerHTML);
			$("#gallery_dsc").html($(this).children('span').children("span").get(1).innerHTML);
			$("#gallery_link").attr('href',$(this).children('span').children("span").get(5).innerHTML);
			if ($(this).children('span').children("span").get(2).innerHTML !='')
			{
				$("#gallery_img").attr( { src: "/i/thumbs/"+$(this).children('span').children("span").get(2).innerHTML, width: $(this).children('span').children("span").get(3).innerHTML, height: $(this).children('span').children("span").get(4).innerHTML});
				$("#gallery_img").show();
			} else $("#gallery_img").hide();


	   });

		//pikaruk expert question block main page
		$("#questMinus").click(function () {


			$("#ul_quest/li:visible:last").hide();
		   });

		  $("#questPlus").click(function () {
			$("#ul_quest/li:hidden:first").show();

	  		 });

		 $("a[@id^=quest_a]").click(function () {

			var str =$(this).attr('id');
			var id= str.substr(7);

			  $("span[@id^=quest_span]").hide();
			  $("#quest_span"+id).show();
	  		 });


       // banzalik action jquery

	   //show gray div and autorization popup
	     $("#loginLinkToogle").click(function () {
			toogleAutunoficaton();

	   });

	   //hide gray div and autorization popup
	   $("#ui-gray").click(function () {
			toogleAutunoficaton();
			});





		// Toggle Single Portlet
		/*$('a.toggle').click(function()
            {
               var block = $(this).parent('div').parent('div').parent('div').next('div');
               block.addClass('iLoveIe');
               block.slideToggle('fast', function (){

                    var img = $(this).prev('div').children('div').children('div').children('a').children('img');

                    if(img.attr('src') == '/images/openClose.png')
                        img.attr('src', '/images/openClose2.png');
                    else
                        img.attr('src', '/images/openClose.png');
                    $(this).removeClass('iLoveIe');

                }

                );
                return false;
            }
        );

        $('a.toggle2').click(function()
			{
//				alert($(this).parent('div').parent('div').parent('div').next('div').id)
                var block = $(this).parent('div').parent('div').parent('div').next('div').next('div');
                block.addClass('iLoveIe');
//                alert(block.attr('class'));
                block.slideToggle('fast', function (){

                    var img = $(this).prev('div').prev('div').children('div').children('div').children('a').children('img');
                    if(img.attr('src') == '/images/openClose.png')
                        img.attr('src', '/images/openClose2.png');
                    else
                        img.attr('src', '/images/openClose.png');
                    $(this).removeClass('iLoveIe');
//                    alert(block.attr('class'));

                }

                );
				return false;
			}
		);*/

		// Invert All Portlets
		$('a#all_invert').click(function()
			{
				$('div.blueBoxContent').toggle();
				return false;
			}
		);

		// Expand All Portlets
		$('a#all_expand').click(function()
			{
				$('div.blueBoxContent:hidden').show();
				return false;
			}
		);

		// Collapse All Portlets
		$('a#all_collapse').click(function()
			{
				$('div.blueBoxContent:visible').hide();
				return false;
			}
		);

		// Open All Portlets
		$('a#all_open').click(function()
			{
				$('div.box:hidden').show();
				$('a#all_open:visible').hide();
				$('a#all_close:hidden').show();
				return false;
			}
		);

		// Close All Portlets
		$('a#all_close').click(function()
			{
				$('div.box:visible').hide();
				$('a#all_close:visible').hide();
				$('a#all_open:hidden').show();
				return false;
			}
		);

		// Controls Drag + Drop
		//$('#columns td').Sortable(
//			{
//				accept: 'box',
//				helperclass: 'sort_placeholder',
//				opacity: 0.7,
//				tolerance: 'intersect'
//			}
//		);

        $('#columns td').Sortable(
            {
                accept: 'box',
                helperclass: 'sortHelper',
                tolerance: 'intersect',
                ghosting: false,
//                opacity: 0.7,
              //  activeclass :     'sortableactive',
               // hoverclass :     'sortablehover',
                handle: 'div.blueBoxTitle',
//                tolerance: 'pointer'
              //  onChange : function(ser)
              //  {
             //       alert(1)
             //   },
                onStart : function()
                {
                   $.iAutoscroller.start(this, document.getElementsByTagName('body'));
                },
                onStop : function()
                {
                    $.iAutoscroller.stop();
                  	var td1='';
					
					var td3='';
					// запоминание расположения в куках
					//var elts = $('#main_td1').children('div');
					//for (var i=0; i< elts.length; i++) td1 =td1+'|'+elts [i].id;
					//$.cookie('main_td1', td1, { path: '/', expires: 0 });

					

					//var elts = $('#main_td3').children('div');
					//for (var i=0; i< elts.length; i++) td3 =td3+'|'+elts [i].id;
					//$.cookie('main_td3', td3, { path: '/', expires: 0 });



                }
            }
        );


	}
);

// banzalik functions box
function toogleAutunoficaton ()
{
	if ($.browser.msie)
	{
       	   with ($('div.ui-gray') ){
           height($(document.body).height()+7);
           width($(document.body).width());
           toggle();
       }
	  $('div.authoriz').toggle();
	}
	else
	{
	  $('div.authoriz').slideToggle('fast');
       	   with ($('div.ui-gray') ){
           height($(document.body).height()+7);
           width($(document.body).width());
           toggle();
       }
	}
}
function banzalikMaps(){
	var width=$("#mapBg").width();
	var height=$("#mapBg").height();

	// alert(width);
	// alert(height);
	$("#mapClick").css({ "width":width, "height":height, "position":"absolute", "z-index": "9999", "top":"0", "left":"0", "display":"block" });
	$("#mapFlash").css({ "width":800, "height":500, "z-index": "99999", "top":"50%", "left":"50%", "display":"block", "margin-left":"-400px" });
	$("#mapClick").click(function() {
		window_close();
	});

}

function window_close(){
		$("#mapClick").css({ "width":0, "height":0, "position":"absolute", "z-index": "0", "top":"0", "left":"0", "display":"none" });
		$("#mapFlash").css({ "width":0, "height":0, "z-index": "0", "top":"0", "left":"0", "display":"block", "margin-left":"-400px" });
}

