window.addEvent('domready', function () {


    //services top menu

    if ($('SlideItMoo_outer') != null) {

        /* thumbnails example , div containers */
        new SlideItMoo({
            overallContainer: 'SlideItMoo_outer',
            elementScrolled: 'SlideItMoo_inner',
            thumbsContainer: 'ServicesMenu',
            itemsVisible: 4,
            elemsSlide: 3,
            duration: 300,
            itemsSelector: '.menu_block',
            itemWidth: 280,
            showControls: 1,
            startIndex: 5,
            autoSlide: false,
            mouseWheelNav: true,
            onChange: function (index) {

            }

        });


        var currentOpenedMenu = null;
        var currentActiveBlock = null;

        var menu_blocks = $$("div#ServicesMenu .menu_block");

        var setMenuBlockState = function (element, hover) {

            if (element == null)
                return;

            if (hover) {
                element.setStyles({
                    'background-color': '#f5f4f4',
                    'border': '1px solid #cccccc',
                    'margin': '4px 14px 14px 14px'
                });
            }
            else {
                element.setStyles({
                    'background-color': 'transparent',
                    'border-width': '0px',
                    'margin': '5px 15px 15px 15px'
                });
            }

        }

        menu_blocks.addEvents({
            'mouseenter': function () {
                setMenuBlockState(currentActiveBlock, false);
                currentActiveBlock = this;
                setMenuBlockState(currentActiveBlock, true);

                var menu_block = this.getElement('.ddbtn');
                if (menu_block != null) {
                    menu_block.setStyles({ 'display': 'block' });
                }



                if (currentOpenedMenu != null) {
                    currentOpenedMenu.setStyles({ 'display': 'none' });
                }

            },
            'mouseleave': function () {
                if (this.getElement('.ddbtn') != null)
                    this.getElement('.ddbtn').setStyles({ 'display': 'none' });

                if (currentOpenedMenu == null) {
                    setMenuBlockState(currentActiveBlock, false);
                }
            }
        });


        $('SlideItMoo_outer').addEvent(
                        'mouseleave', function () {
                            if (currentOpenedMenu == null) {
                                setMenuBlockState(currentActiveBlock, false);
                            }
                        });

        $('SlideItMoo_outer').addEvent(
                        'mouseover', function () {
                            if (currentOpenedMenu != null) {
                                currentOpenedMenu.setStyles({ 'display': 'none' });
                                currentOpenedMenu = null;
                            }
                        });

        $('ServicesMenu').addEvent(
                    'mouseover', function () {
                        if (currentOpenedMenu != null) {
                            currentOpenedMenu.setStyles({ 'display': 'none' });
                            currentOpenedMenu = null;
                        }
                    });

        $('SlideItMoo_inner').addEvent(
                    'mouseover', function () {
                        if (currentOpenedMenu != null) {
                            currentOpenedMenu.setStyles({ 'display': 'none' });
                            currentOpenedMenu = null;
                        }
                    });



        menu_blocks.each(function (element) {
            var ddm_btn = element.getElement('.ddbtn');

            var idOfBlock = element.get('id');
            var ddMenu = $(idOfBlock.replace("category_", "ServicesOfCat_"));

            if (ddm_btn != null && ddMenu != null) {
                ddm_btn.addEvent(
                    'click', function () {
                        if (ddMenu.getStyle('display') == 'none') {
                            var ddMenuTop = element.getCoordinates().top + element.getCoordinates().height - 2;
                            var ddMenuLeft = 0;
                            var elemantCoordinates = element.getCoordinates();
                            var qqq = element.getCoordinates().left + ddMenu.getDimensions({ computeSize: true }).width + 30;

                            if (document.body.clientWidth < qqq)
                                ddMenuLeft = elemantCoordinates.left + elemantCoordinates.width - ddMenu.getDimensions({ computeSize: true }).totalWidth;
                            else
                                ddMenuLeft = element.getCoordinates().left/*- 14*/;

                            ddMenu.setStyles({ 'left': ddMenuLeft });
                            ddMenu.setStyles({ 'top': ddMenuTop + 'px' });
                            ddMenu.setStyles({ 'display': 'block' });

                            currentActiveBlock = element;

                            setMenuBlockState(currentActiveBlock, true);

                            currentOpenedMenu = ddMenu;
                        }
                        else {
                            ddMenu.setStyles({ 'display': 'none' });
                            currentOpenedMenu = null;
                        }

                    });
            }

            if (ddMenu != null) {
                ddMenu.addEvent(
                    'mouseleave', function () {
                        ddMenu.setStyles({ 'display': 'none' });
                        setMenuBlockState(currentActiveBlock, false);
                        currentOpenedMenu = null;
                    });
            }
        });
    }
    // end services top menu



    var changerShowFirst = true;

    var displayChanger = function () {
        if ($('changer_first') != null && $('changer_second') != null) {
            if (changerShowFirst) {

                $('changer_first').style.display = 'none';
                $('changer_second').style.display = 'block';
                changerShowFirst = false;
            }
            else {
                $('changer_second').style.display = 'none';
                $('changer_first').style.display = 'block';
                changerShowFirst = true;
            }
        }
    };
    var myTimerChanger = displayChanger.periodical(5000);



    var withoutbusiness = $('withoutbusiness');
    if (withoutbusiness != null) {
        var business = 0;

        withoutbusiness.addEvent('click', function () {
            if (business == 0) {
                $('withoutbusiness1').style.visibility = 'visible';
                $('withoutbusiness1').style.display = 'block';

                if ($('withbusiness_info') != null) {
                    $('withbusiness_info').style.visibility = 'hidden';
                    $('withbusiness_info').style.display = 'none';
                }

                if ($('withbusiness_foto') != null) {
                    $('withbusiness_foto').style.visibility = 'hidden';
                    $('withbusiness_foto').style.display = 'none';
                }
                business = 1;
            }
            else {
                $('withoutbusiness1').style.visibility = 'hidden';
                $('withoutbusiness1').style.display = 'none';

                if ($('withbusiness_info') != null) {
                    $('withbusiness_info').style.visibility = 'visible';
                    $('withbusiness_info').style.display = 'block';
                }

                if ($('withbusiness_foto') != null) {
                    $('withbusiness_foto').style.visibility = 'visible';
                    $('withbusiness_foto').style.display = 'block';
                }
                business = 0;
            }

        });

    }


    var list = $$('#city li');
    list.each(function (element) {

        var firstDiv = element.getElement('div');

        element.addEvents({
            'mouseenter': function () {
                firstDiv.style.display = 'block';
                firstDiv.fade('in');
            },
            'mouseleave': function () {
                firstDiv.style.display = 'none';
                firstDiv.fade('out');
            }
        });


    });

    //    $('city').addEvent('mouseleave',
    //			function () {
    //			    $$('#city div').each(function (element) {
    //			        var mySlide = new Fx.Slide(element);
    //			        mySlide.hide();
    //			    });
    //			});
    //*******************************************************
    //   level content blocks
    //*******************************************************
    //var lst = $$('#qq div');
    //var maxDivHeight = 300;
    //lst.each(function(element) {
    //		if(element.clientHeight > maxDivHeight)
    //			maxDivHeight = element.clientHeight;
    ////		alert(element.clientHeight);
    //				  });
    //
    //lst.each(function(element) {
    //				  //element.setProperty('background-color', '#000000');	
    //				 var fx = new Fx.Styles(element, {duration:500, wait:false});
    // 				fx.start({	'height': maxDivHeight	});
    //	
    //				
    //				   });

    //*******************************************************
    //   
    //*******************************************************
    var list = $$('#nav_bar li');
    list.each(function (element) {
        var links = element.getElement('ul.links');

        if (links != null)
            links.style.display = 'none';

        var fx = new Fx.Tween(element);

        element.addEvent('mouseenter',
		    function () {
		        fx.cancel();
		        fx.start('background-color', '#cec5bd');
		        fx.start('color', '#ff8');
		        if (links != null) {
		            links.style.display = 'block';
		            //ddMenu.slideIn();

		        }
		    });

        element.addEvent('mouseleave',
			function () {
			    fx.cancel();
			    fx.start('background-color', '#edeceb');
			    fx.start('color', '#888');
			    if (links != null) {
			        links.style.display = 'none';
			        //ddMenu.slideOut();

			    }
			});
    });

    //*******************************************************
    //   Top toggler menu with banners
    //*******************************************************


    //var mySlide2 = new Fx.Slide('test2');
    //	$('toggle2').addEvent('click', function(e){
    //	e = new Event(e);
    //	mySlide2.toggle();
    //	e.stop();
    //	});

    //*******************************************************
    //   Services menu
    //*******************************************************

    //create our Accordion instance
    //var accordion = new Accordion($('accordion'), $$('#category_list li'), $$('#service_list ul'), {
    //		opacity: false,
    //		onActive: function(toggler, element){
    //			//toggler.setStyle('color', '#ff3300');
    //		},
    //	 
    //		onBackground: function(toggler, element){
    //			//toggler.setStyle('color', '#222');
    //		}
    //	});

    Accordion.implement({
        addSection: function (toggler, element, pos) {
            toggler = $(toggler);
            element = $(element);
            var test = this.togglers.contains(toggler);
            var len = this.togglers.length;
            this.togglers.include(toggler);
            this.elements.include(element);
            if (len && (!test || pos)) {
                pos = $pick(pos, len - 1);
                toggler.injectBefore(this.togglers[pos]);
                element.injectAfter(toggler);
            } else if (this.container && !test) {
                toggler.inject(this.container);
                element.inject(this.container);
            }
            var idx = this.togglers.indexOf(toggler);
            toggler.addEvent('mouseover', this.display.bind(this, idx));
            if (this.options.height) element.setStyles({ 'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none' });
            if (this.options.width) element.setStyles({ 'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none' });
            element.fullOpacity = 1;
            if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
            if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
            element.setStyle('overflow', 'hidden');
            if (!test) {
                for (var fx in this.effects) element.setStyle(fx, 0);
            }
            return this;
        }
    });

    var selectedElement = -1;

    if ($('services_selected_category') != null && $('services_selected_category') != "")
        var selectedElement = $('services_selected_category').value;

    var myAccordion = new Accordion($('accordion'), 'li.toggler', 'div.cat_element', {
        opacity: true,
        display: selectedElement,
        mode: 'horizontal',
        onActive: function (toggler, element) {
            toggler.setStyle('color', '#41464D');
        },
        onBackground: function (toggler, element) {
            toggler.setStyle('color', '#528CE0');
        }
    });

    if ($('services_selected_category') != null && $('services_selected_category') != "")
        myAccordion.display(selectedElement);



});




var oldMenu = null;
var oldMenuId = -1;
function showsubmenu(id)
 {
	 if(oldMenu != null) 
 		oldMenu.style.display="none";
	 else
	 {
		document.getElementById('anons'+oldMenuId).style.display="none"; 
	 }
	
/*	if(oldMenuId > 0)
	{
 		
	}
	else
	alert("adasdasdas");
*/	
	
		

	submenu = document.getElementById('anons'+id);

   submenu.style.display="block";

	oldMenu = submenu ;
	//oldMenuId = id;

}

