var photoshop = {

	paginate: function(node_obj) {
		var page=parseInt($(node_obj).attr("page"));
		$.get("/photoshop/a_photoshop.php", {"photoshop_id": $("#photoshop_image").attr("photoshop_id"), "page": page}, photoshop.paginate_return, "json");

		//Update Pagination Buttons
		if (page>1) {
			$("a", "#photoshop_slide_next").attr("page", page-1);
			$("a", "#photoshop_page_next").attr("page", page-1);
			$("#photoshop_slide_next").show();
			$("#photoshop_page_next").show();
			$("#photoshop_page_next_end").show();
		} else {
			$("#photoshop_slide_next").hide();
			$("#photoshop_page_next").hide();
			$("#photoshop_page_next_end").hide();
		}

		var total_photos=parseInt($("#photoshop_image").attr("total_photos"));
		if (page<total_photos) {
			$("a", "#photoshop_slide_prev").attr("page", page+1);
			$("a", "#photoshop_page_prev").attr("page", page+1);
			$("#photoshop_slide_prev").show();
			$("#photoshop_page_prev").show();
			$("#photoshop_page_prev_end").show();
		} else {
			$("#photoshop_slide_prev").hide();
			$("#photoshop_page_prev").hide();
			$("#photoshop_page_prev_end").hide();
		}

		//Scroll Pagination Numbers
		$("li.numbers").each(function(i) {
			if ((total_photos-page)!=i) {
				$(this).removeClass("selected");
			} else {
				$(this).addClass("selected");
			}
		});
		pos=0;
		if ((page+7)<total_photos) {
			pos=(total_photos-(page+7))*(-24);
			if (page<3) pos=(total_photos-10)*(-24);
		}
		$("ul", "div.pagination_wrapper").css("left", pos+"px");

		$("iframe", "div.AdBox").attr("src", $("iframe", "div.AdBox").attr("src")); //refresh ads

		return false;
	},

	paginate_return: function(data, textStatus) {
		$("#photoshop_image_view").attr("src", data.photo);
		if (data.page==1) {
			$("#photoshop_rank").html("And the WINNER is...");
			$("p", "#photoshop_by").html('<a href="/members/'+data.user_name+'">'+data.author_name+'</a>. Congrats, You win money!');
		} else {
			$("#photoshop_rank").html("# "+data.page);
			$("p", "#photoshop_by").html('by: <a href="/members/'+data.user_name+'">'+data.author_name+'</a>');
		}

		self.location="#"+data["page"];
		return false;
	},

	setView: function(view_type, photo_id) {
		this._setCookie("photoshop_"+photo_id, view_type, 1);
		//document.location = document.location;
		return true;
	},

	_setCookie: function(c_name,value,expiredays) {
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
						((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+
						";path=/";
	},

	social_buttons: function() {
		$("img", "#social_buttons").each(
			function() {
				$(this).hover(
					function() {
						var src=this.src.replace('_off', '_on');
						this.src=src;
					},
					function() {
						var src=this.src.replace('_on', '_off');
						this.src=src;
					}
				);
			}
		);
	}
}