$(document).ready(function(){
	
	$(".tabButton").click(function(){
		var name = $(this).html();
		$(".tabButton").removeClass("tabButtonSel");
		if(tab){
			$("#tabButton" + tab).addClass("tabButtonNormal");
			$("#tab" + tab).fadeOut(200, function(){
				$("#tab" + name).fadeIn(200);
			});
		}else{ $("#tab" + name).fadeIn(200); }
		$(this).removeClass("tabButtonNormal");
		$(this).addClass("tabButtonSel");
		tab = name;
	});
	
	
	$(".bFooter").click(function(){
		clearInterval(bTimeout);
		showFeatContent($(this).html());
		bTimeoutFunction();
	});
	
	$(".sMedia").mouseover(function(){
		var temp = $(this).attr("id");
		var html = $("#info" + temp).html();
		$("#sMediaText").html(html);
	});
	
	bTimeoutFunction();
	
	

	
	/* forum stuff 
	$("#postEditorButtons div").click(function(){
		var a = $(this).attr("button");

		var temp = $("#pText").text();
		switch(a){
			case "u":	temp += "[u][/u]";	
		}

		$("#pText").text(temp);
	});
	*/
	
	
});

function showFeatContent(num){
	$(".bFooter").removeClass("bFooterSel");
	$("#bFooter" + num).addClass("bFooterSel");
	$("#featInfo" + bCur).fadeOut(150, function(){ $("#featInfo" + num).fadeIn(150); });
	bCur = num;
}

function bTimeoutFunction(){
	bTimeout = setInterval(function(){
		showFeatContent(bNum);
		bNum = (bNum == 5) ? 1 : bNum += 1;
	}, 7000);
}

function postLoad(hash){ $.get("http://psgeeks.org/forums/postLoad.php", {h: hash}); }



function addtag(tag, srcLink){
	var txt = document.getElementById('pText');
	if(document.selection){
		txt.focus();
		sel = document.selection.createRange();
		if(srcLink){ sel.text = '[' + tag + '=' + srcLink + ']' + sel.text + '[/' + tag + ']'; }else{
			sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
		}
	}else if(txt.selectionStart || txt.selectionStart == '0'){
		if(srcLink){
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"=" + srcLink + "]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		}else{
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		}
	}else{
		txt.value = '[' + tag + '][/' + tag + ']';
	}
	return;
}

function showModalWindow(c, f, height, type){
	var status = $("#modalWindow").attr("status");
	if(status == "shown"){
		$("#modalWindowText").html(c);
		$("#modalWindow").animate({
			height: "0px",
			opacity: "0.0"
		}, 100);
		$("#modalWindow").attr("status", "hidden");
		$("#modalWindowOK").attr("onClick", "");
	}else{
		if(f) $("#modalWindowOK").attr("onClick", f);
		$("#modalWindowText").html(c);
		$("#modalWindow").animate({
			height: height,
			opacity: "1"
		}, 100);
		$("#modalWindow").attr("status", "shown");
		if(type == "link") $("#tagTextLink").focus();
	}
}

function closeModalWindow(){
	$("#modalWindow").fadeOut(100, function(){
		$("#modalWindow").height(0);
		$("#modalWindow").attr("status", "hidden");
		$("#modalWindowText").html("");
	});
}


function addLink(){
	showModalWindow('<h3>Create a Text Link:</h3><br /><p>Enter your link into the field below.</p><p><input type="text" style="width:276px;" id="tagTextLink" /></p>', 'editorAddLink()', '128px', 'link');
}

function addColor(){
	showModalWindow('<h3>Set a font color:</h3><br /><p>Pick a color from the choices below.</p><p><span onClick="eAC(\'black\')" class="floatHover" style="background-color:black;"></span><span onClick="eAC(\'white\')" class="floatHover" style="background-color:white;"></span><span onClick="eAC(\'green\')" class="floatHover" style="background-color:green;"></span><span onClick="eAC(\'red\')" class="floatHover" style="background-color:red;"></span><span onClick="eAC(\'pink\')" class="floatHover" style="background-color:pink;"></span><span onClick="eAC(\'purple\')" class="floatHover" style="background-color:purple;"></span><span onClick="eAC(\'brown\')" class="floatHover" style="background-color:brown;"></span><span onClick="eAC(\'gray\')" class="floatHover" style="background-color:gray;"></span><span onClick="eAC(\'silver\')" class="floatHover" style="background-color:silver;"></span><span onClick="eAC(\'blue\')" class="floatHover" style="background-color:blue;"></span><span onClick="eAC(\'gold\')" class="floatHover" style="background-color:gold;"></span><span onClick="eAC(\'violet\')" class="floatHover" style="background-color:violet;"></span></p><div style="clear:both;">&nbsp;</style>', 'eAC()', '142px', 'link');
}

function eAC(c){
	if(!c){closeModalWindow()}
	addtag("color", c);
	closeModalWindow();
}

function editorAddLink(){
	var link = $("#tagTextLink").val();
	addtag("url", link);
	closeModalWindow();
}

function showPM(h){
		$("#" + h).slideDown("fast");
}