$(document).ready(
		function() {
			$(".main-nav li .nav-top-item").hover(function() {
				$(this).stop().animate( {
					paddingRight : "25px"
				}, 200);
			}, function() {
				$(this).stop().animate( {
					paddingRight : "15px"
				});
			});

			jQuery('ul.actions li.delete').live('click', function() {
				if (!confirm('Are you sure to delete this record?')) {
					return false;
				} else {
					wb_showUpdate('.content-box-body');
					$.post($(this).attr('href'));
					var kt = $(this).attr('href').split('delete');
					// to prevent the cache from loading the old data since
					// the first request seems to load after the redirect..at
					// least on
					// localhost
					setTimeout("redirect('" + kt[0] + 'admin' + "')", 1250);
				}
				return false;
			});
			jQuery.preLoadImages("/images/test/buybtn.png",
					"/images/test/buybtnh.png");
		});
(function($) {
	var cache = [];
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for ( var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)
function clearCart(url) {
	if (!confirm('Are you sure you want to clear your cart?')) {
		return false;
	} else {
		$.get(url, function() {
			window.location = window.location;
		});
	}
}
function changeUnitPrice(url) {
	wb_showUpdate('.content-box-body');
	redirect(url);
}
function showLoginWrapper() {
	$('#aPlogoContainer').css('position:static');
	$('#aPloginWrap').slideToggle('slow', function() {
		if ($('#aPloginWrap').attr('display') == 'block') {
			$('#aPloginFrm').fadeOut('slow');
		} else {
			$('#aPloginFrm,#aPloginPromoContent').fadeIn('slow');
		}
	});
}
function scrollTo(target) {
	var destination = $(target).offset().top;
	$("html:not(:animated),body:not(:animated)").animate( {
		scrollTop : destination - 20
	}, 500);
	return false;
}
function userproxy(url, itemid) {
	wb_showUpdate('.content-box-body');
	$.post(url, {
		item : itemid
	}, function(response) {
		if (strpos(response, 'Error:') !== false) {
			var kt = response.split('Error:');
			$.jGrowl.defaults.position = 'center';
			$.jGrowl(kt[1], {
				header : 'Error!'
			});
		} else {
			if (strpos(url, 'vpn') !== false) {
				userResponse = "VPN was added to your list!";
			} else {
				userResponse = "Proxy was added to your list!";
			}
			$.jGrowl.defaults.position = 'bottom-right';
			$.jGrowl(userResponse, {
				header : 'Success!'
			});
		}

		$.fn.yiiGridView.update('ip-grid', {
			type : 'POST',
			url : $(this).attr('href'),
			success : function() {
				$.fn.yiiGridView.update('ip-grid');
			}
		});
		wb_hideUpdate('.content-box-body');
	});
}
function add2cart(url, itemid) {
	wb_showUpdate('.content-box-body');
	$.post(url, {
		item : itemid
	}, function(response) {
		if (strpos(response, 'Error:') !== false) {
			var kt = response.split('Error:');
			$.jGrowl.defaults.position = 'center';
			$.jGrowl(kt[1], {
				header : 'Error!'
			});
		} else {
			$.jGrowl.defaults.position = 'bottom-right';
			$.jGrowl("Proxy was added to your shopping cart!", {
				header : 'Success!'
			});
			$('#spctCount').html(response);
		}

		$.fn.yiiGridView.update('ip-grid', {
			type : 'POST',
			url : $(this).attr('href'),
			success : function() {
				$.fn.yiiGridView.update('ip-grid');
			}
		});
		wb_hideUpdate('.content-box-body');
	});
}
function removeFromCart(url, itemid) {
	if (!confirm('Are you sure you want to remove this proxy from your shopping cart?')) {
		return false;
	} else {
		wb_showUpdate('.content-box-body');
		$.jGrowl.defaults.position = 'bottom-right';
		$.jGrowl("Proxy was removed from your shopping cart!", {
			header : 'Success!'
		});
		$.post(url, {
			item : itemid
		}, function(response) {
			window.location = window.location;
		});
	}
}
function removeUserIp(url, itemid) {
	if (!confirm('Are you sure you want to remove this proxy from the selected user?')) {
		return false;
	} else {
		wb_showUpdate('.content-box-body');

		$.get(url, function(response) {
			$.fn.yiiGridView.update('ip-grid', {
				type : 'POST',
				url : $(this).attr('href'),
				success : function() {
					$.fn.yiiGridView.update('ip-grid');
				}
			});
			$.jGrowl.defaults.position = 'bottom-right';
			$.jGrowl("Proxy was removed from the user!", {
				header : 'Success!'
			});
			wb_hideUpdate('.content-box-body');
		});
	}
}
function popup(url, width, height) {
	var popupW = (screen.width / 2) - (width / 2);
	var popupH = (screen.height / 2) - (height / 2);
	return window.open(url, "Window1", "menubar=no,width=" + width + ",height="
			+ height + ",toolbar=no,screenX=" + popupW + ",screenY=" + popupH);
}
function strpos(haystack, needle, offset) {
	var i = (haystack + '').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
}
function redirect(url) {
	window.location = url;// ;
}

function wb_dialog(el, height, width, title, modal) {
	$("#" + el).dialog( {
		bgiframe : true,
		height : height,
		width : width,
		title : title,
		modal : modal
	});
	jQuery("#" + el).bind('dialogclose', function(event) {
		$("#" + el).dialog("destroy");
	});
}
function wb_iFrameDialog(width, height, title, modal, iframe, url) {
	var wrapper = 'DJddfhSHS34';
	jQuery('<div id="' + wrapper + '"></div>').appendTo("body");
	$("#" + wrapper).dialog( {
		title : title,
		bgiframe : true,
		height : height,
		width : width,
		modal : true
	});

	if (iframe) {
		jQuery("#" + wrapper)
				.html(
						"<iframe frameborder='0' hspace='0' src='"
								+ url
								+ "' name='TB_iframeContent"
								+ Math.round(Math.random() * 1000)
								+ "' allowtransparency='true' style='padding:0!important;margin:0!important;width:100%;height:100%;background:transparent!important' ></iframe>");
	}

	jQuery(".ui-dialog").bind('dialogclose', function(event) {
		wb_close_dialog(wrapper);
	});
	return false;
}
function wb_ajaxPost(form, responseElId) {
	wb_showUpdate('#' + responseElId);
	var req = jQuery.post(jQuery('#' + form).attr('action'), jQuery('#' + form)
			.serialize(), function(html) {
		jQuery('#' + responseElId).html(html);
		wb_hideUpdate('#' + responseElId);
		req = null;
	});
}
function wb_showUpdate(element) {
	if (element == undefined) {
		element = "body";
	}
	jQuery(element).ajaxLoader();
}
function wb_hideUpdate(element) {
	if (element == undefined) {
		element = "body";
	}
	jQuery(element).ajaxLoaderRemove();
}
function wb_close_dialog(wrapper) {
	$("#" + wrapper).remove();
	jQuery(".wb_ui-dialog").remove();
}
function wb_navigate(url) {
	document.location = url;
}

/* Loader */
jQuery.fn.ajaxLoader = function(conf) {
	var config = jQuery.extend( {
		className : 'wb_loader'
	}, conf);

	return this.each(function() {
		var t = jQuery(this);

		if (!this.ajaxLoader) {
			var offset = t.offset();
			var dim = {
				left : offset.left,
				top : offset.top,
				width : t.outerWidth(),
				height : t.outerHeight()
			};

			this.ajaxLoader = jQuery(
					'<div class="' + config.className + '"></div>').css( {
				position : 'absolute',
				left : dim.left + 'px',
				top : dim.top + 'px',
				width : dim.width + 'px',
				height : dim.height + 'px'
			}).appendTo(document.body).hide();
		}

		this.ajaxLoader.fadeIn(500);
	});
};

jQuery.fn.ajaxLoaderRemove = function() {
	return this.each(function() {
		if (this.ajaxLoader) {
			this.ajaxLoader.fadeOut(500);
		}
	});
};
function checkFieldOptions(selObj, showHideEl) {
	if (selObj.value == 1) {
		jQuery('#' + showHideEl).show();
	} else {
		jQuery('#' + showHideEl).hide();
	}
}
