var box;
var link;    
var initMultiBox;
function start(){
    box = new multiBox({
        mbClass: '.mbhtml',//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: './Scripts/ForceDownload.asp',//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: 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)
    });
    
    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: './Scripts/ForceDownload.asp',//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,
        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)
    });
    
    if ($$('citys')) startCity();
    if ($$('.names')) startMemb();
    if ($('fsend')) actSubmit();
    if ($('up_fotos')) startOver();
    
    
}

function actSubmit(){
   $('fsend').addEvent('submit', function(e){
        if($('ch1_').value.length < 4 || $('ch0_').value.length < 4){
            e = new Event(e).stop();
            alert('Заполните все поля');
            return false;
        }
    }); 
}

function gPage(d,leter,count,cid,im,cPage){
    
    var url = "/mods/a.function.php";
    var str = "d="+d+"&l="+leter+"&aj=15&c="+count+"&cid="+cid+"&im="+im+"&p="+cPage; 
    coreReq = new Request.HTML({url: url, update: $('ajpage')});
    coreReq.send(str);  
}

function imgToogle(p1,p2,p3){
    document.location.href = 'veterani/'+p1+'/'+(p2 ? p2 : '0')+(p3 ? '' : '/img');
}

function videoToogle(p1,p2,p3){
    document.location.href = 'veterani/'+p1+'/'+(p2 ? p2 : '0')+(p3 ? '' : '/video');
}

function startMemb(){
    var ob = $('overlay');
    $each($$('.names li a'), function(element, i){
        //if(element.parentNode.parentNode.hasClass('y_foto')){
            element.addEvent('click', function(){
                
                var fla = $('pr_pic'+i);
                
                
                ob.setStyles({
                    'display': 'block', 
                    'opacity': .8,
                    height: window.getScrollSize().y
                });
                
                                
                fla.setStyles({
                    'display': 'block'
                });
                $('close'+i).setStyle('display', 'block')
                
                var a_pic = $('pr_pic'+i).getElement('img');
                var a_vid = $('pr_pic'+i).getElement('object');
                
                if (!a_pic) {
                    $('pr_pic'+i).setStyle('background', '#fff');
                } else {
                    $('pr_pic'+i).setStyle('background', '#fff');
                }
                if (!a_vid) {
                    $('pr_pic'+i).setStyle('width', '250px');
                } else {
                    $('pr_pic'+i).setStyle('width', '500px');
                }
                var top = (($(window).getHeight() - fla.getHeight()) / 2) + window.getScroll().y;
                var left = ($(window).getWidth() - fla.getWidth()) / 2;
                
                fla.setStyles({
                    top: top,
                    left: left
                });
//                var size2 = $('pr_pic'+i).getSize();
//                var leW = size2.x;
//                var leH = size2.y;
//                var iW = -(leW)-5;
//                var iH = 0;
//                if (Browser.Engine.trident) {
//                    iH = -(leH-le)+5;
//                } else if (Browser.Engine.presto) {
//                    iH = -(leH-le)+2;
//                } else {
//                    iH = -(leH-le)+3;
//                }
//                
//                var ii = -2;
                //alert(ii);

//                $('pr_pic'+i).setStyles({'left': iW+'px', 'top': iH+'px'});
//                
//                
//                
                //if (!$('pr_pic'+i).getElement('img'))
            });
            ob.addEvent('click', function(){
                $('pr_pic'+i).setStyle('display', 'none');
                ob.setStyle('display', 'none');
            });
            
            $('close'+i).addEvent('click', function(){
                $('close'+i).setStyle('display', 'none');
                ob.setStyle('display', 'none');
                $('pr_pic'+i).setStyle('display', 'none');
            });
        //}
    });
}

function startCity() {
    var mySlide = new Fx.Slide('citylist', {
        duration: 500,
        transition: Fx.Transitions.Pow.easeOut
    }).hide();
    
    
    $('showcitys').addEvent('click', function(){
        mySlide.toggle();
    });
}

function showBox(url){
    var ob = $('overlay');
    var fla = $(url);
    ob.setStyles({
        'display': 'block', 
        'opacity': .8,
        height: window.getScrollSize().y
    });

    fla.setStyle('display', 'block');
    
    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 = $('overlay');
    var fla = $(url);
    
    ob.setStyles({'display': 'none', 'opacity': 0});
    fla.setStyle('display', 'none');
}

function startOver(){
    $('up_fotos').addEvent('mouseenter', function(){
        this.setStyle('background', 'url(img/file_.gif)');
    });
    $('up_fotos').addEvent('mouseleave', function(){
        this.setStyle('background', 'url(img/file.gif)');
    });
    
    $('send').addEvent('mouseenter', function(){
        this.setStyle('background', 'url(img/send_.gif)');
    });
    $('send').addEvent('mouseleave', function(){
        this.setStyle('background', 'url(img/send.gif)');
    });
}


function fileLink(l){
    $('flink').href = "data/"+l;
}

function wfileLink(l){
    $('wflink').href = "data/"+l;
}


function showBox(url){
    var ob = $('overlay');
    var fla = $(url);
    ob.setStyles({
        'display': 'block', 
        'opacity': .7,
        height: window.getScrollSize().y
    });

    fla.setStyle('display', 'block');
    
    var top = (($(window).getHeight() - fla.getHeight()) / 2) + window.getScroll().y;
    var left = ($(window).getWidth() - fla.getWidth()) / 2;
    
    fla.setStyles({
        top: top,
        left: left
    });
    
}
function closeBox(url){
    var ob = $('overlay');
    var fla = $(url);
    
    ob.setStyles({'display': 'none', 'opacity': 0});
    fla.setStyle('display', 'none');
}
