/****** Global JS ******/

/* sets up sliding right rail modules */
function initSlideRail(){
	$('.moduleHeader').click(function(){
		var module = $(this).parent('.module'),
			isopen = $(module).hasClass('open'),
			_body = $(this).next('.moduleBody'),
			btn_collapse = $(this).children(".icon_collapse");
		if(isopen){			
			$(module).removeClass('open').addClass('closed');
			$(_body).slideUp();		
			$(btn_collapse).css("background-position","left bottom");					
		}else{
			$(module).removeClass('closed').addClass('open');
			$(_body).slideDown();			
			$(btn_collapse).css("background-position","top left");	
		}
	});
}

/* sets up bottomAdsSignup click event */
function initBottomAdsSignup() {
	$("#tsc_ads_signup #signup_wrapper form#signup input#signup_email").blur(function(){
		if($(this).val() == "") {
			$(this).val("Enter your email address").css("color", "#8b8b8b");
		}	
	 }).click(function(){
		if($(this).val() == "Enter your email address") {
			$(this).val("").css("color", "#000000");
		}	
	 });
}

/* Set-up code when DOM parsing completed*/
$(document).ready(function(){
	/* prevent exec script in search box */
	$("form[action='/search/'] a")
	.attr("href","#")
	.click(function(e){
		e.preventDefault();
		$(this).parents("form").submit();    
	});

	$("form[action='/search/']").submit(function(){
		$input = $("input[name=q]",this);
		//get unsafe search string 
		var s = $input.val();
		//replace
		s = s.replace(/</g,'&lt;').replace(/>/g,'&gt;');
		//set safe search string 
		$input.val(s);
	});

	/* Text Size */
	var originalFontSize = getFontSize();
	$(".increaseFont").click(function(){
			var fontSize = getFontSize();
			var newFontSize = fontSize + 1;
			setFontSize(newFontSize);
			return false;
	});
	$(".decreaseFont").click(function(){
			var fontSize = getFontSize();
			var newFontSize = fontSize - 1;
			setFontSize(newFontSize);
			return false;
	});
	
	initSlideRail();
	initBottomAdsSignup();
	
	/*** button hover in registration***/
	if($("#register_content").attr('id') != undefined)
	{
		$("#register_content").find("button").mouseover(function() {
			$(this).css('background-position', 'left bottom');
		}).mouseout(function(){
			$(this).css('background-position', 'left top');
		});
	}
});

function getFontSize() {
        var currentSize = $("#body_text").css("font-size");
        var currentSizeNumber = parseFloat(currentSize, 13);
        if(currentSizeNumber > 20) {
                currentSizeNumber = 20;
        }
        return currentSizeNumber;
}

function setFontSize(size) {
        $("#body_text").css("font-size", size);
} 

/* Image rollovers --Give any IMAGE a Class of "over" and use -over at end of filename for hover-- */
$(function(){
	$('img.over').mouseover(function(){
		if(!this.src.match('-over')){
			var file = this.src.substr(0,this.src.length-4),
				ext = this.src.substr(this.src.length-4,this.src.length);
			file += '-over';
			this.src = file + ext;
		}
	})
	.mouseout(function(){
		if(this.src.match('-over')){
			var source = this.src.replace('-over','');
			this.src = source;
		}
	});
});


/* Most Popular Tout */
function mptabs(swapmp) {
	if (swapmp == 'mod_tab_viewed') {
	$("#mod_tab_viewed").show();
	$("#mod_tab_searched").hide();
	$("#tab_viewed").removeClass("inactive").addClass("active");
	$("#tab_searched").removeClass("active").addClass("inactive");
	
	}
	
	else if (swapmp == 'mod_tab_searched') {
	$("#mod_tab_viewed").hide();
	$("#mod_tab_searched").show();
	$("#tab_searched").removeClass("inactive").addClass("active");
	$("#tab_viewed").removeClass("active").addClass("inactive");
	
	}
}



/* Homepage Forum Topics Module*/
function forum_tabs(swapmp) {
	if (swapmp == 'mp_tab') {
	$("#mp_tab").show();
	$("#recent_tab").hide();
	$("#btn_tab_mp").removeClass("inactive").addClass("active");
	$("#btn_tab_recent").removeClass("active").addClass("inactive");
	
	}
	
	else if (swapmp == 'recent_tab') {
	$("#mp_tab").hide();
	$("#recent_tab").show();
	$("#btn_tab_recent").removeClass("inactive").addClass("active");
	$("#btn_tab_mp").removeClass("active").addClass("inactive");
	
	}
}
