//code from http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx
function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}
// end code from bloggindeveloper.com

var $j = jQuery.noConflict();
$j(document).ready(function() {
    var showLogin = document.location.toString().toLowerCase().indexOf("showlogin=yes") != -1;
    if (showLogin == true) {
        $j('a.thickbox.signin').trigger("click")
    };
    var showSurvey = document.location.toString().toLowerCase().indexOf("showsurvey=yes") != -1;
    if (showSurvey == true) {
        $j('a.thickbox.survey').trigger("click")
    };
    $j('a[rel="external"]').click(function() {
        window.open($j(this).attr('href')); return false
    });
    $j('body').css('display', 'block');
    if ($j('#topnav').length) $j('#topnav ul li:first').css('background', 'none');
    if ($j('.subnav').length) $j('ul.subnav li:first a').css('padding-left', 20);
    if ($j('.main dl').length) $j('.internal .main dl:last').css('margin-bottom', 0);
    if ($j('.entry:last').length || $j('.row:last').length) $j('.entry:last, .row:last').css('border-bottom', 'none');
    if ($j('.member_spotlight').length) {
        var elementHeight = $j('.member_spotlight').outerHeight();
        $j('.member_spotlight').innerfade({ speed: 1000, timeout: 6000, type: 'sequence' })
    };
    if ($j('.sidebar dl dt a').length) $j(".sidebar dl dt a").bigTarget({ hoverClass: 'over', clickZone: 'dl:eq(0)' });
    if ($j('.button a').length) $j(".button a").bigTarget({ hoverClass: 'over', clickZone: 'div:eq(0)' });
    //if ($j('.main dl dt a').length) $j('.main dl dt a').bigTarget({ hoverClass: 'over', clickZone: 'dl:eq(0)' });
    if ($j('.button div a').length) $j('.button div a').bigTarget({ hoverClass: 'over', clickZone: 'div:eq(0)' });
    if ($j('.member_spotlight div a').length) $j('.member_spotlight div a').bigTarget({ hoverClass: 'over', clickZone: 'div:eq(0)' });
    if ($j('.tabs').length) {
        $j('.home ul.tabs').tabs({ fx: { opacity: 'toggle'} }).tabs('rotate', 5000, 'true');
        $j('.home ul.tabs li a').click(function() {
            $j('.home ul.tabs').tabs('rotate', null)
        })
    };
    if ($j('.star_rating:radio.star').length) $j('.star_rating:radio.star').rating();
    if ($j('.tooltip').length) {
        $j('.tooltip').each(function() {
            var time = 100;
            var hideDelay = 50;
            var hideDelayTimer = null;
            var beingShown = false;
            var shown = false;
            var parentTip = $j('dd.description', this).parent();
            var trigger = $j('.trigger', this);
            var info = $j('dd.description', this).css('opacity', 0); $j([trigger.get(0), info.get(0)]).mouseover(function() {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) { return } else {
                    beingShown = true; info.css('z-index', 100); info.css('display', 'block').animate({ opacity: 1 }, time, 'swing', function() {
                        beingShown = false; shown = true
                    }); parentTip.css('z-index', 100)
                } return false
            }).mouseout(function() {
                if (hideDelayTimer) clearTimeout(hideDelayTimer); hideDelayTimer = setTimeout(function() {
                    hideDelayTimer = null; info.animate({ opacity: 0 }, time, 'swing', function() {
                        shown = false; info.css('display', 'none')
                    })
                }, hideDelay, info.css('z-index', 0), parentTip.css('z-index', 0)); return false
            })
        })
    };
    $j("label.overlabel").overlabel(); if ($j('.flow.three').length) {
        $j('.flow.three').each(function() {
            var getItems = $j(this).find('li').size();
            if (getItems > '1') { $j(this).columnize({ width: 200, balance: true }) } else {
                $j(this).addClass('single')
            }
        })
    };
    if ($j('.flow.two').length) {
        $j('.flow.two').each(function() {
            var getItems = $j(this).find('li').size();
            if (getItems > '1') { $j(this).columnize({ width: 300, balance: true }) } else {
                $j(this).addClass('single')
            }
        })
    };
    var headerHeight = $j('#header').outerHeight();
    var billboardHeight = $j('.billboard').outerHeight();
    var leftHeight = $j('.billboard .left').outerHeight();
    var rightBottomHeight = $j('.billboard .right .bottom').outerHeight();
    var titleHeight = $j('.billboard .title').outerHeight();
    var graphHeight = 335;
    if (window.console && window.console.log) { window.console.log('Total billboard height: ', billboardHeight); window.console.log('Total left coulmn height: ', leftHeight); window.console.log('Total right column height: ', rightBottomHeight); window.console.log('Total title height: ', titleHeight) };
    if ($j(".billboard .title").length) {
        if ((leftHeight + titleHeight) <= rightBottomHeight) {
            $j('.billboard, .billboard .right').css({ 'height': rightBottomHeight });
            $j('#graph').css('top', (headerHeight + billboardHeight - graphHeight + 29));
            if (window.console && window.console.log) window.console.log('Left coulmn height is less then right column')
        } else if (leftHeight >= rightBottomHeight) {
            $j('.billboard .right, .billboard').css({ 'height': leftHeight + titleHeight });
            $j('#graph').css('top', (headerHeight + billboardHeight + titleHeight + 29 - graphHeight));
            if (window.console && window.console.log) window.console.log('Left coulmn height is greater then right column')
        } else {
            $j('.billboard .right, .billboard').css('height', billboardHeight + titleHeight); $j('#graph').css('top', (headerHeight + billboardHeight + titleHeight + 29 - graphHeight));
            if (window.console && window.console.log) window.console.log('Billbaord height has been set by the right coulmn')
        }
    };
    if ($j('.billboard').outerHeight() <= $j('.billboard .right .bottom').outerHeight()) {
        $j('.billboard .right, .billboard').css('height', ($j('.billboard').outerHeight() + 20));
        $j('#graph').css('top', (headerHeight + $j('.billboard').outerHeight() + 29 - graphHeight));
        if (window.console && window.console.log) window.console.log('Space added between the right coulmn and the nav')
    };
    if ($j(".billboard .title").length) { return } else {
        if (($j('.billboard').outerHeight() <= $j('.billboard .right .bottom').outerHeight())) {
            $j('.billboard .right, .billboard').css('height', ($j('.billboard').outerHeight() + 110));
            $j('#graph').css('top', (headerHeight + $j('.billboard').outerHeight() + 29 - graphHeight));
            if (window.console && window.console.log) window.console.log('Detected split class, billboard height is less then right column')
        } else {
            $j('.billboard .right, .billboard').css('height', ($j('.billboard').outerHeight() + 31)); $j('#graph').css('top', (headerHeight + $j('.billboard').outerHeight() + 29 - graphHeight));
            if (window.console && window.console.log) window.console.log('Detected split class, billboard height has been set by the right coulmn')
        }
    };
    if ($j('.home').length) {
        $j('.billboard .right, .billboard').css({ 'height': $j('.billboard .right .bottom').outerHeight() + 20 });
        $j('#graph').css('top', (headerHeight + $j('.billboard .right .bottom').outerHeight() - graphHeight - 11));
        if (window.console && window.console.log) window.console.log('Detected home class, billboard height has been set by the right coulmn')
    }
});

function css_browser_selector(u) {
    var ua = u.toLowerCase(), is = function(t) {
        return ua.indexOf(t) > -1
    }, g = 'gecko', w = 'webkit', s = 'safari', h = document.getElementsByTagName('html')[0], b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : /opera(\s|\/)(\d+)/.test(ua) ? 'opera opera' + RegExp.$2 : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' ' + s + ' chrome' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c
}; css_browser_selector(navigator.userAgent);