var timeout;
var menu_array = [];
var menu_proj = [];
var imag_array = [];
var m = [];


function start(){
    correctBrowser();
    Cufon.replace('.l_nav h4', {fontFamily: 'AGLettericaCondensed'});
    Cufon.replace('.tel h5', {fontFamily: 'AGLettericaCondensed'});
    Cufon.replace('.ttl h3', {fontFamily: 'AGLettericaCondensed'});
    Cufon.replace('.nav a',   {fontFamily: 'AGLettericaCondensed'});
    Cufon.replace('.zabr a',   {fontFamily: 'AGLettericaCondensed', hover:true});
    Cufon.replace('.zabr h3',  {fontFamily: 'AGLettericaExtraCompressed'});
    Cufon.replace('.zabr h4',  {fontFamily: 'AGLettericaCondensed'});    
    Cufon.replace('.cont h2',  {fontFamily: 'AGLettericaExtraCompressed'});
    if ($$('.news')) Cufon.replace('.news h2',  {fontFamily: 'AGLettericaExtraCompressed'});
    Cufon.replace('.ta a',  {fontFamily: 'AGLettericaCondensed', hover: true});
    Cufon.replace('.copy',  {fontFamily: 'AGLettericaCondensed', hover: true});
    Cufon.replace('.copy strong',  {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.dl_list dt', {fontFamily: 'AGLettericaCondensed'});
    Cufon.replace('.dl_list dd h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.r_items h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.r_items h4', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.otz_list dt', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.pages a', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.pages2 a', {fontFamily: 'AGLettericaCondensed', hover: true});
    Cufon.replace('.form_send span', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.bron_send span', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.rib_send span', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.imag_numb', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.d_td_text h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.bron h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.bron2 h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.t_items h2', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.item_l a', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.leave_comment h3', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.leave_comment a', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.list_comments dt', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.comment_form h4', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.comment_form_in h5', {fontFamily: 'AGLettericaExtraCompressed', hover: true});
    Cufon.replace('.partners h3', {fontFamily: 'AGLettericaCondensed', hover: true});
    Cufon.replace('.float_ab h3',  {fontFamily: 'AGLettericaExtraCompressed'});
    
    menu_array = $$('.act');
    menu_proj = $$('.navs');
    imag_array = $$('.imag_numb');
    m = $$('.rat_in');

    if ($$('.titls')) startTitls();
    if ($$('.imag')) startImag();
    if ($$('.domiki')) startDomik();
    if ($('bron')) startInSlide();
    if ($$('.pages2')) startNavPage();
    if ($$('.item_l')) startDoska();
    if ($$('.foot_links')) footOver();
    if ($$('.imagi')) re();
    if ($$('.weth_m')) startWeather();
    if ($$('.partners')) startPart();
    if ($$('.leave_comment')) startSlideComment();
    

     

    initMultiBox = new multiBox({
        mbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
        container: $(document.body),//where to inject multiBox
        descClassName: false,//the class name of the description divs
        path: './Files/',//path to mp3 and flv players
        useOverlay: true,//use a semi-transparent background. default: false;
        addDownload: false,//do you want the files to be downloadable?
        pathToDownloadScript: false,//if above is true, specify path to download script (classicASP and ASP.NET versions included)
        addRollover: false,//add rollover fade to each multibox link
        addOverlayIcon: true,//adds overlay icons to images within multibox links
        showControls: true,//adds overlay icons to images within multibox links
        showNumbers: false,
        addChain: false,//cycle through all images fading them out then in
        recalcTop: false,//subtract the height of controls panel from top position
        addTips: false,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
        clos: 'close2'
    });
    initMultiBox = new multiBox({
        mbClass: '.m',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
        container: $(document.body),//where to inject multiBox
        descClassName: false,//the class name of the description divs
        path: './Files/',//path to mp3 and flv players
        useOverlay: true,//use a semi-transparent background. default: false;
        addDownload: false,//do you want the files to be downloadable?
        pathToDownloadScript: false,//if above is true, specify path to download script (classicASP and ASP.NET versions included)
        addRollover: false,//add rollover fade to each multibox link
        addOverlayIcon: true,//adds overlay icons to images within multibox links
        showControls: true,//adds overlay icons to images within multibox links
        showNumbers: false,
        addChain: false,//cycle through all images fading them out then in
        recalcTop: false,//subtract the height of controls panel from top position
        addTips: false,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
        clos: 'close'
    });
    
    initMultiBox = new multiBox({
        mbClass: '.mbvideo',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
        container: $(document.body),//where to inject multiBox
        descClassName: false,//the class name of the description divs
        path: rootPath,//path to mp3 and flv players
        useOverlay: true,//use a semi-transparent background. default: false;
        addDownload: false,//do you want the files to be downloadable?
        pathToDownloadScript: false,//if above is true, specify path to download script (classicASP and ASP.NET versions included)
        addRollover: false,//add rollover fade to each multibox link
        addOverlayIcon: false,//adds overlay icons to images within multibox links
        showControls: true,//adds overlay icons to images within multibox links
        showNumbers: false,
	movieWidth: 360,//default width of movie
	movieHeight: 288,//default height of movie
        addChain: false,//cycle through all images fading them out then in
        recalcTop: false,//subtract the height of controls panel from top position
	clos: 'close',
        addTips: false//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
    });

    
    if(Browser.Engine.trident){
    	$$('.mb10').each(function(el){
    		el.addEvent('click', function(){
    			window.open(this.href, null, "height=390,width=900,status=yes,toolbar=no,menubar=no,location=no");
    			return false;
    		});
    	});
    	$$('.mb11').each(function(el){
    		el.addEvent('click', function(){
    			window.open(this.href, null, "height=390,width=900,status=yes,toolbar=no,menubar=no,location=no");
    			return false;
    		});
    	});
    }else{
    initMultiBox = new multiBox({
        mbClass: '.mb10',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
        container: $(document.body),//where to inject multiBox
        //container: $('bodyid'),
        descClassName: false,//the class name of the description divs
        path: './Files/',//path to mp3 and flv players
        useOverlay: true,//use a semi-transparent background. default: false;
        addDownload: false,//do you want the files to be downloadable?
        pathToDownloadScript: false,//if above is true, specify path to download script (classicASP and ASP.NET versions included)
        addRollover: false,//add rollover fade to each multibox link
        addOverlayIcon: true,//adds overlay icons to images within multibox links
        showControls: false,//adds overlay icons to images within multibox links
        showNumbers: false,
        addChain: false,//cycle through all images fading them out then in
        recalcTop: false,//subtract the height of controls panel from top position
        addTips: false,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
        clos: 'close3'
    });
    
    hid_mb = new multiBox({
        mbClass: '.mb11',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)
        container: $(document.body),//where to inject multiBox
        descClassName: false,//the class name of the description divs
        path: './Files/',//path to mp3 and flv players
        useOverlay: true,//use a semi-transparent background. default: false;
        addDownload: false,//do you want the files to be downloadable?
        pathToDownloadScript: false,//if above is true, specify path to download script (classicASP and ASP.NET versions included)
        addRollover: false,//add rollover fade to each multibox link
        addOverlayIcon: true,//adds overlay icons to images within multibox links
        showControls: false,//adds overlay icons to images within multibox links
        showNumbers: false,
        addChain: false,//cycle through all images fading them out then in
        recalcTop: false,//subtract the height of controls panel from top position
        addTips: false,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
        clos: 'close3'
    });
    }
    


    
    if(Browser.Engine.webkit){
        $$('.n_lnk').setStyles({'display': 'inline-block', 'margin':'0 0 5px 0'});
    }
    if ($$('.menu')) startMenu();
}

function footOver(){
    $each($$('.foot_links a'), function(element, i){
        element.addEvent('mouseenter', function(){
            var reg = /(.*?)\.gif/;
            var ima = this.getElement('img');
            ima.src = ima.src.replace(reg, "$1_.gif");
        });
        element.addEvent('mouseleave', function(){
            var reg = /(.*?)\_.gif/;
            var ima = this.getElement('img');
            ima.src = ima.src.replace(reg, "$1.gif");
        });
    });
}

function startTitls(){
    $each($$('.titls img'), function(element, i){
        element.addEvent('mouseenter', function(){
            var reg = /(.*?)\.gif/;
            this.src = this.src.replace(reg, "$1_.gif");
        });
        element.addEvent('mouseleave', function(){
            var reg = /(.*?)\_.gif/;
            this.src = this.src.replace(reg, "$1.gif");
        });
   });
}

function startDoska(){
    $each($$('.item_img'), function(element, i){
        element.addEvent('mouseenter', function(){
            this.style.backgroundColor = '#fffe8c';
        });
        element.addEvent('mouseleave', function(){
            this.style.backgroundColor = '';
        });
   });
   var rat = $$('.rat_in');
   
   $each($$('.vote'), function(el, z){
        el.addEvent('mouseenter', function(){
            var reg = /(.*?)\.gif/;
            if (Browser.Engine.trident){
                rat[z].style.backgroundColor = '#fffe8c';
                this.parentNode.parentNode.childNodes[0].style.backgroundColor = '#fffe8c';
            }else{
                //rat[z].style.backgroundColor = '#fffe8c';
                m[z].style.backgroundColor = '#fffe8c';
                this.parentNode.parentNode.childNodes[1].style.backgroundColor = '#fffe8c';
            }
            
            this.childNodes[0].childNodes[0].src = this.childNodes[0].childNodes[0].src.replace(reg, "$1_.gif");
            
        });
        el.addEvent('mouseleave', function(){
            var reg = /(.*?)\_.gif/;
            if (Browser.Engine.trident){
                this.parentNode.childNodes[0].style.backgroundColor = '';
                rat[z].style.backgroundColor = '';
            }else{
                rat[z].style.backgroundColor = '';
            }
            this.childNodes[0].childNodes[0].src = this.childNodes[0].childNodes[0].src.replace(reg, "$1.gif");
        });
   });
   
   $each($$('.rat_in'), function(elem, w){
        elem.addEvent('mouseenter', function(){
            this.style.backgroundColor = '#fffe8c';
            if (Browser.Engine.trident){
                this.parentNode.parentNode.childNodes[0].style.backgroundColor = '#fffe8c';
            }else{
                this.style.backgroundColor = '#fffe8c';
                //m[w].style.backgroundColor = '#fffe8c';
                this.parentNode.parentNode.childNodes[1].style.backgroundColor = '#fffe8c';
            }            
        });
        elem.addEvent('mouseleave', function(){
            this.style.backgroundColor = '';
            if (Browser.Engine.trident){
                this.parentNode.parentNode.childNodes[0].style.backgroundColor = '';
            }else{
                rat[w].style.backgroundColor = '';
                this.parentNode.parentNode.childNodes[1].style.backgroundColor = '';
            }
        });
   });
}

function startInSlide(){
    myAccordion = new Accordion($$('.toggle'), $$('.slide'), {
            onActive: function(toggler, slider){
                if (Browser.Engine.trident) slider.setStyle('display', 'block');
                //slider.setStyle('padding-bottom', '20px');
            },
            onBackground: function(toggler, slider){
                if (Browser.Engine.trident) slider.setStyle('display', 'none');
            },
            onComplete: function(){
                
            },

            opacity: 0,
            display: false,
            alwaysHide: true
    });
}
function re(){
    $each($$('.imagi img'), function(element, i){
        
        element.addEvent('mouseenter', function(){
            
            this.parentNode.parentNode.style.backgroundColor = '#fff';
            
        });
        element.addEvent('mouseleave', function(){
            this.parentNode.parentNode.style.backgroundColor = '';
            
        });
    });
}
function startImag(){
    $each($$('.imag img'), function(element, i){
        element.addEvent('mouseenter', function(){
            this.parentNode.parentNode.setStyle('background-color', '#fff');
            
        });
        element.addEvent('mouseleave', function(){
            if (!element.parentNode.parentNode.hasClass('cur_dom')) this.parentNode.parentNode.setStyle('background-color', '');
        });
   });
   
   
    if ($$('.imag_numb')){
        $each($$('.imag_numb'), function(element, i){
            element.addEvent('mouseenter', function(){
                $('im'+i).parentNode.setStyle('background-color', '#fff');
                this.parentNode.setStyle('background-color', '#fff');
            });
            element.addEvent('mouseleave', function(){
                if (!element.hasClass('cur_dom')) this.parentNode.parentNode.setStyle('background-color', '');
            });
       });
   }
}
function startDomik(){
    $each($$('.imag'), function(element, i){
        if (!element.hasClass('cur_dom') && element.hasClass('domiki')) {
             $('im'+i).setStyle('opacity', .5);
        }
        
        element.addEvent('mouseenter', function(){
            if (!element.hasClass('cur_dom')) {
                this.setStyle('background-color', '#fff');
                this.childNodes[0].style.backgroundColor = '#fff';
                this.childNodes[0].style.display = 'block';
                //alert(this.className)
            }
            if (element.hasClass('domiki')) $('im'+i).setStyle('opacity', 1);
        });
        element.addEvent('mouseleave', function(){
            if (!element.hasClass('cur_dom')){ 
                this.setStyle('background-color', '');
                this.childNodes[0].style.backgroundColor = '';
                this.childNodes[0].style.display = 'none';
                if (element.hasClass('domiki')) $('im'+i).setStyle('opacity', .5);
            }
            
        });
   });
   
   
    if ($$('.imag_numb')){
        $each($$('.imag_numb'), function(element, i){
            element.addEvent('mouseenter', function(){
                $('im'+i).parentNode.parentNode.setStyle('background-color', '#fff');
                this.parentNode.setStyle('background-color', '#fff');
            });
            element.addEvent('mouseleave', function(){
                if (!element.hasClass('cur_dom')) this.parentNode.parentNode.parentNode.setStyle('background-color', 'transparent');
            });
            element.addEvent('click', function(){
                var a = this.parentNode.getElement('a').href;
                document.location.href = a;
            });
       });
   }
}

function startNavPage(){
    $each($$('.pages2 a'), function(element, i){
        element.addEvent('click', function(){
            var ima = $('domik_images').getElement('img');
            var nim = $('img_name_'+i).value;
            ima.setAttribute('src', 'user.img/'+nim);
            remClass()
            this.addClass('page2');
            Cufon.replace('.pages2 a', {fontFamily: 'AGLettericaCondensed', hover: true});
        });
   });
}

function remClass(){
	$each($$('.pages2 a'), function(element){
		element.removeClass('page2');
		
	});
	return true;
}

function showTab(url){
    var ob = $('over');
    var fla = $(url);
    ob.setStyles({
        'display': 'block', 
        'opacity': .8,
        height: window.getScrollSize().y
    });
    fla.setStyle('display', 'block');
    
    var w = $(window).getWidth();
    //w = w-400;
    w=900;
    fla.setStyles({'width': w+'px', 'height': 440, 'background': '#afd898'});
    
    var top = (($(window).getHeight() - fla.getHeight()) / 2) + window.getScroll().y;
    var left = ($(window).getWidth() - fla.getWidth()) / 2;
    
    fla.setStyles({
        top: top,
        left: left
    });
    
    ob.addEvent('click', function(){
        ob.setStyles({'display': 'none', 'opacity': 0});
        fla.setStyle('display', 'none');
    });
}
function closeBox(url){
    var ob = $('over');
    ob.setStyles({'display': 'none', 'opacity': 0});
    
    if(url=='all'){
    	var fla = $('tab0');
    	var fla1 = $('tab1');
    
	fla.setStyle('display', 'none');
    	fla1.setStyle('display', 'none');
    }else{
	var fla = $(url);
	fla.setStyle('display', 'none');
    }
    
    
}

function correctBrowser(){
   var ob = $('container');
   var ob1 = $('container2');
   var ob2 = $('container3');
   var ob3 = $('container4');
   var style = '0 0 0 1px';
   if(Browser.Engine.trident) style = '0 0 0 2px'; 
   if(Browser.Engine.gecko) style = '0 0 0 2px'; 
   if(Browser.Engine.webkit || Browser.Engine.presto) style = '0 0 0 3px'; 
   
   if ($('container')) if(style) ob.setStyle('padding',style); 
   if ($('container2')) if(style) ob1.setStyle('padding',style); 
   if ($('container3')) if(style) ob2.setStyle('padding',style); 
   if ($('container4')) if(style) ob3.setStyle('padding',style); 
    
}

function startMenu(){
   $each(menu_array, function(element, i){
        element.addEvent('mouseenter', function(){
             if(timeout) clearTimeout(timeout);
             hideAllS(i);
             
        });
        element.addEvent('mouseleave', function(){
             timeout = setTimeout('hideAllS();', 90);
             
        });
   });
   
   $each(menu_proj, function(element, i){ 
         element.addEvent('mouseenter', function(){
             if(timeout) clearTimeout(timeout);
             hideAllS(i);
         });
         element.addEvent('mouseleave', function(){
             timeout = setTimeout('hideAllS();', 40);
         });
             
   });
   
}
function hideAllS(act){
    $each(menu_array, function(element, i){
        if(menu_proj[i]) {
        if(act !== false && act==i) {
             menu_proj[i].setStyle('display', 'block');
            element.setStyle('background-color', '#2f6312');
        } else {
            menu_proj[i].setStyle('display', 'none');
            element.setStyle('background-color', '');
        } 
        }
    });
}


function startWeather(){
    $each($$('.foot_links a'), function(element, i){ 
         element.addEvent('mouseenter', function(){
            $('v'+i).setStyle('display', 'block');
            if(Browser.Engine.webkit) $('v'+i).setStyle('left', '615px');
            if(Browser.Engine.presto) $('v'+i).setStyle('left', '616px');
            if(Browser.Engine.trident5) $('v'+i).setStyle('left', '613px');
            if(Browser.Engine.trident4) $('v'+i).setStyles({'left': '613px', 'bottom': '159px'});
         });
         element.addEvent('mouseleave', function(){
            $('v'+i).setStyle('display', 'none');
         });
             
   });   
}

function hideAllW(act){
    $each($$('.foot_links a'), function(element, i){
        if(act !== false && act==i) {
            
            
        } else {
            
        } 
    });
}

function startPart(){
    $each($$('.partners img'), function(element, i){
        element.setStyle('opacity', .5);
        
        element.addEvent('mouseenter', function(){
            this.setStyle('opacity', 1);
        });
        element.addEvent('mouseleave', function(){
            this.setStyle('opacity', .5);
        });
    });
}

function startSlideComment(){
    myAccordion = new Accordion($$('.leave_comment'), $$('.comment_form'), {
            onActive: function(toggler, slider){
                if (Browser.Engine.trident) slider.setStyle('display', 'block');
                //slider.setStyle('padding-bottom', '20px');
            },
            onBackground: function(toggler, slider){
                if (Browser.Engine.trident) slider.setStyle('display', 'none');
            },
            onComplete: function(){
                
            },

            opacity: 0,
            display: false,
            alwaysHide: true
    });
}

