    var bloginfo = new Array();

    /*console.log (bloginfo);*/
    var loading = 0;
    var rows_done = false;

    function services_over () {
        $('.service_thumbnail_body').each (function () {
            $(this).slideDown ();
        });

        $('.service_thumbnail_arrow').each (function () {
            $(this).html ('&darr;');
            $(this).removeClass ('arrow_right').addClass ('arrow_down');
        });
    }

    function services_out () {
        $('.service_thumbnail_body').each (function () {
            $(this).slideUp ();
        });

        $('.service_thumbnail_arrow').each (function () {
            $(this).html ('&rarr;');
            $(this).removeClass ('arrow_down').addClass ('arrow_right');
        });
    }

    function adjust_rollover_container (id) {
        var offset = $('#' + id).offset ();
        var screen_top = $(document).scrollTop ();
        var screen_bottom = screen_top + $(window).height ();
        var thumb_top = offset.top;
        var thumb_height = $('#' + id).outerHeight (true);
        var caption_height = 0;
        var rollover_height = $('#' + id + ' section.post_thumbnail_rollover').outerHeight (true);

        //if ((thumb_top + thumb_height + rollover_height + caption_height - screen_top + 55) > screen_bottom) {
            $('#' + id + ' section.post_thumbnail_rollover').css ('top', '0px');
        //} else {
            //$('#' + id + ' section.post_thumbnail_rollover').css ('top', (thumb_height - 43) + 'px');
        //}

        /*console.log ("offset: " + offset);
        console.log ("screen_top: " + screen_top);
        console.log ("screen_bottom: " + screen_bottom);
        console.log ("thumb_top: " + thumb_top);
        console.log ("thumb_height: " + thumb_height);

        if ((thumb_top + thumb_height + rollover_height + caption_height - screen_top) > screen_bottom) {
            var img_offset = $('#' + id).offset();

            if ((img_offset.top - $(document).scrollTop()) >= $(this).outerHeight(true)) {
                var move = ($(this).outerHeight(true)) * -1 + 50;
                $(this).css ('top', move);
                console.log ("Move Up: " + move);
                $(this).data ('moved', 1);
            }
        }*/
    }

    function activate_thumbs () {
        $('.project_thumb').each (function () {
            var id = $(this).attr ('id');
            adjust_rollover_container (id);

            $(this)/*.find ('img')*/.hover (function () {
                $('#' + id + ' section.post_thumbnail_rollover').show (0, function () {
                    adjust_rollover_container (id);
                });
            }, function () {
                $('#' + id + ' section.post_thumbnail_rollover').hide (0, function () {
                    /*if ($(this).data ('moved') != 0) {
                        if ($('body#home').length > 0) {
                            var move = $('#' + id).outerHeight(true) - 43;
                        } else {
                            var move = $('#' + id).outerHeight(true) - 46;
                        }
                        $(this).css ('top', move);
                        console.log ("Move Down: " + move);
                        $(this).data ('moved', 0);
                    }*/
                });
            });
        });
    }

    function fetch_row_archive () {
        data = { 'post_type':'post', 'orderby':'date', 'order':'DESC', 'posts_per_page':4, 'page':$('#next_row_number').html() };
        /*console.log (data);*/

        $.get (bloginfo['url'] + "/service/we-manage/", data, function (html_data) {
            $('#ajax_loader').replaceWith (html_data);
            $('#next_row_number').html(parseInt ($('#next_row_number').html()) + 1);
            if ($('.blank_thumb').length > 4) {
                rows_done = true;
                for (var i = 0; i < 4; i++) {
                    $('.small_post_thumbnail:last').remove();
                }
            }
            setTimeout ('loading = 0', 1000);
        });
    }

    function fetch_row_home () {
        var row = $('#project_number').html ();

        if ($('#twitter_id').length > 0) {
            //$('#twitter_id').before ('<div id="dummy0" class="dummy" style="display: none;"></div><div id="dummy1" class="dummy" style="display: none;"></div><div id="dummy2" class="dummy" style="display: none;"></div><div id="dummy3" class="dummy" style="display: none;"></div><div id="dummy4" class="dummy" style="display: none;"></div><div id="dummy_master" class="dummy" style="display: none;"></div>');
            $('#twitter_id').before ('<div id="dummy0" class="dummy" style="display: none;"></div><div id="dummy1" class="dummy" style="display: none;"></div><div id="dummy2" class="dummy" style="display: none;"></div><div id="dummy3" class="dummy" style="display: none;"></div><div id="dummy_master" class="dummy" style="display: none;"></div>'); /* 4 column */

            for (var col = 0; col < 4; col++) { /* 4 column 5 -> 4 */
                data = { 'col':col, 'row':row };

                $.get (bloginfo['url'] + "/service/we-talk/", data, function (html_data) {
                    var column = $('#dummy_master').html (html_data).find ('.column').html ();
                    var row = $('#dummy_master .row').html ();
                    $('#dummy_master').html ('');
                    $('#dummy' + column).html (html_data);
                    if ($(".dummy .post_thumbnail").length == 4) { /* 4 column 5 -> 4 */
                        var done = true;

                        for (var c = 0; c < 3; c++) {  /* 4 column 4 -> 3 */
                            if ($('#post_thumbnail_' + row + '_' + c).hasClass ('project_thumb')) {
                                done = false;
                                break;
                            }
                        }

                        if (done) {
                            $('.dummy').remove ();
                            rows_done = true;
                        } else {
                            for (var c = 0; c < 4; c++) { /* 4 column 5 -> 4 */
                                $('#dummy' + c).replaceWith ($('#dummy' + c).html ());
                            }

                            if ($(window).height () >= $(document).height()) {
                                fetch_row_home ();
                            }
                        }

                        $('#ajax_loader').remove();
                    }
                });
            }
        } else {
            var category = $('#category_name').html ();

            $('#category_name').before ('<div id="dummy0" class="dummy" style="display: none;"></div><div id="dummy1" class="dummy" style="display: none;"></div><div id="dummy2" class="dummy" style="display: none;"></div><div id="dummy3" class="dummy" style="display: none;"></div><div id="dummy4" class="dummy" style="display: none;"></div><div id="dummy_master" class="dummy" style="display: none;"></div>');

            for (var col = 0; col < 5; col++) {
                data = { 'col':col, 'row':row, 'category':category };

                $.get (bloginfo['url'] + "/service/we-deliver/", data, function (html_data) {
                    var column = $('#dummy_master').html (html_data).find ('.column').html ();
                    $('#dummy_master').html ('');
                    $('#dummy' + column).html (html_data);
                    if ($(".dummy .post_thumbnail").length == 5) {
                        var done = true;

                        for (var c = 0; c < 5; c++) {
                            if ($('#post_thumbnail_' + row + '_' + c).hasClass ('project_thumb')) {
                                done = false;
                                break;
                            }
                        }

                        if (done) {
                            $('.dummy').remove ();
                            rows_done = true;
                        } else {
                            for (var c = 0; c < 5; c++) {
                                $('#dummy' + c).replaceWith ($('#dummy' + c).html ());
                            }

                            if ($(window).height () >= $(document).height()) {
                                fetch_row_home ();
                            }
                        }

                        $('#ajax_loader').remove();
                    }
                });
            }
        }

        $('#project_number').html (parseInt (row) + 1);
        setTimeout ('loading = 0', 1000);
        activate_thumbs();
    }

    var images = new Array();

    function load_image (i) {
        $('.projector').animate({
            opacity: 0
        }, 1000, function() {
            $('.projector').empty ();
            $('.projector').append (images[i]);
            $('.projector').animate ({ opacity: 1 }, 1000);
        });

        if (i == (images.length - 1)) {
            next = 0;
        } else {
            next = i + 1;
        }
        setTimeout ("load_image (" + next + ")", 5000);
    }

    function hide_box () {
        $('.share_email_popup').fadeOut ("slow");
    }

    function hide_error () {
        $('#email_status_message').fadeOut ("slow", function () {
            $(this).html ('').fadeIn (0);
        });
    }

    $(document).ready(function() {
        $('#bloginfo div').each (function () {
            var key = $(this).attr ('class');
            var value = $(this).html ();
            bloginfo[key] = value;
        });

        $.ajaxSetup({ cache: false });

        /*if (($(document).scrollTop() + $(window).height ()) >= $(document).height()) {
            if (($('body#home').length > 0) || ($('body#category').length > 0)) {
                fetch_row_home ();
            } else if ($('body#archive').length > 0) {
                fetch_row_archive ();
            }
        }*/

        if ($('#latest_tweet').length > 0) {
            $.get (bloginfo['url'] + "/tweep", function (html_data) {
                $('#latest_tweet').parent().find('.twitter_thumbnail').remove();
                $('#latest_tweet').replaceWith (html_data);
            });
        }

        /*$(this).scroll (function() {
            if (!(rows_done)) {
                if (($(this).scrollTop() + $(window).height()) == $(this).height()) {
                    if (($('#ajax_loader').length == 0) && (loading == 0)) {
                        loading = 1;
                        if ($('#twitter_id').length > 0) {
                            $('#twitter_id').before ('<div id="ajax_loader"><img src="' + bloginfo['template_url'] + '/images/ajax-loader.gif" /></div>');
                        } else {
                            $('#category_name').before ('<div id="ajax_loader"><img src="' + bloginfo['template_url'] + '/images/ajax-loader.gif" /></div>');
                        }

                        if (($('body#home').length > 0) || ($('body#category').length > 0)) {
                            fetch_row_home();
                        } else if ($('body#archive').length > 0) {
                            console.log ('ja');
                            fetch_row_archive ();
                        }
                    }
                }
            }
        });*/

        activate_thumbs();

        var timeout = 0;

        $('.service_thumbnails').hover (function () {
            timeout = setTimeout ("services_over()", 500);
        }, function () {
            clearTimeout (timeout);
            services_out();
        });


        /* single-project.php */
        $('.photo_thumbnail').each (function () {
            var image = new Image ();
            image.src = $(this).attr ('data-img');


            $(this).parent().attr ('href', 'javascript: return (false);');

            $(this).hover (function () {
                $('.project_full_image').html ('<img alt="" src="" />');
                $('.project_full_image img').attr ('src', $(this).attr ('data-img'));
                $('.project_full_image img').attr ('alt', $(this).attr ('alt'));
            });
        });

        $('.video_thumbnail').each (function () {
            var video_id = $(this).attr ('data-img');

            $(this).parent().attr ('href', 'javascript: return (false);');

            $(this).click (function () {
                $('.project_full_image').html ('<iframe src="" width="572" height="392" frameborder="0"></iframe>');
                $('.project_full_image iframe').attr ('src', 'http://player.vimeo.com/video/' + video_id + '?autoplay=1');
            });


            $(this).parent().parent().find ('#video_marker a').attr ('href', 'javascript: return (false);').click (function () {
                $('.project_full_image').html ('<iframe src="" width="572" height="392" frameborder="0"></iframe>');
                $('.project_full_image iframe').attr ('src', 'http://player.vimeo.com/video/' + video_id + '?autoplay=1');
            });
        });

        function checkEmail(email) {
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (!filter.test(email)) {
                return false;
            }
            return true;
        }

        var default_to = $('#to_email').attr ('value');

        var default_from = $('#from_email').attr ('value');

        $('#share_email_popup_open').click (function () {
            $('#to_email').attr ('value', default_to);
            $('#email_status_message').removeClass ('error success').html ('');
            $('.share_email_popup').css ('display', 'inline-block');
            return false;
        });

        $('#share_email_popup_close').click (function () {
            hide_box();
            return false;
        });

        $('#to_email').focus (function () {
            if ($(this).attr ('value') == default_to) {
                $(this).attr ('value', '');
            }
        });

        $('#from_email').focus (function () {
            if ($(this).attr ('value') == default_from) {
                $(this).attr ('value', '');
            }
        });

        $('#share_email_submit').click (function () {
            $('#email_status_message').removeClass ('error success').html ('');
            /* validate */
            var success = true;

            if (!checkEmail ($('#to_email').attr ('value'))) {
                $('#email_status_message').addClass ('error').html ('Your "to" address is not a valid email address');
                success = false;
                setTimeout ("hide_error();", 2000);
            }

            if (!checkEmail ($('#from_email').attr ('value'))) {
                $('#email_status_message').addClass ('error').html ('Your "from" address is not a valid email address');
                success = false;
                setTimeout ("hide_error();", 2000);
            }

            if (success) {
                var subject = "Interesting Link on Nirvana site";
                var email_to = $('#to_email').attr ('value');
                var email_from = $('#from_email').attr ('value');
                var message = $('#message').attr ('value');
                /* ajax */
                $.ajax ({
                    type: "POST",
                    url: bloginfo['url'] + "/email/send/",
                    data: {
                        subject: subject,
                        message: message,
                        email_to: email_to,
                        email_from: email_from
                    },
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        if (data.code !== 0) {
                            if (typeof data.error !== 'undefined') {
                                $('#email_status_message').addClass('error').html(data.error);
                                success = false;
                                setTimeout ("hide_error();", 2000);
                            } else {
                                $('#email_status_message').addClass('error').html('Your email could not be sent, we\'re not sure why');
                                success = false;
                                setTimeout ("hide_error();", 2000);
                            }
                        } else {
                            $('#email_status_message').addClass ('success').html ('Your email was sent successfully');
                            setTimeout ("hide_box();", 2000);
                        }
                    },
                    error: function () {
                        $('#email_status_message').addClass ('error').html ('Your email could not be sent right now');
                        setTimeout ("hide_error();", 2000);
                    }
                });
            }
        });

        /* splash page */
        
        if ($('.splash .gallery .gallery-icon a').length > 0) {
            var loaded_images = 0;

            $('.splash').before ('<div id="ajax_loader"><img src="' + bloginfo['template_url'] + '/images/ajax-loader.gif" /></div>');
            
            $('.splash .gallery .gallery-icon a').each (function () {
                var a = $(this);
                var index = images.push($("<img />").attr ('src', a.attr ('href')).attr ('class', 'slide').load (function () {
                    loaded_images = loaded_images + 1;
                    if (loaded_images == $('.splash .gallery .gallery-icon a').length) {
                        $('#ajax_loader').animate ({
                            opacity: 0
                        }, 1000, function () {
                            load_image (0);
                        })
                    }
                }));
            });
        }

        /* twitter pulse */

        $('.twitter_pulse_element').each (function () {
            var screen_name = $(this).attr ('data-screenname');
            var url = bloginfo['url'] + "/tweep/" + screen_name;

            /*$(this).parent().find('.image_at_url').each(function () {
                var image_loaded = false;
                var this_id = $(this).attr('id');

                $(this).find('img').load(function () {
                    image_loaded = true;
                });

                setTimeout(function () {
                    if (image_loaded === false) {
                        $("#" + this_id).remove();
                    }
                }, 5000);
            });*/

            if ($('#dummy_' + screen_name).length === 0) {
                $.get(url, function (html_data) {
                    var num = 0, html_frag;

                    if ($('#dummy_' + screen_name).length === 0) {
                        $('#main_wrapper').append('<div id="dummy_' + screen_name + '" style="display:none;">' + html_data + '</div>');

                        for (num = 0; $('div[data-screenname=' + screen_name + '][data-num=' + num + ']').length > 0; num++) {
                            html_frag_id = $('#dummy_' + screen_name + ' .twitter_thumbnail:first').attr('id');
                            html_frag = $('#dummy_' + screen_name + ' .twitter_thumbnail')[0];

                            $('div[data-screenname=' + screen_name + '][data-num=' + num + ']').replaceWith (html_frag).show();
                            $('#' + html_frag_id + ' .image_at_url').each(function () {
                                var image_loaded = false;
                                var this_id = $(this).attr('id');

                                $(this).find('img').load(function () {
                                    image_loaded = true;
                                });

                                setTimeout(function () {
                                    if (image_loaded === false) {
                                        $("#" + this_id).remove();
                                    }
                                }, 5000);
                            });
                        }

                        $('#dummy_' + screen_name).remove();
                    }
                });
            }
        });
    });

