//====CUSTOMIZED JQUERY====//

$=jQuery.noConflict();

$(function() {
    
    $('.postLarge, .postSmall, .articlePost').each(function() {
        $('.loadit', this).removeClass('loadit');
        var identity = $(this).attr('id');
        if(!($.cookie("rate-"+identity+"") === "rated")) {
            $('.post-ratings img', this).click(function() {
                $(this).parent().parent().removeClass('rate').addClass('rated');
                $.cookie("rate-"+identity+"", "rated", { path: '/', expires: 365 });
            });
        }
        if($.cookie("rate-"+identity+"") === "rated") {
            if($('.postButton.rate', this).length > 0) {
                $('.postButton.rate', this).removeClass('rate').addClass('rated');
            }
            if($('#ratingLarge', this).length > 0) {
                $('#ratingLarge', this).removeClass('rate').addClass('rated');
            }
            var pr = $('.post-ratings img', this);
            pr.attr('title','You love it!');
            pr.removeAttr('onmouseover');
            pr.removeAttr('onmouseout');
            pr.removeAttr('onclick');
            pr.removeAttr('onclick');
            pr.removeAttr('onkeypress');
            pr.removeAttr('style');
        }
        
    });   
    
    var closeDate = new Date();
    var today = new Date();
    
    if(closeDate != null) {
    
        if($.cookie("WelcomeBar") === "closed") {
            $('#welcomeBar').css({display: 'none'});
        }
        else {
            $('#welcomeBar').css({display: 'block', marginTop: '0'});
            if(!($.browser.msie)) {
                $('#welcomeClose').css({opacity: 0.5});
                $('#welcomeClose').hover(function() {
                    $(this).stop().animate({opacity: 1}, 200);
                },function() {
                    $(this).stop().animate({opacity: 0.5}, 200);
                });
            }
        }
        
        if(closeDate < today) {
            $('#welcomeBar').css({display: 'none'});
        }
        
        $('#welcomeClose').click(function() {
            $('#welcomeBar').animate({marginTop: '-43px'}, 300);
            $.cookie("WelcomeBar", "closed", { path: '/' });
        });
        
    }

    $('.postThumbnail').each(function() {
    
        $('.thumbnailHover', this).css({opacity: 0, display: 'block'});
    
        $(this).hover(function() {
            $('.thumbnailHoverContent', this).stop().animate({opacity: 0.4}, 'fast');
            $('.thumbnailHoverArrow', this).stop().animate({opacity: 1}, 'fast');
            $('.thumbnailHover', this).stop().animate({opacity: 0.1}, 'fast');
        },function() {
            $('.thumbnailHoverContent', this).stop().animate({opacity: 0}, 'fast');
            $('.thumbnailHoverArrow', this).stop().animate({opacity: 0}, 'fast');
            $('.thumbnailHover', this).stop().animate({opacity: 0}, 'fast');
        });
        
    });
    
    if($('#share_buttons_wrapper').length > 0 ) {
    
        var top = $('#share_buttons_single_page').offset().top - parseFloat($('#share_buttons_single_page').css('margin-top').replace(/auto/, 0));

        $(window).scroll(function (event) {

            // what the y position of the scroll is

            var y = $(this).scrollTop();
            // whether that's below the form
            if (y >= top-20) {
                // if so, ad the fixed class
                $('#share_buttons_single_page').addClass('fixed');
            } else {
                // otherwise remove it
                $('#share_buttons_single_page').removeClass('fixed');
            }
        });
    
    }
    
    $('div.author').each(function() {
        
        if($('.blackTip', this).length > 0) {
        
            $width = $('.blackTip', this).width();
            $hw = -($width/2);
            
            $('.blackTip', this).css({marginLeft: $hw});
            
            $(this).hover(function() {
               $('.blackTip', this).css({display: 'block'}).stop().animate({opacity: 1}, 'fast');
            },function() {
                $('.blackTip', this).stop().animate({opacity: 0}, 'fast', function() {
                    $(this).css({display: 'none'});
                });
            });
            
        }
    
    });
    
    if($('#expand').length > 0 ) {
    
        $('#expand').toggle(function(e) {
        
            e.preventDefault();
            
            $('.ddArrow', this).html('&#9650;');

            $('#authorBio').addClass('show');

        },function() {
        
            $('.ddArrow', this).html('&#9660;');
            
            $('#authorBio').removeClass('show');
                    
        });
        
    }
    
    var $color1 = '#97b62c';
    var $color2 = '#ebd077';
    var $color3 = '#d95b44';
    var $color4 = '#c12942';
    var $color5 = '#45494c';
    
    $('#rated ul li:nth-child(1) .score').css({backgroundColor: $color1, borderColor: $color1});
    $('#rated ul li:nth-child(2) .score').css({backgroundColor: $color2, borderColor: $color2});
    $('#rated ul li:nth-child(3) .score').css({backgroundColor: $color3, borderColor: $color3});
    $('#rated ul li:nth-child(4) .score').css({backgroundColor: $color4, borderColor: $color4});
    $('#rated ul li:nth-child(5) .score').css({backgroundColor: $color5, borderColor: $color5});
    
    
    $('#popular ul li').each(function() {
        $(this).hover(function() {
            $('a span', this).stop().animate({marginLeft: 0}, 200);
        },function() {
            $('a span', this).stop().animate({marginLeft: '-52px'}, 100);
        });
    });
    
});



