var reporter = null;

var Report = Class.create({
	id: 0,
	time_id: 0,
	initialize: function() {
		var links = $$('a[rel=reporter]');
		for (var i = 0; i < links.size(); i++) {
			Event.observe(links[i], 'click', this.show_reporter.bindAsEventListener(this));
		}
		this.config_reporter();
	},
	config_reporter: function() {
		Event.observe($('report'), 'mouseover', this.clear_timeout.bindAsEventListener(this));
		Event.observe($('report'), 'mouseout', this.hide_reporter.bindAsEventListener(this));
	},
	clear_timeout: function() {
		window.clearTimeout(this.time_id);
	},
	hide_reporter: function() {
		return this.time_id = window.setTimeout("$('report').hide()", 500);
	},
	show_reporter: function(event) {
		if (this.time_id != 0) window.clearTimeout(this.time_id); 
		var element = Event.element(event);
		this.id = element.readAttribute('alt');
		var anchor = element.parentNode;
		var position = anchor.positionedOffset();
		$('report').setStyle({
			left: position.left+'px',
			top: position.top+'px'
		});
		window.setTimeout("$('report').show()", 200);
		this.hide_reporter();
	},
	report: function(error) {
		new Ajax.Request('report/index', {
			parameters: {"id":this.id, "error":error},
			onSuccess: function(transport) {
				if (transport.responseText == 'ok') {
					alert('Thanks for your attribution');
				}
			}
		});
	}	
});

function bookmark() {
	title = "Creamy Sites - Free Porn Movies & Pictures"; 
	url = "http://www.creamysites.com/";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if (window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); 
	} else if (window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function init() {
	reporter = new Report();
	
	Event.observe($('search'), 'focus', function() {
		if ($F('search') == 'Search ...') {
			$('search').value = '';
		}
	});
	
	Event.observe($('search'), 'blur', function() {
		if ($F('search') == '') {
			$('search').value = 'Search ...';
		}
	});
	
	Event.observe($('home'), 'click', function() {
		window.location = 'http://www.creamysites.com/';
	});
}

Event.observe(window, 'load', init);

