$(document).ready(function() {
	$("input[@type='file']").livequery("change", function (e) {
		// Check whether there's a value for the input - if not, we don't want to submit the form.  jQuery in Google Chrome will otherwise
		// submit the form.
		if ($(this).val() != "" && $(this).attr("name") != "audioFile") {
			$("form").hide();
			$("form").submit();
			$("#uploadPane").html("<p><img src=\"/images/indicator.gif\" width=\"16\" height=\"16\" alt=\"Adding image\" /> Adding image...</p>");
		}
	});
    
    $("label.cabinet").mouseover(function(e) {
        $(this).css("background", "url(/images/buttons/Button_UploadImage_On.GIF)");    
    });
    $("label.cabinet").mouseout(function(e) {
        $(this).css("background", "url(/images/buttons/Button_UploadImage.gif)");    
    });
    
	
	function rolloverLabel() { 
	
//		alert(this);
		
		$(this).css("background", "url(/images/buttons/Button_UploadImage_On.GIF)");
		
	} // end rollover

	function rolloutLabel() { 

		$(this).css("background", "url(/images/buttons/Button_UploadImage.gif)");

	}

	// $("label.cabinet").hover(rolloverLabel, rolloutLabel);
	
});

/* Start Alert - It's here because jQuery needs to call the parent window to show / hide the alert.  We do this via top.document */
function dialogBox_startCountdown(){ 
	dur = dur - step; 
    setTimeout("dialogBox_startCountdown()", 1000);
    if (dur == 0) {
    	// Only toggle if still showing i.e. user has not clicked OK to hide.
		HideOverlay();
    } 
}
function checkText(txt) {
	if (!txt.match(/^(<p>)/)) {
		var newTxt = "<p>" + txt + "</p>";
	} else {
		var newTxt = txt;	
	}
	return newTxt;
} // end function
function softAlert(txt, yesFunct) {
	$("#popupText", top.document).html(checkText(txt));
	$("#confirm_yes_button", top.document).css("display","none");
  	$("#confirm_no_button", top.document).css("display","none");
	$("#confirm_okay_button", top.document).css("display","block");
	$("#confirm_okay_button", top.document).click(yesFunct);
	$("#confirm_okay_button", top.document).focus();
	$("#popupButtons", top.document).css("width", "30px");
	PositionAndShowOverlay();
}
function softConfirm(txt, yesFunct, noFunct) {
    $("#popupText", top.document).html(checkText(txt));
	$("#confirm_yes_button", top.document).css("display","block");
    $("#confirm_no_button", top.document).css("display","block");
    $("#confirm_okay_button", top.document).css("display","none");
    $("#confirm_yes_button", top.document).click(yesFunct);
    $("#confirm_no_button", top.document).click(noFunct);
    $("#confirm_no_button", top.document).focus();
	$("#popupButtons", top.document).css("width", "90px");
    PositionAndShowOverlay();
}
function softMessage(txt) {
    $("#popupText", top.document).html(checkText(txt));
    $("#confirm_yes_button", top.document).css("display","none");
    $("#confirm_no_button", top.document).css("display","none");
    $("#confirm_okay_button", top.document).css("display","none");
    PositionAndShowOverlay();
}
function alertOff() {
	$('#overlay', top.document).css("display","none");
	$('#popup', top.document).css("display","none");
	
	/* Unbind button clicks to ensure blocking mode for our dialog box, otherwise if "no" is clicked on softConfirm, and then "yes" is clicked on a seperate 
	softConfirm, two events would fire off asynchronously, which we don't want */
	$("#confirm_yes_button", top.document).unbind('click');
    $("#confirm_no_button", top.document).unbind('click');
	$("#confirm_okay_button", top.document).unbind('click');
}
function PositionAndShowOverlay() {	
	// $('#overlay', top.document).height($('#background', top.document).height() + $('#footer', top.document).height() + 30);
	
	// Show Overlay and Popup
	$('#overlay', top.document).css("display","block");	
	$('#popup', top.document).css("display","block");
	
	// Resize the height of the pop and its text	
	$('#popupText', top.document).height($('#popupText > p', top.document).height() + 10);
	$('#popup', top.document).height($('#popupText', top.document).height() + $('#popupButtons', top.document).height() + 30);
}
function HideOverlay() {
	$('#overlay', top.document).css("display","none");
	$('#popup', top.document).css("display","none");
}
/* End Alert */

// Update Image Selector
// The new image will appear at the end of the paginator list
function RefreshImageSelector(pageNo, refreshArea, callClass, callClassFunction, callClassFunctionArguments) {
	$.post(
		"ajax.Pagination.php",
		{
			pageNo: pageNo,
			callClass: callClass,
			callClassFunction: callClassFunction,
			callClassFunctionArguments: callClassFunctionArguments
		},
		function (data) {
			// Refresh area of parent document - this is being called in an iframe
			$("#"+refreshArea, top.document).html(data);
		}
	);
}