bibil = {}

$(function(){        
    
    $(".main .left ul li, .main .right ul li").mouseover(function(){        
        $(this).addClass("active");
    })

    $(".main .left ul li, .main .right ul li").mouseout(function(){
        $(this).removeClass("active");
    })   
    
    $("#gallery img.model-photo").mouseover(function(){
        //var src = $(this).attr('src');        
        //src = src.replace(/\/grey$/, "");
        //$(this).attr('src', src);                          
        $(this).css("margin-top", "-216px");
    })
    
    $("#gallery img.model-photo").mouseout(function(){
        //var src = $(this).attr('src');        
        //$(this).attr('src', src+"/grey");
        $(this).css("margin-top", "0");
    })    
    
    $("#gallery a.model-link, .people .photo").click(function(){
        var modelid = $(this).attr("modelid");                                 
        overlay(1);        
        $.get('/ajax.php?'+Math.random(), {p: 'getModel', modelid: modelid}, function(res){
            var scrolls = getPageScroll();            
            var curtop = parseInt($("#popup").css("top"));
            var newtop = scrolls[1] + 50;            
            $("#popup").css({top: newtop+"px"});
            $("#popup").show();
            $("#popup").html(res);
            setEventsPopup();            
        });
        return false;
    })    
    
})


function overlay(show)
{
    var ov = $("#overlay-global");
    if(show)
    {
        var pageSize = getPageSize();
        ov.css({
                backgroundColor:    "#000",
                opacity:            0.7,                
                width:                pageSize[0],
                height:               pageSize[1]
            }).fadeIn();
        ov.show();
    }else
    {
        ov.hide();
    }
}

function setEventsPopup()
{
    $("#popup a.close, #popup a.close img").unbind();
    $("#popup a.close, #popup a.close img").click(function(){
        $("#popup").hide();
        stopSslideShow();
        overlay(false);
    })
    
    $("#popup .navi .next").click(function(){
        stopSslideShow();
        slidePhotos('next');
        return false;
    })    
    
    $("#popup .navi .nnext").click(function(){
        stopSslideShow();
        slidePhotos('end');
        return false;
    })        
    
    $("#popup .navi .bback").click(function(){
        stopSslideShow();
        slidePhotos('home');
        return false;
    })            

    $("#popup .navi .back").click(function(){
        stopSslideShow();
        slidePhotos('back');
        return false;
    })        
    
    $("#popup .navi").click(function(){
        slideShow();
        return false;
    })      
    
    
}

function swap(obj,base,over){
    if(over==1) add="a";
    else add="";
    obj.src="/images/contest/"+base+add+".gif";
}

function slideShow(interval)
{
    if(typeof interval == 'undefined') interval = 1000;
    if(typeof bibil.photosPlayInt == 'undefined')
    {
        bibil.photosPlayInt = setInterval("slidePhotos('next')", interval);
        $("#popup .navi").eq(0).removeClass("pause");
        $("#popup .navi").eq(0).addClass("play");
    }else
    {   
        stopSslideShow();
    }
}

function stopSslideShow()
{
    if(typeof bibil.photosPlayInt != 'undefined')
    {
        clearInterval(bibil.photosPlayInt);
        delete bibil.photosPlayInt;
        $("#popup .navi").eq(0).removeClass("play");
        $("#popup .navi").eq(0).addClass("pause");
    }
}

function slidePhotos(pos)
{
    var images = $("#popup img.models-photos");
    var imagesLen = $("#popup img.models-photos").length;
    var imgActive = $("#popup div.img  img.active").eq(0);        
    imgActive.removeClass("active");
    var imgNext = null;
    if(pos == 'next')
    {
        imgNext = imgActive.next("img");
    }else if(pos == 'back')
    {
        imgNext = imgActive.prev("img");
    }else if(pos == 'end')
    {
        imgNext = images.eq(imagesLen-1);
    }else if(pos == 'home')
    {
        imgNext = images.eq(0);
    }
    
    if(imgNext)
    {
        if(imgNext.length == 0) 
        {
            imgNext = pos == 'next' ? images.eq(0) : images.eq(imagesLen-1);
        }
        imgNext.addClass("active");        
    }
    
}


function startGalleryLB()
{
    var galls = $('.gallery_item');
    if(galls.length > 0)
    {
        galls.each(function(i){
            $(this).find("a.gallery_item_img").lightBox({
                fixedNavigation:false,
                imageLoading: '/common/lightbox2/images/lightbox-btn-loading.gif',
                imageBtnClose: '/common/lightbox2/images/lightbox-btn-close.gif',
                imageBtnPrev: '/common/lightbox2/images/lightbox-btn-prev.gif',
                imageBtnNext: '/common/lightbox2/images/lightbox-btn-next.gif'
            }); 
        })
    }

    
}

function getBodyScrollTop()
{
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}



String.prototype.printAddr =
function (_hamper,_prefix,_postfix,_face)
{
  _hamper=
  _prefix+
  "@"+
  this+
  (_postfix || '')
  document.write((_face||_hamper).link("mailto:"+_hamper));
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function chimg(obj,over){
        id=obj.id;
        if(over==1) imgs=id+"a";
        else imgs=id;
        ext="jpg";
        obj.src="/images/"+imgs+"."+ext;
}

function overimg(obj,url){
        obj.src=url;
}
function show_hover(fid){
         // тут подгрузка контента
         /*
         document.getElementById('Hover').style.width=document.body.scrollWidth+"px";
         scrollh=document.body.scrollHeight+500;
         document.getElementById('Hover').style.height=scrollh+"px";
         
         */
         document.getElementById('Hover').style.display="block";
         $("#Hover .hover_bg").html("Загрузка...");
         $.get("/ajax.php?"+Math.random(), {p: 'getFirm', fid: fid}, function(res){
            //alert(res);
            $("#Hover .hover_bg").html(res);
            //$("#Hover").html(res);
            //$("#cert-load").html(res);            
         });
}
function switch_cert_self(obj){
         if(obj.checked==true) document.getElementById("cert_self").style.display="block";
         else document.getElementById("cert_self").style.display="none";
}
function hide_hover(){
         document.getElementById('Hover').style.display="none";
}
window.onload=function(){  
   MM_preloadImages('/images/g.png',
                    '/images/play/nnext_over.gif',
                    '/images/play/nnext.gif',
                    '/images/play/next_over.gif',
                    '/images/play/next.gif',
                    '/images/play/back_over.gif',
                    '/images/play/back.gif',
                    '/images/play/bback_over.gif',
                    '/images/play/bback.gif',
                    '/images/play/play_act.gif',
                    '/images/play/play.gif',
                    '/images/play/play_over.gif'                    
   );
}

