/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
    
    jQuery(function($){
      $("#twitter div").tweet({
//        join_text: "auto",
        username: ['onegraphics'],
        template: '{join}@<a href="http://twitter.com/{screen_name}">{screen_name}</a> {text}',
        query: 'from:onegraphics OR from:salah1 OR from:brrhom @onegraphics',
        query:null,
//        avatar_size: 48,
        count: 3,
//        auto_join_text_default: "",
//        auto_join_text_ed: "",
//        auto_join_text_ing: "",
//        auto_join_text_reply: "",
//        auto_join_text_url: "",
        loading_text: "loading tweets..."
      });
    });
    
    var top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
    $(window).scroll(function (event) {
        // what the y position of the scroll is
        var y = $(this).scrollTop();

        // whether that's below the form
        if (y >= top) {
            // if so, ad the fixed class
            $('#sidebar').addClass('fixed');
        } else {
            // otherwise remove it
            $('#sidebar').removeClass('fixed');
        }
    });



    $('#contact-us-form input,#contact-us-form textarea, #career-form input, #career-form textarea').focus(function(){
        //        alert($(this).attr('title'));
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('');
        }
    })

    $('#contact-us-form input,#contact-us-form textarea, #career-form input, #career-form textarea').blur(function(){
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
    })




    $('#nav ul ul').animate({
        'height':'0px',
        'padding-top':'0px',
        'padding-bottom':'0px'
    },0,'easeOutElastic',function(){
        $(this).css({
            'display':'none'
        });
    });
    $('#nav ul ul').each(function(){
        $(this).parent().children('a').append('<span></span>');
    });
    $('#nav>ul>li>a').click(function(){
        if($(this).parent().children('ul').length==0){            
            return true;
        }
        if($(this).parent().hasClass('active')!=true){
            var new_height=(($(this).parent().children('ul').children('li').length)*23)+1;
            var current_element=$(this);
            if($('#nav ul li.active').length>0){
                $('#nav ul li.active').each(function(){
                    $(this).removeClass('active').children('ul').animate({
                        'height':'0px',
                        'padding-top':'0px',
                        'padding-bottom':'0px'
                    },500,'easeInOutQuart',function(){
                        $(this).css({
                            'display':'none'
                        });
                        $(current_element).parent().addClass('active').children('ul').css({
                            'display':'block'
                        }).animate({
                            'height':new_height+'px',
                            'padding-top':'20px',
                            'padding-bottom':'20px'
                        },500,'easeOutElastic');
                    })
                })
            }
            else{                
                $(current_element).parent().addClass('active').children('ul').css({
                    'display':'block'
                }).animate({
                    'height':new_height+'px',
                    'padding-top':'20px',
                    'padding-bottom':'20px'
                },500,'easeOutElastic');
            }
        }
        else{
            $(this).parent().removeClass('active').children('ul').animate({
                'height':'0px',
                'padding-top':'0px',
                'padding-bottom':'0px'
            },500,'easeOutQuart',function(){
                $(this).css({
                    'display':'none'
                });
            })
        }
        return false;
    });

    $('#featured-websites').cycle({
        fx: 'scrollHorz',
        timeout: 3000,
        pause:   1
    });

    $('.website-detail p').each(function(){
        var color = $(this).parent().css('color');
        $(this).css('color', color);
    })

    $('#random-logos').cycle({
        fx: 'fade',
        timeout: 5000
    });


    $('#career-form').hide();
    $('.challenge-button').click(function(){
        $('#career-form:hidden').show('slow', function(){
            $("body").animate({ scrollTop: $(document).height() }, "50");
        });
    });
    $('#career-form a.close').click(function(){
       $('#career-form').hide('slow');
    });
})

