// Initialize jQuery
function initialize()
{
	// Run Lightbox
	$(".lightbox").lightbox();
	$(".lightbox").children("img").addClass("border");
	/*
	$(".lightbox").each(function(){
		$(this).hover(function(){
			$(this).append("<span></span>").css({
				display: "block",
				position: "relative",
				top: "0",
				left: "0",
				width: "140px",
				height: "100%",
				backgroundImage: "url(graphics/thumb.png)",
				backgroundRepeat: "no-repeat",
				backgroundPositionX: "center",
				backgroundPositionY: "center",
				zIndex: "50"
			});
		});
	});
	*/
	//$(".lightbox").dropShadow();

	// RTE
	$("a.rte").each(function(){
		var theID   = $(this).attr("rel");
		var theIDC  = '#'+theID;
		var theTrig = $(this).attr("id");
		$("body").append('<div id="chrome-'+theID+'" class="jqmWindow"><a class="jqmClose" href="#" title="Close"><img src="graphics/close.png" alt="Close" /></a><div id="'+theID+'" class="jqmContent border"><form><textarea name="description" id="id_description" class="rte-zone"></textarea></form></div></div>');
		$("#chrome-"+theID).jqm({
			trigger  : 'a#'+theTrig,
			onShow   : function(hash){hash.w.fadeIn('1000');},
			onHide   : function(hash){hash.w.fadeOut('2000',function(){ hash.o.remove();});}
		});
	});
	$('.rte-zone').rte();

	// Run jqModal
	$("a.modal").each(function(){
		var theURL  = $(this).attr("href");
		var theID   = $(this).attr("rel");
		var theIDC  = '#'+theID;
		var theTrig = $(this).attr("id");
		$("body").append('<div id="chrome-'+theID+'" class="jqmWindow"><a class="jqmClose" href="#" title="Close"><img src="graphics/close.png" alt="Close" /></a><div id="'+theID+'" class="jqmContent border">&nbsp;</div></div>');
		$("#chrome-"+theID).jqm({
			ajax     : theURL, 
			trigger  : 'a#'+theTrig,
			target   : theIDC,
			ajaxText : '<div class="center"><img src="graphics/loading.gif" alt="Loading..." /></div>',
			onShow   : function(hash){
				hash.w.fadeIn('1000');
			},
			onHide   : function(hash){
				hash.w.fadeOut('2000',function(){ hash.o.remove();});},
			onLoad   : function(hash){
				$(theIDC).children("form").each(function(){
					$(this).ajaxForm({target: theIDC});
				});
			}
		});
	});

	// Format Spoiler/Hide tags
	$(".spoiler").each(function() {
		$(this).hide();
		var getID = '#'+$(this).attr("id");
		var title = $(this).attr("title");
		if(!title)
		{
			title = '* Spoiler Alert! *';
		}
		$('<a class="reveal" rel="'+getID+'" title="'+title+'">'+title+'</a>').insertBefore(this);
	});
	$("a.reveal").each(function() {
		$(this).click(function(theID) {
			theID = $(this).attr("rel");
			if($(theID).is(":hidden"))
			{
				$(theID+":hidden").fadeIn("slow");
			}
			else
			{
				$(theID+":visible").fadeOut("def");
			}
		});
	});

	// Format youtube
	$(".youtube").hide();
	$("a.showYT").each(function() {
		var theID = '#'+$(this).attr("rel");
		$(this).click(function() {
			if($(theID).is(":hidden"))
			{
				$(theID+":hidden").slideDown("slow");
			}
			else
			{
				$(theID+":visible").slideUp("normal");
			}
		});
	});

	// Format "Show All" link
	$(".hidetext").each(function(getID,title) {
		$(this).hide();
		getID = '#'+$(this).attr("id");
		title = ' ~ Show All';
		$('<a class="showall" rel="'+getID+'" title="'+title+'">'+title+'</a>').insertBefore(this);
	});
	$("a.showall").each(function() {
		$(this).click(function(theID) {
			theID = $(this).attr("rel");
			$(theID+":hidden").fadeIn("slow");
			$(this).fadeOut("fast");
		});
	});

	// Open External Links in Seperate Page
	$("a[rel=external]").each(function() {
		$(this).attr('target','_blank');
	}); 
	
	$('input[type=submit]').css({cursor:"pointer"});
	$('input[type=reset]').css({cursor:"pointer"});
	$('input[type=button]').css({cursor:"pointer"});
	$('select').css({cursor:"pointer"});
}

// Small Window
function openWindow(theURL,winName,features) { 
	window.open(theURL,winName,features);
}

// Check All Boxes
function checkallboxes(){
   var oAllCheckBoxes, x;
	oAllCheckBoxes = document.getElementsByTagName('input');
	for( x = 0; x < oAllCheckBoxes.length; x++){
		if(oAllCheckBoxes.item(x).type == 'checkbox'){
		oAllCheckBoxes.item(x).checked = true;
		}
	}
}

// Uncheck All Boxes
function uncheckallboxes(){
   var oAllCheckBoxes, x; 
	oAllCheckBoxes = document.getElementsByTagName('input');
	for( x = 0; x < oAllCheckBoxes.length; x++){
		if(oAllCheckBoxes.item(x).type == 'checkbox'){
		oAllCheckBoxes.item(x).checked = false;
		}
	}
}	

function toggleFatty( isclosed )
{
	var divfatty = document.getElementById("full_find");
	var openfatty = document.getElementById("open_full");
	var closefatty = document.getElementById("close_full");
	var lessbutt = document.getElementById("less_button");
	
	if ( ! isclosed ) {
		divfatty.style.display = "";
		openfatty.style.display = "none";
		closefatty.style.display = "";
		lessbutt.style.display = "none";
	} else {
		divfatty.style.display = "none";
		openfatty.style.display = "";
		closefatty.style.display = "none";
		lessbutt.style.display = "";
	}
}