var RzutOka = {
    init: function() {
        RzutOka.Fonts.init();
        RzutOka.Anchors.init();
        RzutOka.OpenModal.init();
        RzutOka.OpenWindow.init();
        RzutOka.SlideShow.init();
        RzutOka.Portfolio.init();
        RzutOka.ScrollPane.init();
    },
    Fonts: {
        init: function() {
            Cufon.replace('#header #main-menu ul li a', {hover: true});
            Cufon.replace('#header #langs ul li a', {hover: true});
            Cufon.replace('#tagline-sub-menu', {hover: true});
            Cufon.replace('#footer #facebook');
            Cufon.replace('#footer #foot-menu ul li a', {hover: true});
        }
    },
    Anchors: {
        init: function() {
            jQuery("[rel=ext]").click(function(){window.open(this);return false;});
            jQuery('a').click(function(){this.blur();});
        }
    },
    OpenModal: {
        init: function() {
            jQuery(document).ready(function(){
                jQuery("a[rel^='project']").prettyPhoto({
//                    deeplinking: false,
                    social_tools: '',
                    default_width: 843,
                    default_height: 400,
                    changepicturecallback: function() {
                        RzutOka.Portfolio.readInit();
                    }
                });
            });
        }
    },
    OpenWindow: {
        init: function() {
            jQuery("[rel=reference]").click(RzutOka.OpenWindow.go);
        },
        go: function() {
            var anc = jQuery(this);
            var w = 630, h = 440;
            if (window.screen) {
                w = window.screen.availWidth * 60 / 100;
                h = window.screen.availHeight * 90 / 100;
            }
            window.open(anc.attr('href'), 'RzutOkaReference', 'width='+w+',height='+h);
            return false;
        }
    },
    SlideShow: {
        init: function() {
            jQuery('ul#main-page-gallery-assets').cycle({
                pause : true,
                pager : 'div#main-page-gallery-buttons'
            });
        }
    },
    Portfolio: {
        init: function() {
            jQuery('div#portfolio').cycle({
                fx      : 'scrollHorz',
                timeout : 0,
                next    : '.portfolio_arrow_right',
                prev    : '.portfolio_arrow_left'
            });
        },
        readInit: function() {
            var images = jQuery('div.project-read-gallery-images');
            if(images.length > 1) {
                jQuery('.project-read-gallery-arrow-right').show();
                jQuery('.project-read-gallery-arrow-left').show();
                images.cycle({
                    fx      : 'scrollHorz',
                    timeout : 0,
                    next    : '.project-read-gallery-arrow-right',
                    prev    : '.project-read-gallery-arrow-left',
                    pager   : '.project-read-gallery-thumbs',
                    pagerAnchorBuilder: function(index, DOMelement) {
                        var selector = ['.project-read-gallery-thumbs-source div.project-read-gallery-thumb:nth-child(', ')'].join(index+1);
                        return jQuery(selector).clone().wrap('<div>').parent().html();
                    }
                });
            }
            else {
                jQuery('.project-read-gallery-arrow-right').hide();
                jQuery('.project-read-gallery-arrow-left').hide();
            }
        }
    },
    ScrollPane: {
        pane: null,
        init: function() {
            this.pane = jQuery(".about-us-pane");
            this.pane.jScrollPane();
        }
    }
}

jQuery(document).ready(RzutOka.init);

/* debug */
var ConsoleProxy = {
    check: function() {
        return (typeof console === "object");
    },
    log: function(obj) {
        if(this.check())
            console.log(obj);
    },
    debug: function(msg) {
        if(this.check())
            console.debug(msg);
    },
    warn: function(msg) {
        if(this.check())
            console.warn(msg);
    },
    error: function(msg) {
        if(this.check())
            console.error(msg);
    },
    msg: function(msg) {
        if(this.check())
            console.error(msg);
    },
    group: function(name) {
        if(this.check())
            console.group(name);
    },
    groupEnd: function() {
        if(this.check())
            console.groupEnd();
    }
}
