$(document).ready(function() {

    /******* image slider on the home page **************/
    var homePage = $('body.pg-home');
    if (homePage.length >= 1) {
        $('#imgSlider').crossSlide({
            fade: 1
        }, [
  {
      src: '/images/imgSlider/carney1.jpg',
      from: '100% 80% 1x',
      to: 'top left 1.7x',
      time: 13
  }, {
      src: '/images/imgSlider/carney2.jpg',
      from: 'top left',
      to: 'bottom right 1.5x',
      time: 15
  }, {
      src: '/images/imgSlider/carney3.jpg',
      from: '100% 80% 1.5x',
      to: '80% 20% 1.1x',
      time: 12
  }, {
      src: '/images/imgSlider/carney4.jpg',
      from: '100% 50%',
      to: '30% 50% 1.5x',
      time: 14
  }
  , {
      src: '/images/imgSlider/carney5.jpg',
      from: '100% 50%',
      to: 'bottom right 1.5x',
      time: 15
  }
]);
        
    } //end:if
    /******* end: image slider on the home page **************/

});    // end:DOM ready

/************************************************** keep element at the bottom *********************************/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}


    function getWindowHeight() {
        var windowHeight = 0;
        if (typeof (window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else {
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
            }
        }
        return windowHeight;
    }

    function setFooter() {

        if (document.getElementById('hd') && document.getElementById('bd') && document.getElementById('global-chrome-content')) {
            document.getElementById('global-chrome-content').style.display = 'block';
            
            var windowHeight = getWindowHeight();
            var hdHeight = document.getElementById('hd').offsetHeight;
            var bdHeight = document.getElementById('bd').offsetHeight;
            var ftHeight = document.getElementById('global-chrome-content').offsetHeight;
            var diff = (windowHeight - (hdHeight + bdHeight)) - ftHeight;
            if (diff >= 0) {
                document.getElementById('global-chrome-content').style.marginTop = diff - 10 + 'px';
            }
        } //end:if
    }
    addLoadEvent(setFooter);
    window.onresize = function() { setFooter(); }
/************************************************** end: keep element at the bottom *********************************/

    /************************************************** twitter linkify and add classes *********************************/
    $(document).ready(function() {

        try {
            $("div.s_twitter .singleUser:even").addClass("even").parent().find('a:first').addClass("even");
            $("div.s_twitter .singleUser:odd").addClass("odd").parent().find('a:first').addClass("odd");
            $(".s_twitter p").each(function() {
                var $this = $(this);
                $this.attr("innerHTML", linkify($this.attr("innerHTML")));
            });
        }
        catch (e) {
            return false;
        }
        
    });  // end:DOM ready




    function linkify(s) {
        return s.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) {
            return m.link(m);
        }).replace(/@[\S]+/g, function(m) {
            return '<a href="http://twitter.com/' + m.substr(1) + '">' + m + '</a>';
        });
    }
    /************************************************** end:twitter  *********************************/

    $(document).ready(function() {

        try {
            $("#tabs").tabs();
            $("#tabs").tabs('select', 1);
        }
        catch (e) {
            return false;
        }


    });  // end:DOM ready



/*### popupWindow - regular JS  ###*/
    function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                oldonload();
                func();
            }
        }
    }
    // END


    var popupConfig = {
        targetedElement: 'a',
        targetedElementClassName: 'popupWindow',
        width: 310,
        height: 260
} // end:configuration

        function popupWindows() {
            var links = document.getElementsByTagName(popupConfig.targetedElement);
            for (var i = 0; i < links.length; i++) {
                if (links[i].className == popupConfig.targetedElementClassName) {
                    links[i].onclick = function() {
                        openPopup(this.getAttribute("href"));
                        return false;
                    } // end:onclick
                } // end:if
            } // end:for
        } // end:function
        addLoadEvent(popupWindows);

        function openPopup(linkURL) {
            var popupParametars = 'width=' + popupConfig.width + ',height=' + popupConfig.height;
            window.open(linkURL, 'popup', popupParametars)
        }

        /*### end:popupWindow  ###*/
