/**
 * AJAX Nette Framwork plugin for jQuery
 *
 * @copyright   Copyright (c) 2009 Jan Marek
 * @license     MIT
 * @link        http://nettephp.com/cs/extras/jquery-ajax
 * @version     0.2
 */
jQuery.extend({
    nette: {
        updateSnippet2: function(id,html){
            $("#" + id).html(html);
        },
        updateSnippet: function (id, html) {

            var options = {
                speed:600
            };

            if(id == "snippet--rightColumn"){
                //alert("snippet update");
                $("#" + id).hide("slide", {
                    direction:"right"
                }, options.speed, function () {
                    var el = $(this).html(html);
                    if(window.location.hash == "#gallery"){
                        $("#bottomGallery").gallery("loadImage",1);
                    }
                    if(window.location.hash == "#portfolio"){
                        $("#bottomGallery").gallery("loadImage",1);
                    }
                    el.show("slide",{
                        direction:"right",
                        mode:"show"
                    }, options.speed, function(){
                        //alert("rightColumn is shown!");
                        });
                    $.nette.registerAfterUpdate();
                });
            }

            else if(id == "snippet--leftColumn"){

                $("#" + id).hide("slide", {
                    direction:"down"
                }, options.speed, function () {
                    var el = $(this).html(html);
                    el.show("slide",{
                        direction:"up",
                        mode:"show"
                    }, options.speed, function(){
                        
                        });
                    $.nette.registerAfterUpdate();
                });
            }

            else{
                $("#" + id).fadeOut("medium", function () {
                    $(this).html(html).fadeIn("medium");
                    $.nette.registerAfterUpdate();
                });
            }
            if($.browser.msie){
        //$(this).get(0).style.removeAttribute('filter');
        }
        },
        success: function (payload) {
            // redirect
            if (payload.redirect) {
                window.location.href = payload.redirect;
                return;
            }

            // snippets
            if (payload.snippets) {
                if($.cookie('redirecting')){
                    for (var i in payload.snippets) {
                        jQuery.nette.updateSnippet2(i, payload.snippets[i]);
                    }
                    $.cookie('redirecting',null);
                    if(window.location.hash == "#gallery"){
                        galleryChanges($(""),0,false);
                        $("#bottomGallery").gallery("loadImage",1);
                    }
                    if(window.location.hash == "#portfolio"){
                        $("#bottomGallery").gallery("loadImage",1);
                    }
                }
                else{
                    for (var i in payload.snippets) {
                        jQuery.nette.updateSnippet(i, payload.snippets[i]);
                    }
                }
            }
        },
        registerAfterUpdate: function() { }
    }
});

jQuery.ajaxSetup({
    success: jQuery.nette.success,
    dataType: "json"
});
