jQuery.noConflict();

jQuery(document).ready(function($) {

// If user has no avatar, replace it with the default one
if ($('#avatar').attr('src') == '') {
	$('#panel').prepend('<img class="no-avatar" src="images/intox/default-avatar.png" />');
	$('#avatar').addClass('no-display');
}

$('.post-avatar img').each(function() {
if ($(this).attr('src') == '') {
	$(this).parent('.post-avatar').append('<img class="no-avatar" src="images/intox/postbit-avatar.png" />');
	$(this).addClass('no-display');
}
});

// Target the forum's id and replace the on/off icon's src attribute to use the new icon
$('#mark_read_113[alt="Forum Contains No New Posts"]').attr('src', 'images/intox/mc-icon-off.png');
$('#mark_read_37[alt="Forum Contains No New Posts"]').attr('src', 'images/intox/tf2-icon-off.png');
$('#mark_read_15[alt="Forum Contains No New Posts"]').attr('src', 'images/intox/css-icon-off.png');
$('#mark_read_114[alt="Forum Contains No New Posts"]').attr('src', 'images/intox/bf3-icon-off.png');
$('#mark_read_107[alt="Forum Contains No New Posts"]').attr('src', 'images/intox/mw3-icon-off.png');

$('#mark_read_113[alt="Forum Contains New Posts"]').attr('src', 'images/intox/mc-icon.png');
$('#mark_read_37[alt="Forum Contains New Posts"]').attr('src', 'images/intox/tf2-icon.png');
$('#mark_read_15[alt="Forum Contains New Posts"]').attr('src', 'images/intox/css-icon.png');
$('#mark_read_114[alt="Forum Contains New Posts"]').attr('src', 'images/intox/bf3-icon.png');
$('#mark_read_107[alt="Forum Contains New Posts"]').attr('src', 'images/intox/mw3-icon.png');

// Hide the PM number if there are no messages
$('.unread.0').hide();

// Makes the dropdowns work!
$('.menu li.dropdown-link').hover(function() {
	$(this).find('.dropdown').stop(true,true).slideDown();
	$(this).find('.menu-arrow').show();
}, function() {
	$(this).find('.dropdown').stop(true,true).slideUp();
	$(this).find('.menu-arrow').hide();
});


// Replaces the default debug info with a newly formatted version
if ($("#debug a").length == 1) {
	$("#debug").hide();
	var debug_link = $("#debug a").attr("href");
	$("#debug a").remove();
	var debug = $("#debug").html().replace('[','').replace(']','');
	$("#debug_link").attr("title", debug).attr("href", debug_link);
} else {
	$("#debug").hide();
	$("#debug_link").hide();
}

// TipTip settings
$('.tip').tipTip({defaultPosition: "top", edgeOffset: 7, maxWidth: "auto"});
$('.tip2').tipTip({defaultPosition: "right", edgeOffset: 10});
$('.author-button').tipTip({defaultPosition: "top", edgeOffset: 5});

// Animate the Return to Top button
$('#return-top').click(function () {
	$('html, body').animate({scrollTop: 0}, 'slow');
	return false;
});

// Adds the header images in an array and grabs them at random, then adds them to #banner's CSS
var header_imgs = ['images/intox/headers/1.png', 'images/intox/headers/2.png', 'images/intox/headers/3.png', 'images/intox/headers/4.png', 'images/intox/headers/5.png', 'images/intox/headers/6.png', 'images/intox/headers/7.png', 'images/intox/headers/8.png', 'images/intox/headers/9.png', 'images/intox/headers/10.png'];
var i= Math.floor(Math.random()*header_imgs.length);
$('#banner').css('background', '#000 url('+header_imgs[i]+') top center no-repeat');

//  Stuff for rounded corners
if ($('#posts td:first').is('.tcat2')) {
$('#posts td:first').removeClass('tcat2');
$('#posts td:first').addClass('tcat');
}

$('#post_ td:first').removeClass('tcat2');
$('#post_ td:first').addClass('tcat');

$('#post_0 td:first').removeClass('tcat2');
$('#post_0 td:first').addClass('tcat');

$('#posts > table:first').addClass('first-table');
$('#posts > table:last').addClass('last-table');

$('#post_').removeClass('tborder2');
$('#post_').addClass('tborder4');

$('#post_0').removeClass('tborder2');
$('#post_0').addClass('tborder4');
// End rounded corners stuff

// Fix the weird square corners bug for fancyCollapses to make the thead all round when collapsed
if(jQuery().fancyCollapses){
        $(".tborder  tbody[id$='_e']").fancyCollapses({easing: "easeInOutQuart", speed: "normal"});
		$(".tborder5  tbody[id$='_e']").fancyCollapses({collapser: ".tborder5 .tcat .expander", easing: "easeInOutQuart", speed: "normal"});
		if ($('.thead > .expcolimage').not('.all-radius')) {
		$('.thead > .expcolimage').click(function () {
			$(this).parent().toggleClass('all-radius');
		});
		} else {
			$('.thead > .expcolimage').click(function () {
				$(this).parent().toggleClass('no-radius');
			});
		}
}

// Stuff to make the sidebar work
$('.hide-servers').hide();
$('#sidebar').css({marginRight: '-20px', width: '0', display: 'none'});

$('.hide-servers').click(function () {
	$('#sidebar').css({marginRight: '-20px'});
	$('#sidebar').animate({width: '0'}, function () {
		$('.show-servers').show();
		$('.hide-servers').hide();
		$('#sidebar').css({display: 'none'});
	});
	$.cookie('sidebar','collapsed', {expires: 365});
	return false;
});

$('.show-servers').click(function () {
	$('#sidebar').css({marginRight: '0', display: 'block'});
	$('#sidebar').animate({width: '180px'}, function () {
		$('.show-servers').hide();
		$('.hide-servers').show();
		$.cookie('sidebar','expanded', {expires: 365});
	});
	return false;
});

if($.cookie('sidebar') == 'expanded') {
        $('.show-servers').hide();
        $('.hide-servers').show();
		$('#sidebar').css({marginRight: '0', width: '180', display: 'block'});
};
// End sidebar stuff

$('.login-button').click(function() {
		$(this).hide();
		$('.login').fadeIn('fast');
	return false;
});

pageWidth = $('.page-width').css('width'),

$('#toggle-width').click(function() {
	if ( $('.page-width').css('width') == pageWidth ) {
		$('.page-width').animate({ width: '90%' });
		$.cookie('SiteWidth', 'fluid');
	} else {
		$('.page-width').animate({ width: pageWidth });
		$.cookie('SiteWidth', 'fixed');
	}
});

 if ( $.cookie('SiteWidth') == 'fluid' ) {
	$('.page-width').css('width', '90%');
 }
 if ( $.cookie('SiteWidth') == 'fixed' ) {
	$('.page-width').css('width', pageWidth);
 }
});
