var Aruna = {
    init : function() {
        "use strict"
        //console.log(this.shadeColor('#7F46DD', -7)); //first
        //console.log(this.shadeColor('#7F46DD', -14)); //second

        jQuery('ul.sf-menu').supersubs({
           minWidth:    12, // minimum width of sub-menus in em units
           maxWidth:    40, // maximum width of sub-menus in em units
           extraWidth:  1 // extra width can ensure lines don't sometimes turn over
         })
        .superfish({delay: 0}); // call supersubs first, then superfish

        jQuery('a[href=#postModal]').on('click', function() { 
            jQuery('.post-window input:text, .post-window input:file, select.post_type, textarea').val('');
            jQuery('#postModal select.post_type').val('window-image');
            jQuery("select.post_type").data("selectBox-selectBoxIt").destroy();
            jQuery('#myCombobox, #categoryCombobox').selectBoxIt({
                autoWidth: false
            });
        });

        //checking for login, making sure the username and the password are not empty
        jQuery('#login-button').on('click', function() {
            var formparent = jQuery(this).parent().parent(),
                inputlog = formparent.find('input[name=log]'),
                inputpwd = formparent.find('input[name=pwd]');
            if(inputlog.val() == '') {
                inputlog.parent().css("border", "1px solid red");
                return false;
            }
            else {
                inputlog.parent().css("border", "none");
            }

            if(inputpwd.val() == '') {
                inputpwd.parent().css("border", "1px solid red");
                return false;
            }
            else {
                inputpwd.parent().css("border", "none");
            }
        });

        //disabling the submit button to prevent multiple submissions from the same user
        jQuery('#postModal form').on('submit', function() {
            jQuery(this).find('button').attr("disabled", "disabled");
            return true;
        });

        jQuery('.sf-menu .sub-menu .sf-with-ul').parent().addClass('has-dropdown');
        jQuery('.sf-menu > li > .sf-with-ul').append('<b class="caret"></b>').parent().addClass('dropdown');

        jQuery("img.lazy").lazyload({
            effect : "fadeIn"
        });

        jQuery('.footer-widget').eq(0).parent().removeClass().addClass('col-sm-3');
        jQuery('.footer-widget').eq(1).parent().removeClass().addClass('col-sm-4 col-sm-offset-1');
        jQuery('.footer-widget').eq(2).parent().removeClass().addClass('col-sm-3 col-sm-offset-1');

        //fixing comment form submit button by adding custom css classes
        jQuery('#contact_submit').addClass('btn btn-primary btn-lg custom-button');

        //comments button to redirect to the comment form 
        jQuery('.comments-counter button').on('click', function() {
            jQuery.scrollTo('.comments-form', 300);
        })
        
        //bookmarks AJAX processing
        jQuery('.loggedin.bookmark, .loggedin.bookmarked').on('click', function(e) {
            e.preventDefault();
            var $this = jQuery(this),
                id = $this.data('id');
            if($this.hasClass('bookmarked') ) {
                //remove bookmark
                jQuery.post(MyAjax.ajaxurl, {
                    action : 'bookmark-remove',
                    post_id : id
                },
                function() {
                    //we sent the data, now we update the button bg color and tooltip
                    $this.tooltip("destroy");
                    $this.data('title', 'BOOKMARK');
                    $this.removeClass('bookmarked');
                    $this.addClass('bookmark');
                });
            }
            else {
                //add bookmark
                jQuery.post(MyAjax.ajaxurl, {
                    action : 'bookmark-submit',
                    post_id : id
                },
                function() {
                    //we sent the data, now we update the button bg color and tooltip
                    $this.tooltip("destroy");
                    $this.data('title', 'BOOKMARKED');
                    $this.removeClass('bookmark');
                    $this.addClass('bookmarked');
                });
            }
        });

        //post rating AJAX processing
        jQuery('.counters-line .pull-right a').on('click', function(e) {
            e.preventDefault();
            var $this = jQuery(this),
                id = $this.data('id'),
                voted = $this.data('voted'),
                vote = $this.data('vote'),
                toggle = $this.data('toggle'),
                className = $this.parent().attr("class"),
                className2 = '';

            //getting the sibling class, for further processing
            if(className == 'like') {
                className2 = 'dislike';
            }
            else {
                className2 = 'like';
            }

            //we go up 2 levels to get the sibling rating div
            var sibling = $this.parent().parent().find('.' + className2 + ' a'),
                voted2 = sibling.data('voted');


            if(voted == '1' || (vote != '0' && vote != '1') ) {
                return false;
            }

            if(typeof(toggle) === 'undefined') {
                $this.data('voted', '1');
                sibling.data('voted', '0');
                jQuery.post(MyAjax.ajaxurl, {
                    action : 'rate-submit',
                    post_id : id,
                    vote_id : vote
                    },
                    function() {
                        //we update the meta data for each like/dislike button accordingly
                        $this.data('voted', '1');
                        var icn = $this.find('i');
                        icn.addClass('icon-' + className + 'd');
                        var countnumber = $this.find('.countnumber');
                        //updating the number automatically
                        countnumber.html(parseInt(countnumber.html() )+1);

                        //checking the sibling vote details, to see if the user voted for the first time or he changed it
                        if(voted2 == '1') {
                            countnumber = sibling.find('.countnumber');
                            countnumber.html(parseInt(countnumber.html() )-1);
                            var icn2 = sibling.find('i');
                            icn2.removeClass('icon-' + className2 + 'd');
                        }
                    }
                );
            }
        });
    
        //reposting AJAX processing
        jQuery('.repost').on('click', function(e) {
            jQuery('#postModal input, #postModal textarea').val('');
            e.preventDefault();
            var $this = jQuery(this),
                id = $this.data('id');

            jQuery.post(MyAjax.ajaxurl, {
                    action : 'repost-data',
                    post_id : id
                },
                function(data) {
                    //we sent the data, now we update the button bg color and tooltip
                    var obj = jQuery.parseJSON(data), 
                        format = obj.post_format;

                    //resetting the category selectbox

                    jQuery('#categoryCombobox option').removeAttr("selected");
                    jQuery("#categoryCombobox").data("selectBox-selectBoxIt").destroy();
                    jQuery('#categoryCombobox option[value="' + obj.categories[0] + '"]').attr("selected", "selected");

                    if(format == 'quote') {
                        var wquote = jQuery('.post-window.window-quote'),
                            quote_text = jQuery('<div />').html(obj.quote_text).text(),
                            quote_author = jQuery('<div />').html(obj.quote_author).text(),
                            quote_source = jQuery('<div />').html(obj.quote_source).text(),
                            title = jQuery('<div />').html(obj.title).text();

                        jQuery('select.post_type option').removeAttr("selected");
                        jQuery("select.post_type").data("selectBox-selectBoxIt").destroy();
                        jQuery('select.post_type option[value="window-quote"]').attr("selected", "selected");
                        jQuery('#myCombobox, #categoryCombobox').selectBoxIt({
                             autoWidth: false
                        });

                        //showing the details for the image post format
                        jQuery('.post-window').hide();
                        wquote.show();
                        wquote.find('input[name=quote_title]').val(title);
                        wquote.find('textarea[name=quote]').val(quote_text);
                        wquote.find('input[name=quote_author]').val(quote_author);
                        wquote.find('input[name=quote_source]').val(quote_source);
                        wquote.find('input[name=quoteimage]').val(obj.quote_image);
                        wquote.find('input[name=tags_quote]').val(obj.tags);
                        console.log(wquote.find('input[name=tags]'));
                        if(obj.quote_nsfw == 1) {
                            jQuery('#check13').attr("checked", "checked");
                        }
                        else {
                            jQuery('#check13').removeAttr("checked");
                        }
                    }
                    else if(format == 'gallery') {
                        var wslider = jQuery('.post-window.window-slider'),
                            title = jQuery('<div />').html(obj.title).text(),
                            title1 = jQuery('<div />').html(obj.title1).text(),
                            title2 = jQuery('<div />').html(obj.title2).text(),
                            title3 = jQuery('<div />').html(obj.title3).text(),
                            title4 = jQuery('<div />').html(obj.title4).text(),
                            title5 = jQuery('<div />').html(obj.title5).text(),
                            title6 = jQuery('<div />').html(obj.title6).text(),
                            title7 = jQuery('<div />').html(obj.title7).text(),
                            title8 = jQuery('<div />').html(obj.title8).text(),
                            title9 = jQuery('<div />').html(obj.title9).text(),
                            title10 = jQuery('<div />').html(obj.title10).text();

                        jQuery('select.post_type option').removeAttr("selected");
                        jQuery("select.post_type").data("selectBox-selectBoxIt").destroy();
                        jQuery('select.post_type option[value="window-slider"]').attr("selected", "selected");
                        jQuery('#myCombobox, #categoryCombobox').selectBoxIt({
                             autoWidth: false
                        });

                        //showing the details for the image post format
                        jQuery('.post-window').hide();
                        wslider.show();
                        wslider.find('input[name=title_slider]').val(title);
                        wslider.find('input[name=tags_slider]').val(obj.tags);
                        wslider.find('textarea[name=title1]').val(title1);
                        wslider.find('input[name=image1]').val(obj.image1);
                        wslider.find('textarea[name=title2]').val(title2);
                        wslider.find('input[name=image2]').val(obj.image2)
                        wslider.find('textarea[name=title3]').val(title3);
                        wslider.find('input[name=image3]').val(obj.image3);
                        wslider.find('textarea[name=title4]').val(title4);
                        wslider.find('input[name=image4]').val(obj.image4);
                        wslider.find('textarea[name=title5]').val(title5);
                        wslider.find('input[name=image5]').val(obj.image5);
                        wslider.find('textarea[name=title6]').val(title6);
                        wslider.find('input[name=image6]').val(obj.image6);
                        wslider.find('textarea[name=title7]').val(title7);
                        wslider.find('input[name=image7]').val(obj.image7);
                        wslider.find('textarea[name=title8]').val(title8);
                        wslider.find('input[name=image8]').val(obj.image8);
                        wslider.find('textarea[name=title9]').val(title9);
                        wslider.find('input[name=image9]').val(obj.image9);
                        wslider.find('textarea[name=title10]').val(title10);
                        wslider.find('input[name=image10]').val(obj.image10);

                        if(obj.slider_nsfw == 1) {
                            jQuery('#check10').attr("checked", "checked");
                        }
                        else {
                            jQuery('#check10').removeAttr("checked");
                        }
                    }
                    else if(format == 'video') {
                        var wvideo = jQuery('.post-window.window-video'),
                            title = jQuery('<div />').html(obj.title).text();

                        jQuery('select.post_type option').removeAttr("selected");
                        jQuery("select.post_type").data("selectBox-selectBoxIt").destroy();
                        jQuery('select.post_type option[value="window-video"]').attr("selected", "selected");
                        jQuery('#myCombobox, #categoryCombobox').selectBoxIt({
                             autoWidth: false
                        });

                        //showing the details for the image post format
                        jQuery('.post-window').hide();
                        wvideo.show();
                        wvideo.find('textarea[name=title_video]').val(title);
                        if(obj.localvideo != '') {
                            wvideo.find('input[name=video]').val(obj.localvideo);
                        }
                        else if(obj.externalvideo != '') {
                            wvideo.find('input[name=video]').val(obj.externalvideo);
                        }

                        wvideo.find('input[name=tags_video]').val(obj.tags);

                        if(obj.video_nsfw == 1) {
                            jQuery('#check7').attr("checked", "checked");
                        }
                        else {
                            jQuery('#check7').removeAttr("checked");
                        }
                    }
                    else {
                        var wimage = jQuery('.post-window.window-image'),
                            title = jQuery('<div />').html(obj.title).text();

                        jQuery('select.post_type option').removeAttr("selected");
                        jQuery('select.post_type option[value="window-image"]').attr("selected", "selected");
                        jQuery("select.post_type").data("selectBox-selectBoxIt").destroy();
                        jQuery('#myCombobox, #categoryCombobox').selectBoxIt({
                             autoWidth: false
                        });

                        //showing the details for the image post format
                        jQuery('.post-window').hide();
                        wimage.show();
                        wimage.find('textarea[name=title_image]').val(title);
                        wimage.find('input[name=tags_image]').val(obj.tags);
                        wimage.find('input[name=postimage]').val(obj.thumb);

                        if(obj.standard_nsfw == 1) {
                            jQuery('#check16').attr("checked", "checked");
                        }
                        else {
                            jQuery('#check16').removeAttr("checked");
                        }
                    }
                    jQuery('.tagsinput').remove();
                    jQuery('.tags-selector').tagsInput({
                         autocomplete:{ selectFirst:true,width:'100px',autoFill:true },
                        'interactive':true,
                        'defaultText':'Add tag',
                        'removeWithBackspace' : true,
                        'placeholderColor' : '#afafaf',
                        width: "100%"
                    });
                });

            jQuery("#postModal").modal('show');
        });

        //random post
        jQuery('.random_post').on('click', function(e) {
            e.preventDefault();
            jQuery.post(MyAjax.ajaxurl, {
                action : 'random_post',
                }, function(data) {
                    window.location.href = data;
            });
        });

        //nsfw filters 

        jQuery('figure.nsfw').hover(function() {
            jQuery(this).find('.nsfw_text').animate({"line-height":"358px"}, 400);
            jQuery(this).find('.nsfw_textreveal').css({"opacity" : 0, "display": "block"}).animate({"opacity":1,"top":"-155px"}, 400);
        }, function() {
            jQuery(this).find('.nsfw_text').animate({"line-height":"392px"}, 400);
            jQuery(this).find('.nsfw_textreveal').animate({"opacity":0}, 400);
        });

        jQuery('figure.nsfw').on('click', function() {
            jQuery(this).find('.nsfw_textreveal').css("display", "none");
            jQuery(this).removeClass('nsfw').unbind('hover');
            jQuery.scrollTo(jQuery(this).parent().parent(), 500);
        });


        jQuery('.tags-selector').tagsInput({
            autocomplete:{ selectFirst:true,width:'100px',autoFill:true },
            'interactive':true,
            'defaultText':'Add tag',
            'removeWithBackspace' : true,
            'placeholderColor' : '#afafaf',
            width: "100%"
        });
        jQuery('.tagsinput input')
            .focus(function() {
                jQuery('.tagsinput').css({"border" : "solid 2px #7541cc"});
            })
            .blur(function() {
                jQuery('.tagsinput').css({"border" : "solid 2px #e8e8e8"});
            });
        jQuery('#agreeTerms').on('change', function() {
           if(jQuery(this).is(":checked")) {
               jQuery('#error-button').fadeOut({
                   duration: 500,
                   queue : false,
                   complete : function() {
                       jQuery('#register-button').fadeIn(500);
                   }
               });
           } else {
               jQuery('#register-button').fadeOut({
                   duration: 500,
                   queue : false,
                   complete : function() {
                        jQuery('#error-button').fadeIn(500);
                   }
               });
           }
        });
        jQuery('#agreeTerms2').on('change', function() {
           if(jQuery(this).is(":checked")) {
               jQuery('#error-button2').fadeOut({
                   duration: 500,
                   queue : false,
                   complete : function() {
                       jQuery('#register-button2').fadeIn(500);
                   }
               });
           } else {
               jQuery('#register-button2').fadeOut({
                   duration: 500,
                   queue : false,
                   complete : function() {
                        jQuery('#error-button2').fadeIn(500);
                   }
               });
           }
        });
        jQuery('#myCombobox').selectBoxIt({
            autoWidth: false
        });
        jQuery('#categoryCombobox').selectBoxIt({
            autoWidth: false
        });
        jQuery('#categoryCombobox').bind({
            "change" : function(ev, obj) {
                var color = jQuery('#categoryComboboxSelectBoxItOptions').find('.selectboxit-focus').attr('rel');
                jQuery('#categoryComboboxSelectBoxIt').css({background : color});
            }
        });
        jQuery('#myTab a').click(function (e) {
            e.preventDefault();
            jQuery(this).tab('show');
        })
        this.initFlexsliders();
        jQuery('.has-tooltip').tooltip({
            placement: "bottom",
            animation : "true"
        });
        jQuery('.has-popover').popover({
            placement: "top",
            trigger : "hover"
        });
        jQuery('#postModal').on('shown.bs.modal', function () {
            jQuery(".post-window .window-left").not('.small-padding').mCustomScrollbar({
                scrollInertia : 0,
                scrollButtons:{
                    enable: false
                },
                advanced:{
                    updateOnBrowserResize: true,
                    updateOnContentResize: true
                }
            });
        });
        jQuery(".top-ten .drop-down").mCustomScrollbar({
            scrollInertia : 0,
            scrollButtons:{
                enable: false
            },
            advanced:{
                updateOnBrowserResize: true,
                updateOnContentResize: true
            }
        });
        jQuery(".slider-numbers").mCustomScrollbar({
            scrollInertia : 0,
            scrollButtons:{
                enable: false
            },
            advanced:{
                updateOnBrowserResize: true,
                updateOnContentResize: true
            }
        });
        jQuery(".slider-selector").mCustomScrollbar({
            scrollInertia : 0,
            scrollButtons:{
                enable: false
            },
            advanced:{
                updateOnBrowserResize: true,
                updateOnContentResize: true
            }
        });
        jQuery('.left-aside .sidebar-content').mCustomScrollbar({
            scrollInertia : 0,
            scrollButtons:{
                enable: false
            },
            advanced:{
                updateOnBrowserResize: true,
                updateOnContentResize: true
            }
        });
        jQuery('.top-ten').on('mouseenter', function() {
                jQuery('.top-ten .drop-down').fadeIn({ duration: 400, queue : false });
            }).on('mouseleave', function() {
                jQuery('.top-ten .drop-down').fadeOut({ duration: 400, queue : false });
            });

        jQuery('.social-icons > a').not('.mail').on('click', function(e) {
            e.preventDefault();
            var href = jQuery(this).data('href');
            openWindow(href);
        });

        function openWindow(url){
            var width=640;
            var height=460;
            var topPos=window.screen.height/2-(height/2);
            var leftPos=window.screen.width/2-(width/2);
            window.open(url,"Share", "status=1,height=" + height + ",width=" + width + ",top=" + topPos + ",left=" + leftPos + ",resizable=0");
        }

        var uploadButton = jQuery('<button/>')
            .addClass('btn btn-primary')
            .prop('disabled', true)
            .text('Processing...')
            .on('click', function () {
                var $this = jQuery(this),
                    data = $this.data();
                $this
                    .off('click')
                    .text('Abort')
                    .on('click', function () {
                        $this.remove();
                        data.abort();
                    });
                data.submit().always(function () {
                    $this.remove();
                });
            });

        jQuery('.modal-top-menu button').click(Aruna.switchWindow);
        jQuery('#myCombobox').on("change", Aruna.switchWindowPost);
        jQuery(window).on("scroll", function() {
            jQuery('.main-post').not('.post-page').each(Aruna.stickyButtons);
        });
//        jQuery('input, textarea').placeholder();
        jQuery('.scroll-top').on('click', Aruna.scrollTop);
        this.slidePostCreator();
        this.resizeLeftSidebar();
        jQuery(window).scroll(this.moveLeftSidebar);
        jQuery('.inception-menu .sub-navigation a, .top-menu .section-title a').on("click", Aruna.switchLeftSidebarWindow);
    },
    showScrollTop : function() {
        var windowH = jQuery(window).height();
        var scrollTop = jQuery(window).scrollTop();
        if( scrollTop >= (1.2 * windowH) ) {
            jQuery('.scroll-top').fadeIn({duration: 500, queue : false});
        } else {
            jQuery('.scroll-top').fadeOut({duration: 500, queue : false});
        }
    },
    switchLeftSidebarWindow : function(e) {
        var el = jQuery(this);
        var element = el.attr('rel');
        jQuery('.sidebar-content').not('.'+element).fadeOut(200);
        jQuery('.'+element).fadeIn(200, function() {
            jQuery('.' + element).mCustomScrollbar("update");
        });
        e.preventDefault();
    },
    moveLeftSidebar : function() {
        var move = jQuery(window).scrollTop();
        var maxTop = jQuery(document).height() - (jQuery(window).height() + jQuery('footer').outerHeight() + 10);
        if(move < 0) {
            move = 0;
        }
        if(move >= maxTop) {
            move = maxTop;
        }
        jQuery('.left-aside').css({ top : move+"px"});

        jQuery('.left-aside .sidebar-content').each(function(){
            jQuery(this).mCustomScrollbar("update");
        });
    },
    resizeLeftSidebar : function() {
        var windowH = jQuery(window).height();
        var headerH = jQuery('header').height();
        var menuH = jQuery('.left-aside .top-menu').height();
        jQuery('.left-aside .sidebar-content').height((windowH - headerH - menuH));
        jQuery('.left-aside .sidebar-content').each(function(){
            jQuery(this).mCustomScrollbar("update");
        });
    },
    slidePostCreator : function() {
      jQuery('.slider-numbers a').on('click', function(e) {
          var el = jQuery(this);
          var window = el.attr('rel');
          jQuery('.slider-numbers a.active').removeClass('active');
          jQuery('.slider-selector-window').not('.'+window).fadeOut(300);
          jQuery('.'+window).fadeIn(400);
          el.addClass("active");
          e.preventDefault();
      });
    },
    stickyButtons : function() {
        Aruna.showScrollTop();
        var el = jQuery(this);
        if(el.outerHeight() > 700) {
            var articleTop = el.find('.article-top');
            var buttonsBar = el.find('.buttons-bar');
            var buttonsBarH = buttonsBar.outerHeight();
            var viewportTop =  jQuery(window).scrollTop() + jQuery('header').outerHeight();
            var articleTopH = articleTop.outerHeight();
            var contentH = el.find('.article-content').outerHeight();
            var elPos = {};
            elPos.top = el.offset().top + articleTopH;
            elPos.bottom = el.outerHeight() + elPos.top;

            var top = 0;
            if(elPos.top < viewportTop && elPos.bottom > viewportTop) {
                top = Math.abs(elPos.top - viewportTop);
                var maxTop = contentH - buttonsBarH;
                if(top > maxTop) {
                    top = maxTop;
                }
                buttonsBar.addClass('move');
            } else {
                buttonsBar.removeClass('move');
            }
            buttonsBar.css({
                top: top+"px"
            });
        }
    },
    switchWindowPost : function() {
        var windowName = jQuery(this).val();
        jQuery('.post-window').not('.'+windowName).fadeOut(0, function() {
            jQuery('.'+windowName).fadeIn(500, function() {
            });
        });
    },
    switchWindow : function() {
        var windowName = jQuery(this).attr('rel');
        jQuery('.modal-window').not('.'+windowName).fadeOut(500, function() {
            jQuery('.modal-top-menu button').removeClass('active-ind');
            jQuery('.'+windowName).fadeIn(500, function() {
                jQuery('.modal-top-menu button[rel="'+windowName+'"]').addClass('active-ind');
            });
        });
    },
    scrollTop : function() {
        jQuery('body, html').animate({
            scrollTop : 0
        }, 500);
    },
    initFlexsliders : function() {
        // jQuery('.post-slider').flexslider({
        //     'controlNav': false,
        //     'directionNav' : false,
        //     "touch": true,
        //     "animation": "slide",
        //     "animationLoop": true,
        //     "slideshow" : false,
        //     start : function(ev) {
        //         var slideTotal = ev.find('li:not(".clone") img').length;
        //         var slideCurrent = ev.find('li:not(".clone").flex-active-slide').index();
        //         jQuery('.slider-controls-wrap .counters .total').text(slideTotal);
        //         jQuery('.slider-controls-wrap .counters .current').text(slideCurrent);
        //     },
        //     after : function(ev) {
        //         var slideCurrent = ev.find('li:not(".clone").flex-active-slide').index();
        //         jQuery('.slider-controls-wrap .counters .current').text(slideCurrent);
        //     }
        // });

        // Aruna.createSliderButton('.post-slider', '.slider-controls-wrap .next', 'next');
        // Aruna.createSliderButton('.post-slider', '.slider-controls-wrap .prev', 'prev');

        jQuery('.headlines-slider').flexslider({
            'controlNav': false,
            'directionNav' : false,
            "touch": true,
            "animation": "slide",
            "animationLoop": true,
            "slideshow" : false
        });

        Aruna.createSliderButton('.headlines-slider', '.headline-controls .next', 'next');
        Aruna.createSliderButton('.headlines-slider', '.headline-controls .prev', 'prev');
    },
    createSliderButton : function(slider, button, action) {
        jQuery(button).click(function() {
            jQuery(slider).flexslider(action);
            return false;
        });
    },
    shadeColor : function(color, percent) {

        var R = parseInt(color.substring(1,3),16);
        var G = parseInt(color.substring(3,5),16);
        var B = parseInt(color.substring(5,7),16);

        R = parseInt(R * (100 + percent) / 100);
        G = parseInt(G * (100 + percent) / 100);
        B = parseInt(B * (100 + percent) / 100);

        R = (R<255)?R:255;  
        G = (G<255)?G:255;  
        B = (B<255)?B:255;  

        var RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
        var GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
        var BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));

        return "#"+RR+GG+BB;
    }

};

jQuery(document).ready(function() {
    Aruna.init();
});
jQuery(window).resize(function() {
   Aruna.resizeLeftSidebar();
});

jQuery(window).load(function() {
            jQuery('.layout-masonry').isotope( {
              itemSelector: 'article',
              transformsEnabled: false
            });
        });
