function createBookmark(name) {
	var title = name;
	var url = document.location;
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute("href",url);
		elem.setAttribute("title",title);
		elem.setAttribute("rel","sidebar");
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

function addToFavorites(type_id, item_id) {
	var data = { action: "add", type_id: type_id, item_id: item_id };
	$.post("/ajax/action_favorites.php", data, function (data) {
		if (data.code == 2) {
			document.location = "join.html";
			return false;
		}
		alert(data.message);
	}, "json");
}

function deleteFavorite(type_id, item_id) {
	var data = { action: "remove", type_id: type_id, item_id: item_id };
	$.post("/ajax/action_favorites.php", data, function (data) {
		alert(data.message);
	}, "json");
}

function addComment(item_id) {
	var comment = $("#newComment").val();
	var data = { action: "add", body: comment, type_id: 5, item_id: item_id };
	if(comment == undefined || comment.length <= 0) {
		alert("Your comment is empty... Please enter some text before posting");
		return false;
	}
	$("#commentForm input").remove();
	$.post("/ajax/action_comment.php", data, function (data) {
		$("#thankYouContainer").fadeIn("slow");
		$("#newCommentContainer").fadeOut("slow");
		alert(data.message);
	}, "json");
}

function rateComment (comment_id, bump) {
	var data = { action: "bump", comment_id: comment_id, rating: bump };
	$.post("/ajax/action_comment.php", data, function (data) {
		alert(data.message);
	}, "json");
}


function rate(rating, item_id) {
	$.post("/ajax/action_rating.php", 'type_id=5&item_id=' + item_id + '&rating=' + rating, function (data) {
		alert(data.message);
		if (data.code == 0) {
			var hot_perc = Math.round((data.avg_vote * 20 - 20) * 1.25);
			var cold_perc = 100 - hot_perc;
			$('#percent_hot').html(hot_perc + '%');
			$('#percent_cold').html(cold_perc + '%');
			$('#bar_hot').css("width", Math.round(hot_perc * 1.78) + 'px');
			$('#bar_cold').css("width", Math.round(cold_perc * 1.78) + 'px');
		}
	}, "json");
}

function initRolls () {
	$("ul.thumbs li a.image").each(function() {
		this.images = new Array();
		this.origimg = this.style.backgroundImage;
		if (this.origimg != '') {
			prefix = this.origimg.substring(5);
			prefix = prefix.substring(0, prefix.length - 2);
			for (y = 0; y < 5; y++) {
				this.images[y] = new Image();
				this.images[y].src = prefix.replace(/(sample|promo)_[0-9]+/, "promo_" + (2 + y * 2));
			}
			$(this).unbind().hover(
				function() {rollImages(this);},
				function() {clearRoll(this);}
			);
		}
	});
}
function rollImages(thumb, start) {
	if (start == undefined || start > thumb.images.length - 1)
		start = 0;
	thumb.style.backgroundImage = "url(" + thumb.images[start].src + ")";
	alertTimerId = setTimeout (function() {rollImages(thumb, start + 1);}, 652);
}
function clearRoll(thumb) {
	clearTimeout(alertTimerId);
	thumb.style.backgroundImage = thumb.origimg;
}

function camsSwitch (cat) {
	iframe = $("iframe");
	iframe.attr("src", iframe.attr("src").replace(/&cat=[0-9]*/, "&cat=" + cat));
}
