$(document).ready(function(){

	$(".pho").click(function(){			var id = $(this).parent().children("#sku").val();
			var ds = getDimantions();
			var ps = PageScroll();
			var rotaterTop = ps.y + (ds.windowHeight * 0.5);

			$("body").prepend("<div id='loading'></div>");
			$("#loading").css("position","absolute");
			$("#loading").css("z-index","999");
			$("#loading").css("background","#FFFFFF");
			$("#loading").css("width",ds.pageWidth-20+"px");
			$("#loading").css("height",ds.pageHeight+"px");
			$("#loading").fadeTo(250,0.4);

			$("body").prepend("<div id='rotater'><img src='/img/main/ajax_loader.gif'></div>");
			$("#rotater").css("position","absolute");
			$("#rotater").css("z-index","1000");
			$("#rotater").css("top",rotaterTop+"px");
			$("#rotater").css("left",ds.pageWidth/2-32+"px");
			$("#rotater").fadeTo(50,100);

			markme(id);

	});

	$(".close_ulister_deny").click(function(){
		$(".user_ulister_deny").css("display","none");
	});
});

function markme(id)
{
	$.ajax({
		type: "POST",
		url: "/photos/markme",
		data: "sku="+escape(id),
		success: HandleServerResponse
	});
}

function HandleServerResponse(response)
{
	var tmp = response.split(';');
	var id = tmp[0];
	var str = tmp[1];
	var status = tmp[2];
	$("#loading").remove();
	$("#rotater").remove();
	if (status == 0){
		var ds = getDimantions();
		var ps = PageScroll();
		var rotaterTop = ps.y + (ds.windowHeight * 0.4);

		$(".user_ulister_deny").css("display","block");
		$(".user_ulister_deny").css("top",rotaterTop-170+"px");
		$(".user_ulister_deny").css("left",ds.pageWidth/2-220+"px");

	}else{
		$("#ulister"+id).prepend(str);
	}
}

function getDimantions() {
	var dims = {};
	var dbw, dbh;

	if (window.innerHeight && window.scrollMaxY) {
		dbw = window.innerWidth + window.scrollMaxX;
		dbh = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		dbw = document.body.scrollWidth;
		dbh = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		dbw = document.body.offsetWidth;
		dbh = document.body.offsetHeight;
	}

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			dims.windowWidth = document.documentElement.clientWidth;
		} else {
			dims.windowWidth = self.innerWidth;
		}
		dims.windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		dims.windowWidth = document.documentElement.clientWidth;
		dims.windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		dims.windowWidth = document.body.clientWidth;
		dims.windowHeight = document.body.clientHeight;
	}

	dims.pageHeight = Math.max(dbh, dims.windowHeight);
	dims.pageWidth = Math.max(dbw, dims.windowWidth);

	return dims;
}

function PageScroll(){
	var scroll = {};

	if (self.pageYOffset) {
		scroll.y = self.pageYOffset;
		scroll.x = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		scroll.y = document.documentElement.scrollTop;
		scroll.x = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		scroll.y = document.body.scrollTop;
		scroll.x = document.body.scrollLeft;
	}

	return scroll;
}
