function Add_Avatars() {
    $("div.avatar").each(function() {
        // get the id and rel attribute values
        var Div_ID = $(this).attr("id");
        var Rel = $(this).attr("rel").split('-');
        var Values = Rel[0];
        var Width = Rel[1];
        var Height = Rel[2];
        
        // create SWF
        if (swfobject.hasFlashPlayerVersion('9')) {
            var att = { data: '/_Flash/Avatar.swf?v=' + Values, width: Width, height: Height };
            var par = { menu: "false", wmode: "transparent", allowScriptAccess: "always" };
            var id = Div_ID;
            swfobject.createSWF(att, par, id);
        }
    });
}

function Load_Avatar_Updater() {
    $("#avatarupdater").each(function() {
        // get the rel and pass it to the Flash
        var Values = $(this).attr("rel");
        
        // create SWF
        if (swfobject.hasFlashPlayerVersion('9')) {
            var att = { data: '/_Flash/Avatar_Maker.swf?v=' + Values, width: '630', height: '420' };
            var par = { menu: "false", wmode: "transparent", allowScriptAccess: "always" };
            var id = "avatarupdaterflash";
            swfobject.createSWF(att, par, id);
        }
    });

    $("a.avatarupdate").click(function() {
        Avatar_Open();
        return false;
    });
}

function Avatar_Close() {
	// hide it
	$("#avatarupdater").removeClass('visible');

	// remove the flash
	//swfobject.removeSWF("avatarupdaterflash");
	
	// re-add the flash
	$("#avatarupdater").each(function() {
		// get the rel and pass it to the Flash
		var Values = $(this).attr("rel");

		// create SWF
		if (swfobject.hasFlashPlayerVersion('9')) {
			var att = { data: '/_Flash/Avatar_Maker.swf?v=' + Values, width: '630', height: '420' };
			var par = { menu: "false", wmode: "transparent", allowScriptAccess: "always" };
			var id = "avatarupdaterflash";
			swfobject.createSWF(att, par, id);
		}
	});
}
function Avatar_Open() {
    $("#avatarupdater").addClass('visible');
}
function Avatar_Saved() {
    Avatar_Close();
    window.location.href = window.location.href;
}

function Add_Alternating_Elements() {
	$(".messageboardcategories li:even").addClass("even");
	$(".postsummary tr:even").addClass("even");
}

function Add_Delete_Confirmations() {
	$(".deleteconfirm").click(function() {
		return confirm("Are you sure you wish to delete this item?\nThis action cannot be undone.");
	});
}

function Add_User_Link_Popups() {
	$(".userlink").hover(
		function() {
			// get the next UL with a class of "userlinks" and show it
			$(this).children("div.userlinks").show();

		},
		function() {
			// get the next UL with a class of "userlinks" and hide it
			$(this).children("div.userlinks").hide();
		}
	);
}


/**
 * Initialize the datepicker elements
 */
function InitDatePicker() {
	$('.date-pick').datePicker().trigger('change');
	$('.date-pick-past').datePicker({ startDate: '2000-01-01', endDate: (new Date().asString()) }).trigger('change');


	//	Setup default for date picker
	var str = jQuery.trim($('.date-pick').val());
	if (str.length < 6) {
		$('.date-pick').val(new Date().asString());
	}
	
	//	Setup default for date picker past
	str = jQuery.trim($('.date-pick-past').val());
	if (str.length < 6) {
		$('.date-pick-past').val(new Date().asString());
	}
}


//	Setup the datepicker
Date.firstDayOfWeek = 7;
Date.format = 'yyyy-mm-dd';

$(document).ready(function() {
	Add_Avatars();
	InitDatePicker();
	//Add_Alternating_Elements();
	Load_Avatar_Updater();
	Add_Delete_Confirmations();
	Add_User_Link_Popups();
});

/* Son of Suckerfish Javascript: http://htmldog.com/articles/suckerfish/dropdowns/ */
/* Adapted for jQuery by MARSWorks */
/* This will only be loaded by IE (which, conveniently, is the only browser that needs it) */
sfHover = function() {
    $(".usernav li").hover(function() {
        $(this).addClass("sfhover");
    }, function() {
        $(this).removeClass("sfhover");
    });
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

