var text_auction_ended = "Ended";
var text_login_email = "Email:";
var text_login_password = "Password:";
var text_interval_min = "Minute";
var text_interval_mins = "Minutes";
var text_interval_sec = "Second";
var text_interval_secs = "Seconds";
var text_auction_checking = "Checking";
var text_voice_statuses = [];
text_voice_statuses[1] = "Please log in";
text_voice_statuses[2] = "Auction hasn't started yet";
text_voice_statuses[3] = "Auction has ended";
text_voice_statuses[4] = "Out of credits";
text_voice_statuses[5] = "User account not active";
text_voice_statuses[6] = "Your bid has been accepted";
text_voice_statuses[7] = "Auction not found";
text_voice_statuses[8] = "Monthly limit reached";
text_voice_statuses[9] = "You can not over bid yourself";
$(document).ready(function() {
	dom_loaded()
});
function refresh_autobid(A) {
	$.post("user.php?request", {
		action : "autobidbox_changes",
		auction_id : A
	}, function(B) {
		if (B.status == "continue") {
			$("#autobidbox_form_made").text(B.bids);
			if (parseInt(B.bids) >= 1) {
				if (parseInt(B.bids) == parseInt(B.max_bids)) {
					$("#autobid_button").removeAttr("disabled")
				} else {
					$("#autobid_button").attr("disabled", "disabled")
				}
			}
		}
	}, "json");
	if ($("#autobidbox_form_op").val() == "2") {
		setTimeout("refresh_autobid(" + A + ")", 1000)
	}
}
function refresh_items(A) {
	A++;
	if (A == 10) {
		A = 0
	}
	setTimeout("refresh_items(" + A + ")", 1000);
	get_items()
}
function buy(B) {
	var A = "id=" + B;
	$.ajax( {
		async : true,
		type : "GET",
		url : "set.php",
		processData : false,
		data : A,
		success : function(C) {
			var D = parseInt($("s", C).text());
			if (D == 6) {
				$("#userCredit").text($("c", C).text())
			}
			show_popup(text_voice_statuses[D])
		}
	})
}
function show_popup(D) {
	var B = $("#popup");
	var C = $("#popup #msg").html(D);
	B.css( {
		display : "block",
		opacity : 0
	}).animate( {
		opacity : 1
	}, 500, "swing");
	$("#closetimer").text("3");
	var A = function() {
		B.stopTime("closetimer");
		B.css( {
			display : "none"
		})
	};
	B.stopTime("closetimer");
	B.click(A).everyTime(1000, "closetimer", function(E) {
		var F = parseInt($("#closetimer").text());
		$("#closetimer").text(F - 1);
		if (F == 1) {
			A()
		}
	})
}
function get_items() {
	var A = "type=" + $("#type").text();
	$
			.ajax( {
				async : true,
				type : "GET",
				url : "get.php",
				processData : false,
				data : A,
				success : function(B) {
					var C = parseFloat($("s", B).text());
					C = 1000 - (1000 * C);
					if ((nc = $("t", B).text()) != "") {
						setTimeout('clock_is_ticking("' + nc + '")', C)
					}
					$("a", B)
							.each(
									function() {
										var G = $("i", this).text();
										var F = $("l", this).text();
										var H = $("l2", this).text();
										var O = $("p", this).text();
										var I = $("e", this).text();
										var M = $("w", this).text();
										var K = $("u", this).text();
										var E = $("n", this).text();
										var N = $("o", this).text();
										if (N) {
											N = N.split(";").join("<br />");
											N = N
													.split("*")
													.join(
															'&nbsp;<img src="images/site/icon_autobid.gif" alt="AutoBid" />');
											$("#auc_last10_" + G).html(N)
										}
										var L = $("#auc_status_" + G).text();
										if (K == 2) {
											$("#auc_time_" + G).text(H);
											var J = ($("#auc_price_" + G)
													.text() != O ? true : false);
											if (J) {
												$("#auc_price_" + G).text(O);
												$("#auc_winner_" + G).text(M);
												$("#auc_price_" + G).css( {
													backgroundColor : "#e2001a"
												}).animate( {
													backgroundColor : "#ffffff"
												}, 500)
											}
											var D = parse_sec2time(I);
											if ($("#auc_interval_" + G).text() != D) {
												$("#auc_interval_" + G).text(D);
												$("#auc_interval_" + G).css( {
													backgroundColor : "#e2001a"
												}).animate( {
													backgroundColor : "#ffffff"
												}, 500)
											}
										} else if (K == 3) {
											
											$("#auc_time_" + G)
											.css(
													{
														color : "#373730"
													})
											.text(
													text_auction_checking);
											$("#auc_time_" + G).animate( {
												color : "#373730"
										}, 200);
											$("#auc_time_" + G).animate( {
												color : "#673790"
										}, 200);
											$("#auc_status_" + G).text(
											"0")
										} else {
											if (K == 1) {
												$("#auc_button_" + G)
												.attr(
														{
															src : "images/site/sold.jpg"
														});

												if (L == "0") {
													$("#auc_time_" + G)
															.css(
																	{
																		color : "#373730"
																	})
															.text(
																	text_auction_checking);
													$("#auc_button_" + G)
													.attr(
															{
																src : "images/site/bid.jpg"
															});
													$("#auc_status_" + G).text(
															"0.5");
												} else {
													if (L == "0.5") {
														$("#auc_time_" + G)
																.css(
																		{
																			color : "#43b9cc"
																		})
																.text(
																		text_auction_ended);
														$("#auc_status_" + G)
																.text("1");
														$("#auc_button_" + G)
																.attr(
																		{
																			src : "images/site/bid.jpg"
																		})
													}
												}
											} else {
												

												
												if (L != "0") {
													$("#auc_status_" + G).text(
															"0")
												}
												$("#auc_time_" + G).text(
														parse_sec2time(F));
												F = parseInt(F);
												if (F == 30) {
													$("#auc_time_" + G).css( {
														color : "#ff7900"
													}).animate( {
														color : "#eb6a2a"
													}, 500)
												} else {
													if (F == 20) {
														$("#auc_time_" + G)
																.css(
																		{
																			color : "#eb6a2a"
																		})
																.animate(
																		{
																			color : "#eb532a"
																		}, 500)
													} else {
														if (F == 10) {
															$("#auc_time_" + G)
																	.css(
																			{
																				color : "#eb532a"
																			})
																	.animate(
																			{
																				color : "#eb3c2a"
																			},
																			500)
														} else {
															if (F == 5) {
																$(
																		"#auc_time_"
																				+ G)
																		.css(
																				{
																					color : "#eb3c2a"
																				})
																		.animate(
																				{
																					color : "#e2001a"
																				},
																				500)
															}
														}
													}
												}
												var J = ($("#auc_price_" + G)
														.text() != O ? true
														: false);
												if (J) {
													$("#auc_time_" + G).css( {
														color : "#eb932a"
													});
													$("#auc_price_" + G)
															.text(O);
													$("#auc_winner_" + G).text(
															M);
													$("#auc_price_" + G)
															.css(
																	{
																		backgroundColor : "#e2001a"
																	})
															.animate(
																	{
																		backgroundColor : "#ffffff"
																	}, 500)
												}
												var D = parse_sec2time(I);
												if ($("#auc_interval_" + G)
														.text() != D) {
													$("#auc_interval_" + G)
															.text(D);
													$("#auc_interval_" + G)
															.css(
																	{
																		backgroundColor : "#e2001a"
																	})
															.animate(
																	{
																		backgroundColor : "#ffffff"
																	}, 500)
												}
												if (typeof (flash_sound_icon) == "function") {
													if (parseInt($("#type")
															.text()) == G) {
														if (F <= 5) {
															flash_make_sound(
																	"flash_alert",
																	F)
														}
													}
												}
											}
										}
									})
				}
			})
}
function parse_sec2time(D) {
	var B = "";
	var A = (D >= 86400 ? Math.floor(D / 86400) : 0);
	if (A > 0) {
		D -= (A * 86400)
	}
	var E = (D >= 3600 ? Math.floor(D / 3600) : 0);
	if (E > 0) {
		D -= (E * 3600)
	}
	var C = (D >= 60 ? Math.floor(D / 60) : 0);
	if (C > 0) {
		D -= (C * 60)
	}
	if (A > 0) {
		B += A + "D, "
	}
	if (A > 0 || E > 0) {
		B += str_pad(E + "", 2, "0", "STR_PAD_LEFT") + ":"
	}
	B += str_pad(C + "", 2, "0", "STR_PAD_LEFT") + ":";
	B += str_pad(D + "", 2, "0", "STR_PAD_LEFT");
	return B
}
function str_pad(C, G, F, D) {
	var E = "", A;
	var B = function(I, H) {
		var J = "";
		while (J.length < H) {
			J += I
		}
		J = J.substr(0, H);
		return J
	};
	if (D != "STR_PAD_LEFT" && D != "STR_PAD_RIGHT" && D != "STR_PAD_BOTH") {
		D = "STR_PAD_RIGHT"
	}
	if ((A = G - C.length) > 0) {
		if (D == "STR_PAD_LEFT") {
			C = B(F, A) + C
		} else {
			if (D == "STR_PAD_RIGHT") {
				C = C + B(F, A)
			} else {
				if (D == "STR_PAD_BOTH") {
					E = B(F, Math.ceil(A / 2));
					C = E + C + E;
					C = C.substr(0, G)
				}
			}
		}
	}
	return C
}
function clock_is_ticking(A) {
	$("#time").text(A)
}
if (!$.browser.msie || $.browser.version != "6.0") {
	function changeInputType(B, D, E, A, F) {
		if (!B || !B.parentNode || (D.length < 4) || !document.getElementById
				|| !document.createElement) {
			return
		}
		var C = document.createElement("input");
		C.type = D;
		if (B.name) {
			C.name = B.name
		}
		if (B.id) {
			C.id = B.id
		}
		if (B.className) {
			C.className = B.className
		}
		if (B.size) {
			C.size = B.size
		}
		if (B.tabIndex) {
			C.tabIndex = B.tabIndex
		}
		if (B.accessKey) {
			C.accessKey = B.accessKey
		}
		C.onfocus = function() {
			return function() {
				if (this.hasFocus) {
					return
				}
				var G = changeInputType(this, "password", E, (this.value
						.toLowerCase() == E.toLowerCase()) ? true : false);
				if (G) {
					G.hasFocus = true
				}
			}
		}();
		C.onblur = function() {
			return function() {
				if (this.hasFocus) {
					if (this.value == ""
							|| (this.value.toLowerCase() == E.toLowerCase())) {
						changeInputType(this, "text", E, false, true)
					}
				}
			}
		}();
		C.hasFocus = false;
		B.parentNode.replaceChild(C, B);
		if (!A) {
			C.value = E
		}
		if (!F || typeof (F) == "undefined") {
			window.tempElm = C;
			setTimeout("tempElm.hasFocus=true;tempElm.focus();", 1)
		}
		return C
	}
}
function togleintervaldiv(C, A, B) {
	if ($("#dynint_" + C).data("anim") == 1) {
		if (A == "close" && B == true) {
			setTimeout("togleintervaldiv(" + C + ", 'close', true)", 5000)
		}
		return false
	}
	if (A == "close") {
		if ($("#dynint_" + C).data("open") == 0) {
			return false
		}
		if ($("#dynint_" + C).data("hove") == 1) {
			if (B == true) {
				setTimeout("togleintervaldiv(" + C + ", 'close', true)", 5000)
			}
			return false
		}
	}
	$("#dynint_" + C).data("anim", 1);
	if (A == "open") {
		setTimeout(
				'$("#dynint_' + C + '_tbl p").show("clip", { direction: "vertical" }, 350)',
				350);
		$("#dynint_" + C + "_tbl").show("clip", {
			direction : "vertical"
		}, 350);
		setTimeout('$("#dynint_' + C + '").data("open", 1)', 350)
	} else {
		setTimeout(
				'$("#dynint_' + C + '_tbl").hide("clip", { direction: "vertical" }, 350)',
				350);
		$("#dynint_" + C + "_tbl p").hide("clip", {
			direction : "vertical"
		}, 350);
		setTimeout('$("#dynint_' + C + '").data("open", 0)', 350)
	}
	setTimeout('$("#dynint_' + C + '").data("anim", 0)', 700);
	if (A == "open") {
		setTimeout("togleintervaldiv(" + C + ", 'close', true)", 5000)
	}
}
var flash_get_movie = function(A) {
	return ($.browser.msie ? document.getElementById(A) : movie = document[A])
};
var flash_make_sound = function(A, B) {
	flash_get_movie(A).makesound(B)
};
var flash_sound_icon = function(B, A) {
	var C = "";
	if ($.browser.msie) {
		C = '<object id="' + A + '" data="flash/alert.swf" type="application/x-shockwave-flash" width="14" height="14">';
		C += ' <param name="movie" value="flash/alert.swf"/>';
		C += ' <param name="AllowScriptAccess" value="always"/>';
		C += ' <param name="quality" value="high"/>';
		C += ' <param name="wmode" value="transparent"/>';
		C += " <!-- -->";
		C += " </object>"
	} else {
		C = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		C += ' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" width="14" height="14"';
		C += ' id="' + A + '"';
		C += ' align="middle">';
		C += '<param name="movie" value="flash/alert.swf" />';
		C += '<param name="quality" value="high" />';
		C += '<param name="FlashVars" value="id=' + A + '"/>';
		C += '<param name="allowScriptAccess" value="always"/>';
		C += '<embed src="flash/alert.swf" FlashVars="id=' + A + '"';
		C += ' allowScriptAccess="always" quality="high" bgcolor="#ffffff" width="14" height="14"';
		C += ' name="' + A + '" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		C += "</object>"
	}
	$("#" + B).html(C)
};
$(document).ready(
		function() {
			$("#win_pic").click(
					function() {
						$("#win_pic,#public_name,#public_comment").fadeOut(
								"fast");
						$("#win_pic").load(
								'winners.php?id=1&uid=' + Math.random())
								.fadeIn("slow");
						$("#public_name").load(
								'winners.php?id=2&uid=' + Math.random())
								.fadeIn("slow");
						$("#public_comment").load(
								'winners.php?id=3&uid=' + Math.random())
								.fadeIn("slow");
					});
		});