﻿
var gradientElements = [];
Spot.Events.register(window, "ondomready", function() {
	gradientElements.forEach(function(div) {
		var height = $(div).offsetHeight;
		$(div).style.background = "url(/gradient.img?h=" + height + "&c1=fafafa&c2=eaeaea) repeat-x";
	});
});

function share(id, el) {
    Jspb.invoke({assemblyName: "Spot.Engine", className: "Spot.Engine.BusinessObjects.Feed", methodName: "Share", args: [{type: "long", data: id}]}, share_callback, el)
};

function share_callback(ret, sender) {
    sender.innerHTML = "Shared";
};

function star(id, el) {
	Jspb.defaultInvokeUrl = "/default.aspx";
	Jspb.invoke({assemblyName: "Spot.Engine", className: "Spot.Engine.BusinessObjects.User", methodName: "StarItem", args: [{type: "long", data: id}]}, star_callback, {el:el, id:id});
};

function star_callback(ret, sender) {
	if (ret)
	{
		var el = sender.el.firstChild;
		if (el.nodeType == 3)
			el = el.nextSibling;
		el.src = "/_images/layout/star.png";
		sender.el.onclick = function() {
			unstar(sender.id, this);
			return false;
		};
		sender.el.title = "Unstar this item";
	}
};

function unstar(id, el, url) {
	Jspb.defaultInvokeUrl = "/default.aspx";
	Jspb.invoke({assemblyName: "Spot.Engine", className: "Spot.Engine.BusinessObjects.User", methodName: "UnstarItem", args: [{type: "long", data: id}]}, unstar_callback, {el:el, id:id, url: url});
};

function unstar_callback(ret, sender) {
	if (ret)
	{
		window.top.location = sender.url;
		return;
		var el = sender.el.firstChild;
		if (el.nodeType == 3)
			el = el.nextSibling;
		el.src = "/_images/layout/star_empty.png";
		sender.el.onclick = function() {
			star(sender.id, this);
			return false;
		};
		sender.el.title = "Star this item";
	}
};

function showSpotIt(spotword, itemId, returnTo) {
	var content = createLightbox(650, 280, 10, {closeButton: true, autoHide: false});
	content.innerHTML = "<iframe frameborder=\"0\" style=\"width: 650px; height: 280px;\" src=\"/SpotItFrame.aspx?spotword=" + spotword + "&itemId=" + itemId + "&rt=" + returnTo + "\"></iframe>";
};

function showStarIt(spotword, itemId, returnTo) {
	var content = createLightbox(650, 280, 10, {closeButton: true, autoHide: false});
	content.innerHTML = "<iframe frameborder=\"0\" style=\"width: 650px; height: 280px;\" src=\"/StarItFrame.aspx?spotword=" + spotword + "&itemId=" + itemId + "&rt=" + returnTo + "\"></iframe>";
};

function showRedeem(spotword, itemId) {
	var content = createLightbox(650, 280, 10, {closeButton: true, autoHide: false, onclose: function() {
		if (window.top["hasSent"] === true)
			window.location.reload();
	}});
	content.innerHTML = "<iframe frameborder=\"0\" style=\"width: 650px; height: 280px;\" src=\"/RedeemFrame.aspx?spotword=" + spotword + "&itemId=" + itemId + "\"></iframe>";
};

//function makeStarred(elementid, itemid) {
//	var el = jQuery("#" + elementid);
//	el.attr("title", "You have [b]Starred[/b] this Spot. Click to remove from [b]My Spots[/b]");
//	
//	el[0].onclick = function() {
//		unstar(itemid, this, window.top.location);
//		return false;
//	};
//	
//	el.children().first().css("background-image", "url(/_images/layout/new_star.png)");
//	el.children().last().html("Starred");
//	
//	scanElement(el[0]);
//};
