﻿jQuery(document).ready(function () {

	/* Sidebar search in-field label ---------------------------*/

	jQuery("#sidebar label").inFieldLabels({ fadeOpacity: 0.25 });


	/* Map & Gallery swapping ----------------------------------*/

	jQuery('.adventure .map').show();

	jQuery('ul.thumbs a.thumb').click(function () {
		jQuery('.adventure .map').fadeOut(500);
		jQuery('.adventure .slideshow-container').fadeIn(500);
	});

	jQuery('.adventure a.btn_viewmap').click(function () {
		jQuery('.adventure .map').fadeIn(500);
		jQuery('.adventure .slideshow-container').fadeOut(500);
	});

	/* Star Ratings --------------------------------------------*/
	jQuery('.hover-star').rating({
		focus: function (value, link) {
			var tip = jQuery('#hover-text');
			tip[0].data = tip[0].data || tip.html();
			tip.html(link.title || 'value: ' + value);
		},
		blur: function (value, link) {
			var tip = jQuery('#hover-text');
			jQuery('#hover-text').html(tip[0].data || '');
		},
		callback: function (value, link) {
			vote(value);
		}
	});
});


function vote(value) {
	var parts = value.split("|");

	var adventureId = parts[0];
	var userId = parts[1];

	if (userId == "")
		userId = null;

	var vote = parts[2];

	// have they voted already (weak check)
	var cookieName = "vote" + adventureId;
	var hasVoted = jQuery.cookie(cookieName);
	if (hasVoted) {
		return false;
	}

	// save it!
	PageMethods.SubmitVote(adventureId, userId, vote);

	// save cookie
	jQuery.cookie(cookieName, vote, { expires: 99 });

	return true;
}

