jQuery.page = function(options) {
	var instance = new jQuery.ifreewebproxy(options);
	return instance;
};

jQuery.ifreewebproxy = function(options) {
	this.settings = jQuery.extend({}, jQuery.ifreewebproxy.defaults, options);
};

jQuery.ifreewebproxy.adv = function() {
	this.size;
	this.index;
	this.name;
	this.userAgent;
	this.sended = false;
			
	this.send = function() {
		if (!this.sended) {
			var sendData = "size="+this.size+"&name="+this.name+"&index="+this.index+"&userAgent="+this.userAgent;
				var msg = $.ajax({
				type: "POST",
				url: "adc",
				async: false,
				data: sendData
			}).responseText;
					
			this.sended = true;
		}
	}
};

jQuery.extend(jQuery.ifreewebproxy, {
	
	defaults : {

	},
	
	prototype: {
		
		doAdv : function() {
				var selIndex = null;
				var ad = new Array();
				
				$("iframe").each(function(i) {
					//alert(this.src);
					var n = this.getAttribute("name");
					var src = this.getAttribute("src");
					if (/google_ads/.test(n) || /googlesyndication.com/.test(src)) {
							var obj = new jQuery.ifreewebproxy.adv();
							try {
								obj.size = this.getAttribute("width") + "x" + this.getAttribute("height");
								obj.index = i;
								obj.name = this.getAttribute("name");
								obj.userAgent = navigator.userAgent.toLowerCase();
							} catch (e) {}
							
							ad[i] = obj;
			
							if ($.browser.msie) {
								$(this).focus(function(){
									selIndex = i;
								});			
							} else {
								$(this).load(function() {
									this.addEventListener('mouseover', function(e) {
										selIndex = i;
									}, false);
									
									this.addEventListener('mouseout', function(e) {
										selIndex = null;
									}, false);
								});
							}
						} else {
							jQuery("#adv_" + i).hide();
						}
				});
	
					if ($.browser.msie) {
						window.attachEvent('onbeforeunload', function() {
							if (selIndex != null) {
								try {
									ad[selIndex].send();
								} catch (e) { }
							}
						});
					} else {
						window.addEventListener('beforeunload', function(e) {
							if (selIndex != null) {
								try {
									ad[selIndex].send();
								} catch (e) { }
							}
						}, false);
					}
		}
		
	}
});

var page = $.page();
