addthis_options = 'google, twitter, live, favorites, reddit, delicious, studivz, meinvz, hellotxt, technorati, myspace, facebook, email, more';
addthis_brand = document.domain.replace("www.", "");
if (parent.frames.length > 0) top.location.replace(document.location);

loading = '<div class="loading"><img src="/img/103.gif" /></div>';
preloadImg = new Image();
preloadImg.src = "/img/103.gif";

// Credits: Robert Penners easing equations (http://www.robertpenner.com/easing/).
jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
	if ((t/=d) < (1/2.75)) {
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)) {
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)) {
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
};

jQuery(document).ready(function()
{
    $('a[name]').each(function(){
        $(this).attr('realurl', $(this).attr('href'));
        $(this).attr('showurl', '/scj/cgi/out.php?fc=1&p=100&link=' + $(this).attr('name') + '&url=' + $(this).attr('href'));
    });
    
    $('a[name]').mousedown(function(){
        $(this).attr('href', $(this).attr('showurl'));
    });
    
    $('a[name]').mouseout(function(){
        $(this).attr('href', $(this).attr('realurl'));
    });
    
    $('a[name]').blur(function(){
        $(this).mouseout();
    });
    
    var searchText = 'Type something to search...';
    
    $('form[name=search]').submit(function(){
        if ($('input[name=q]').val() == '' || $('input[name=q]').val() == searchText) {
            return false;
        }
    });

    $('img.submit').click(function(){
        $(this).parents().filter('form').trigger('submit');
    });
    
    $('input[name=q]').focus(function(){
        if ($(this).val() == searchText) {
            $(this).removeClass('inactive');
            $(this).val('');
        }
    });
    
    $('input[name=q]').blur(function(){
        if ($(this).val() == '') {
            $(this).addClass('inactive');
            $(this).val(searchText);
        }
    });
    
    $('input[name=q]').blur();
        
    $('a').mousedown(function(){
        _gaq.push(['_trackEvent', 'Click', $(this).attr('url')]);
    });

    jQuery('#relatedNishes').jcarousel({
        easing: 'BounceEaseOut',
        size: 20,
        scroll: 5,
        visible: 5,
        animation: 1000
    });

    jQuery('#imLive').jcarousel({
        easing: 'BounceEaseOut',
        wrap: 'circular',
        scroll: 5,
        visible: 5,
        animation: 1000
    });
    
    jQuery('#relatedBottom').jcarousel({
        size: 15,
        scroll: 5,
        visible: 5,
        animation: 1000
    });
    
    $('#relatedToggle').toggle(function(){
        $('#relatedNishesBox').css({
            position: 'static'
        });
        $('#drop-down-icon').css({
            backgroundPosition: '-16px 0'
        });
        return false;
    }, function(){
        $('#relatedNishesBox').css({
            position: 'absolute'
        });
        $('#drop-down-icon').css({
            backgroundPosition: '0 0'
        });
        return false;
    });
    
    $('#bbToggle').click(function(){
        $('.feedback').hide();
        if ($('.bbcode').is(':visible')) {
            $('.bbcode').hide();
        } else {
            _gaq.push(['_trackEvent', 'BBCode', window.location.href]);
            $('.bbcode').show();
        }
        return false;
    });

    $('div.popjs > a').click(function(){
        _gaq.push(['_trackEvent', 'EnoraClicks', window.location.href]);
    });

    $('#fbToggle').click(function(){
        $('.bbcode').hide();
        if ($('.feedback').is(':visible')) {
            $('.feedback').hide();
        } else {
            $('.feedback').show();
        }
        return false;
    });
    
    $('#fb_send').click(function(){
        $.ajax({
            url: '/feedback.php',
            data: $('#fb_form').serialize(),
            beforeSend: function() { 
                $('.feedback').html(loading);
            },
            success: function(msg) { 
                $('.feedback').html(msg);
            }
        });
        return false;        
    });
    
});

function playClick() {
    _gaq.push(['_trackEvent', 'PlayerVideo',window.location.href]);
    $(document).click();
}
