if (top.frames && top.frames.length != 0){
    self.parent.location=self.document.location;
};

function GAW_preload() {
	if (arguments.length) {
		for(var i=0; i<arguments.length;i++) {
			var newImg = new Image();
			newImg.src = '/assets/i/' + arguments[i];
		}
	}
}

function onWindowLoad() {
	var thumbs = document.getElementsByClassName('thumb');
	$A(thumbs).each(function(element){
		element.style.zoom = 1;
	});
}

Event.observe(window, 'load', onWindowLoad);

GAW_preload(
	'a_hover.gif', 'bl_bl.gif', 'bl_br.gif', 'bl_tl.gif', 'bl_tr.gif', 
	'body_bg.png', 'headline_bg.gif', 'headline_edge.gif', 
	'stars.gif', 'leftline_bg.gif', 'leftline_edge.gif'
);

function onDocumentClick(event) {
	return;
	Position.prepare();
	var pointer = [Event.pointerX(event), Event.pointerY(event)];
	
	new Ajax.Request('/server/request.php', {
		parameters: 'action=hitmap&x=' + pointer[0] + '&y=' + pointer[1] + 
					'&w=' + document.body.offsetWidth + '&h=' + document.body.offsetHeight +
					'&ua=' + escape(navigator.userAgent) + '&p=' + escape(location.pathname) + 
					'&r=' + Math.random() + '&z=' + (new Date).getTimezoneOffset(),
		onComplete: function(response){return;}
	});
}

function setCookie(name, value, expires, path, domain, secure) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + expires*24*60*60*1000);		
	document.cookie= name + "=" + escape(value) +
		((expdate) ? "; expires=" + expdate.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}




var rating = {
	rate: function(imageid, k) {
		new Ajax.Request('/server/request.php', {
			parameters: 'action=rating&imageid=' + imageid + '&k=' + k,
			onComplete: function(response) {
				eval("var ajaxres = ("+ response.responseText +");");
				if (!ajaxres || !ajaxres.status) {
					return;
				}
				
				// set cookie
				var rated = getCookie('rated');
				rated=rated?rated.split(","):[];
				rated.push(imageid);
				rated = rated.join(",");
				setCookie('rated', rated, 30, '/');
				
				// success rating
				var element = $('rating_' + imageid);
				if (element)
					element.style.width = k * 24 + 'px';
			}
		});
	}
};


function download(imageid) {
	if (!imageid) return;
	
	new Ajax.Request('/server/request.php', {
		parameters: 'action=download&imageid=' + imageid,
		onComplete: new Function("return false;")
	});
}

function send_hit(imageid) {
	if (!imageid) return;

	new Ajax.Request('/server/request.php', {
		parameters: 'action=makehit&imageid=' + imageid,
		onComplete: new Function("return false;")
	});
}


Event.observe(document, 'click', onDocumentClick.bindAsEventListener(window));