$(document).ready(function() {
    $("#menu").flashembed("flash/menu.swf");
});
$(document).ready(function() {
    $("ul.project").tabs("div#panes > div.pane", {effect: 'ajax'});
    $("ul.galleryofdetails").tabs("div#panes > div.pane", {initialIndex: 9, effect: 'ajax'});
    $("ul#tabs").tabs("div#panes > div.pane", {initialIndex: 8, effect: 'ajax'});
    $(".gallery, .galleryDetails").livequery(function(){
        $(this).find("img").each(function(i, e) {
            $(e).wrap('<a href="' + $(e).attr('src').replace(/images\/thumb\//, 'photo.html?img=') + '"></a>');
            $(e).after($('<div class="tooltip"><div class="arrow"><div class="tip"><img src="' + $(e).attr('src').replace("images/thumb", "images/medium") + '" /></div></div></div>'));
        });
    });
    $(".gallery").livequery(function(){
        $(this).find("a>img").each(function(i, e) {
            var pos, cls, ofst;
            switch(true)
            {
                case i % 5 == 0:
                    pos = 'top right';
                    cls = 'right';
                    ofst = [40, -85];
                break;
                case i % 5 == 4:
                    pos = 'top left';
                    cls = 'left';
                    ofst = [40, 85];
                break;
                default:
                    pos = 'top center';
                    cls = '';
                    ofst = [40, 0];
                break;
            }
            
            $(e).tooltip({
                tip: ".tooltip",
                position: pos,
                delay: 1,
                relative: true,
                offset: ofst,
                lazy: false,
                events: {
                    def: "mouseover,mouseout"
                }
            }).next('.tooltip').addClass(cls);
        });
    });
    $(".galleryDetails").livequery(function(){
        $(this).find("a>img").each(function(i, e) {
            var pos, pos_x, pos_y, cls, cls_x, cls_y, ofst;
            switch(true)
            {
                case i % 5 == 0:
                    if(i < 10){
                        pos = 'bottom right';
                        cls = 'bottom right';
                        ofst = [-40, -85];
                    }else{
                        pos = 'top right';
                        cls = 'right';
                        ofst = [40, -85];
                    }
                break;
                case i % 5 == 4:
                    if(i < 10){
                        pos = 'bottom left';
                        cls = 'bottom left';
                        ofst = [-40, 85];
                    }else{
                        pos = 'top left';
                        cls = 'left';
                        ofst = [40, 85];
                    }
                break;
                default:
                    if(i < 10){
                        pos = 'bottom center';
                        cls = 'bottom';
                        ofst = [-40, 0];
                    }else{
                        pos = 'top center';
                        cls = '';
                        ofst = [40, 0];
                    }
                break;
            }
            //pos = pos_x +' '+ pos_y;
            //cls = cls_x +' '+ cls_y;
            $(e).tooltip({
                tip: ".tooltip",
                position: pos,
                delay: 1,
                relative: true,
                offset: ofst,
                lazy: false,
                events: {
                    def: "mouseover,mouseout"
                }
            }).next('.tooltip').addClass(cls);
        });
    });
    $("ul#tabs a").click(function() {
        $(this).blur();
    });
});
