
function button_anim(button, top_left){
    $(button).hover(function(){
            $(this).find('.img_act').css({zIndex:'2'}).stop().animate({top:'0', left:'0', width:'100%', height:'100%'},400, 'easeOutCirc')
            $(this).find('.img').css({zIndex:'1'}).stop().animate({top:top_left, left:top_left, width:'0', height:'0'},400, 'easeOutCirc')
        }, function(){
            $(this).find('.img_act').css({zIndex:'1'}).stop().animate({top:top_left, left:top_left, width:'0', height:'0'},400, 'easeOutCirc')
            $(this).find('.img').css({zIndex:'2'}).stop().animate({top:'0', left:'0', width:'100%', height:'100%'},400, 'easeOutCirc')
        }
    )
    $('.link1').click(function(){
        $(this).find('.img_act').css({zIndex:'1'}).stop().animate({top:top_left, left:top_left, width:'0', height:'0'},400, 'easeOutCirc')
        $(this).find('.img').css({zIndex:'2'}).stop().animate({top:'0', left:'0', width:'100%', height:'100%'},400, 'easeOutCirc')
    })
    $('.tabs .nav a').click(function(){
        $('.tabs .nav a').find('.img').css({zIndex:'2'}).css({top:'0', left:'0', width:'100%', height:'100%'})
    })
}
function menu_hover(){
    $(this).find('> a').stop().animate({backgroundPosition:'-280px -400px'},400, 'easeOutQuad')
}
function menu_unhover(){
    $(this).find('> a').stop().animate({backgroundPosition:'-500px -500px'},400, 'easeOutQuad')
}
function menuBind(){
    $('.menu > li').bind ('mouseenter', menu_hover);
    $('.menu > li').bind ('mouseleave', menu_unhover);
}

$(document).ready(function() {
    // animate button_enter
    $('.button_enter').hover(function(){
        $(this).find('span').stop().animate({backgroundPosition:'-1px -1px'},400, 'easeOutQuad')
    }, function(){
        $(this).find('span').stop().animate({backgroundPosition:'-200px -200px'},400, 'easeOutQuad')
    }
    )
    button_anim('.close', '30');
    button_anim('.prev', '30');
    button_anim('.next', '30');
    button_anim('.prev_1', '30');
    button_anim('.next_1', '30');
    button_anim('.link1', '10');
    button_anim('.tabs .nav a', '10');
    //animate menu
    menuBind();
    $('ul.menu').superfish({
        delay:       600,
        animation:   {height:'show'},
        speed:       400,
        autoArrows:  false,
        dropShadows: false
    });
    //tabs
    tabs.init();
    // for lightbox
    if ($("a[rel^='prettyPhoto']").length) {
        $(document).ready(function() {
            // prettyPhoto
            $("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
        });
    }	
    // gallery1
    $("#gallery1").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: 2,
        speed: 400,
        easing: 'easeOutCirc'
    });	
    // gallery2
    //$('div.content').css('display', 'block');
    // Initialize Advanced Galleriffic Gallery
    //$('#thumbs').galleriffic({});
    // bg resize & animate
    $('#bgSlider').bgSlider({
        duration:1000,
        pagination:'.pager',
        preload:false,
        slideshow:false,
        spinner:'.bg_spinner'
    })
    var w_img=1980, h_img=1200;
    var w,new_w,h, new_h, num;
    setWidth();
    setHeight();
    w=new_w;h=new_h;
    setSize();
    function setWidth(){
        new_w=$(window).width();
    }
    function setHeight(){
        new_h=$(window).height();
    }
    function setSize(){
        if ((w/w_img) > (h/h_img)) {
            w_img_new=w+20;
            h_img_new=~~((w+20)*h_img/w_img);
        } else {
            h_img_new=h+20;	
            w_img_new=~~((h+20)*w_img/h_img);
        }
        m_left = -(~~(w_img_new/2)+1)+'px';
        $('#bgSlider img').css({width:w_img_new, height:h_img_new, marginLeft:m_left});
        $('.box_content').css({height:(h-139)});
    }
    setInterval(setNew,150);
    function setNew(){
        setWidth();
        setHeight();
        if ((w!=new_w)|(h!=new_h)) {
            w=new_w;h=new_h;
            setSize();
        }
    }
 });
