var addthis_config = {
   ui_click: true,
   ui_offset_top: -10
}

$(function() {
    var wall_anchor = self.document.location.hash;
    
    var total_items = $("#content.happy-clients a").size();
    
    $("a.item-small:not(.no-content)").click(function(e) {
        
        e.preventDefault();
        
        var position = $(this).attr("id").substring(9);        

        var row    = Math.ceil(position/3);
        var column = (position % 3) == 0 ? 3 : position % 3;

        // alert('row-'+row+' | column-'+column);

        $("#item-large").remove();
        $("#content.happy-clients a").show();

        if (column == 3)
        {                        
            $(this).next().attr("id", "position-"+position).insertBefore($(this));
            $(this).attr("id", "position-"+(position*1 + 1));
        }
        else if (column == 2)
        {
            $(this).prev().attr("id", "position-"+position).insertAfter($(this));
            $(this).attr("id", "position-"+(position*1 - 1));
        }

        $(this).hide().after('<div id="item-large"></div');
        $("#content.happy-clients a, #item-large").css("float", column == 3 ? "right" : "left");

        $.ajax({  
            type: "GET",  
            url: $(this).attr("href"),  
            dataType: "html",
            beforeSend: function() {
                $("#big-red").hide();
                $("#ajax-loader").show();
            },
            complete: function() {
                $("#ajax-loader").hide();
            },
            success: function(result) {                
                $("#item-large").html(result);
            }  
        });
    });
    
    $("a.item-large").click(function(e) {
        e.preventDefault();        
    });
    
    $("#contact,#add-comment").validate({
        errorElement: "span",
        errorClass: "error",
        messages: {
            f_name: "Please enter your name.",
            f_email: {
                required: "Please enter your email address.",
                email: "Invalid email address."
            },
            f_company: "Please enter your company name.",
            f_phone: "Please enter your phone number.",
            f_project_summary: "Please describe your project."
        }
    });
    
    if (typeof($('img').lazyload) == 'function')
    $("img").lazyload({ 
        placeholder : "/web/desktop/themes/doejo/images/big-ajax-loader.gif"
    });
    
    $("#carousel li").click(function() {
        $("#carousel li.active").removeClass("active");
        $(this).addClass("active");
        
        $("#carousel img").hide();
        $("#carousel img.carousel-img-"+$(this).attr("id").substring(12)).show();
    });

});

$(document).ready(function(){
     var fb_opts = {
            'cyclic'        : true,
            'autoScale'		: false,
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'width'		: 640,
            'height'		: 360,
            'type'			: 'swf',
            'showNavArrows' : false,
            'titlePosition' : 'inside',
            'swf'           : {
                    'wmode': 'transparent',
                    'allowfullscreen'	: 'true'
            }
    };
    
    $(".archives-selector").change(function() {
        document.location = $(this).val();
    });
    
    if (typeof($('#searchbox').placeholder) == 'function') $("#searchbox").placeholder();
    
    $(".vimeo").click(function(){
            $.fancybox(		
                   $.extend(fb_opts, {
                        'href' : 'http://vimeo.com/moogaloop.swf?clip_id='+ this.href.substring(this.href.lastIndexOf('/')+1) +'&fullscreen=1&autoplay=1&show_portrait=0&show_byline=0&show_title=0'
                    })
            );
            return false;
    });
    
    

});