$(function() {

    if(!($.browser.msie && $.browser.version < 9)) {
        
        $('.writer, .dlit').bind('click', function(e) {
        
            var $thisa = $(this);
            
            var $this = $(this).attr('href');

            if($(this).hasClass('writer')) {
                var source = 'http://thefinishedbox.com/writer.html';
                var subscribe = null;
            }
                        
            if($(this).hasClass('dlit')) {
                var source = 'http://thefinishedbox.com/subscribe.html';
                var subscribe = 'lb-subscribe';
            }
            
            if($(this).hasClass('writer') || $.cookie("Subscribed") != "testing") {    
            
                e.preventDefault();
            
                if($('#overlay').length < 1) {
                
                    $('#wrapper').append('<div id="overlay" /><div id="loader" class="loadLoader" />');
                    $('#overlay').css({opacity: 0});
                    $('#overlay').animate({opacity: 0.38}, 500, function() {
                        //after the overlay fades in
                        $('#wrapper').append('<div id="lightBoxOuter" />');
                                        
                        $('#lightBoxOuter').css({opacity: 0});
                        $('#lightBoxOuter').append('<div id="lightBox"><div id="innerContent" /><div id="loader" class="lightBoxLoader" /></div>');
                            $('#innerContent').css({opacity: 0});
                            $('.lightBoxLoader').css({opacity:0, display: 'block'});
                            $('.lightBoxLoader').animate({opacity: 1}, 200, function() {
                                $('#innerContent').load(source, function() {
                                
                                    $('.loadLoader').remove();
                                    var width = $('#lightBoxOuter').outerWidth(); var height = $('#lightBoxOuter').outerHeight();
                                    var halfw = -(width/2); var halfh = -(height/2);
                                    $('#lightBoxOuter').css({marginTop: halfh, marginLeft: halfw});
                                    
                                    $('#lightBoxOuter').animate({opacity: 1}, 300, function() {
                                        
                                        if(subscribe === 'lb-subscribe') { $('#innerContent').addClass(subscribe); }
                                        
                                        if($thisa.hasClass('dltut')) {
                                            $('#lightBoxTitle').text("Don't miss another Tutorial!");
                                        }
                                        
                                        var innerWidth = $('#innerContent').outerWidth(); var innerWidthHalf = -(innerWidth/2);
                                        var innerHeight = $('#innerContent').outerHeight(); var innerHeightHalf = -(innerHeight/2);
                                        
                                        $('#lightBox').animate({width: innerWidth}, 300);
                                        $('#lightBoxOuter').animate({marginLeft: innerWidthHalf}, 300, function() {
                                            $('#loader').animate({opacity: 0}, 200, function() {
                                                $(this).remove();
                                            });
                                            $('#lightBox').animate({height: innerHeight}, 300);
                                            $('#lightBoxOuter').animate({marginTop: innerHeightHalf}, 300, function() {
                                                $('#innerContent').append('<div id="lightBoxClose" />');
                                                $('#lightBoxClose').css({opacity:0, display: 'block'});
                                                $('#lightBoxClose').animate({opacity:0.5});
                                                $('#innerContent').css({display: 'block'}).animate({opacity: 1}, 300, function() {
                                                    if(subscribe === 'lb-subscribe') {
                                                        window.location.href = $this;
                                                    }
                                                });
                                            });
                                        });
                                    });
                                });
                            });

                    });
                    
                    //overlay close function
                    $('#overlay, #lightBoxClose').live('click', function() {
                        $('#lightBoxOuter').animate({opacity: 0}, 250, function() {
                            $(this).remove();
                        });
                        $('#overlay').animate({opacity: 0}, 400, function() {
                            $(this).remove();
                        });
                    });
                    
                    $('#lightBoxClose').live('mouseenter', function() {
                        $(this).stop().animate({opacity: 1}, 300);
                    }).live('mouseleave', function() {
                        $(this).stop().animate({opacity: 0.5}, 300);
                    });
                    
                    
                    $('#alreadySubscribed a').live('click', function(i) {
                        i.preventDefault();
                        $('#lightBoxOuter').animate({opacity: 0}, 250, function() {
                            $(this).remove();
                        });
                        $('#overlay').animate({opacity: 0}, 400, function() {
                            $(this).remove();
                        });
                        $.cookie("Subscribed", "true", { path: '/', expires: 365});
                    });
                    
                }
                
            }
            
        });
    }
    
});
 





















