﻿        // Set the image to the zero-based index of the image you want to appear first once a day per user.
        var showFirstImage = 4; // showing qmmunity
        
        (function() {
          var $ = jQuery;

          $(window).bind('load', function() {
            $('#hideContent').remove();
            $('.content').hide();
            setTimeout(function() {
              $('.content').fadeOut(0).fadeIn();
            }, 100);
          });

          document.write("<style id=\"hideContent\">.content{display: none;}</style>");

          jQuery(function($){
            if($(document.body).attr('class').split(/ /).length == 1) 
              $('.sub:visible').hide().slideDown('slow');

            $('.header-menu a').click(function(e) {
              e.preventDefault();
              var location = $(this).attr('href');
              $('.content').fadeOut(function() {
                window.location = location;
              });
            });
                
            $('.header-menu > li > a').click(function(e) {
              e.preventDefault();
              var sub = $('.sub-wrapper:visible');
              var location = $(this).attr('href');
              

              sub.slideUp(function() {
                window.location = location;
              });
              
              if(sub.length) return false;
            });
          
            $('.temp').retainRandomChild().show();
           
            $('body').prepend('<div id="status-text">');
            $.preloadCssImages();
          });
          
          $.fn.retainRandomChild = function() {
            var currentTime = new Date();
            var currentDate = currentTime.getMonth() + 1 + '/' + currentTime.getDate() + '/' + currentTime.getFullYear();
            
            if (getViewedCookie('currentSession') == sessionId) {
                var children = this.children();
                var child = $(children.get(Math.floor(Math.random() * children.length)));
                if(child[0] == document) return $([]);
                child.siblings().remove();  
                return child;
            } else {
                setViewedCookie('currentSession', sessionId);
                var children = this.children();
                var child = $(children.get(showFirstImage));
                if(child[0] == document) return $([]);
                child.siblings().remove();  
                return child;
            }
          }
        })();
        
        function setViewedCookie(name, value){
            document.cookie = name+"="+value
        }
        
        function getViewedCookie(Name){ 
            var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
            if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
            return ""
        }