function show(part) {
	if (selected != "s"+part) {
		$("img#image").attr("src", body_parts+part);
	}
}

function select(part, part_title, location_id) {
	selected = "s"+part;
	
	$("img#image").attr("src", body_parts+part);
	
	var selected_part = "Izbran del: <b>"+part_title+"</b>";
	$("span#naziv").html(selected_part);
	$("input#location_id").attr("value", location_id);
}

function out() {
	$("img#image").attr("src", body_parts+selected);
}

function hover(id, img) {
	$("img#socialimage_"+id).attr("src", assets_url+"images/social_icons/"+img);
}

function hout(id, img) {
	$("img#socialimage_"+id).attr("src", assets_url+"images/social_icons/"+img);
}

jQuery.preloadImages = function() {
	var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
	for(var i = a.length -1; i > 0; i--) {
		jQuery("<img>").attr("src", a[i]);
	}
}

function openPop(url, width, height, s)	{
	x = (640 - width)/2;
	y = (480 - height)/2;
	if (screen)	{
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
	}
	if (navigator.appName == "Netscape")
		height = height + 50;
	window.open(url, '', 'scrollbars=1, status=0, resizable=1, width=' + width + ', height=' + height + ', screenX=' + x + ', screenY=' + y + ', top=' + y + ', left=' + x);
}

/*glasovanje*/
function get_votes() {
	$.ajax({
		type: "POST",
		url: base_url+"tattoo/get_votes",
		data: ({tattoo_id : tattoo_id, user_id: user_id}),
		cache: false,
		dataType: "json",
		success: function(f) {
			var list = "";
			var list_more = "";
			var css_class = "";
			var more_btn  = "";
			for (var k=0; k < f.votes.length; k++) {
				if (k%12 == 11) {
					css_class = "user_vote_last";
				} else {
					css_class = "user_vote";
				}
				
				if (k < 60) {
					list += "<div class=\""+css_class+"\"><a href=\""+base_url+"profile/"+f.votes[k].user_id+"/"+f.votes[k].nice_name+"\" title=\"Zavedno profil: "+f.votes[k].fb_name+"\"><img src=\"http://graph.facebook.com/"+f.votes[k].fb_uid+"/picture\" width=\"50\" height=\"50\" alt=\""+f.votes[k].fb_name+"\" /></a></div>";
				} else {
					list_more += "<div class=\""+css_class+"\"><a href=\""+base_url+"profile/"+f.votes[k].user_id+"/"+f.votes[k].nice_name+"\" title=\"Zavedno profil: "+f.votes[k].fb_name+"\"><img src=\"http://graph.facebook.com/"+f.votes[k].fb_uid+"/picture\" width=\"50\" height=\"50\" alt=\""+f.votes[k].fb_name+"\" /></a></div>";
				}
			}
			$("div#tattoo_votes").html(list);
			if (list_more) {
				more_btn = "<span style=\"cursor: pointer; color: #fff;\" onclick=\"display_more();\">Prikaži ostale glasove &gt;&gt;</span>";
				$("div#more_less_btn").html(more_btn);
				$("div#tattoo_votes_more").html(list_more);
			}
			nr = "<a href=\""+current_url+"#votes\" title=\"glasovi\" class=\"white\">"+k+"</a>";
			$("div#tattoo_votes_nr1").html(nr);
			$("div#tattoo_votes_nr2").html(k);
			$("div#tattoo_votes_nr3").html(k);
			
			if ((user_id) && (f.voted_for)) {
				$("div#user_voted_false").hide();
				$("div#user_voted_true").show();
			} else {
				$("div#user_voted_false").show();
				$("div#user_voted_true").hide();
			}
	}});
}

function display_more() {
	less_btn = "<span style=\"cursor: pointer; color: #fff;\" onclick=\"display_less();\">Skrij ostale glasove &gt;&gt;</span>";
	$("div#more_less_btn").html(less_btn);
	$("div#tattoo_votes_more").fadeIn("slow");
}

function display_less() {
	more_btn = "<span style=\"cursor: pointer; color: #fff;\" onclick=\"display_more();\">Prikaži ostale glasove &gt;&gt;</span>";
	$("div#more_less_btn").html(more_btn);
	$("div#tattoo_votes_more").fadeOut("slow");
}

function vote() {
	$.post(base_url+"tattoo/vote", { tattoo_id: tattoo_id, user_id: user_id },
		function(data) {
			$("div#user_voted_false").hide();
			$("div#user_voted_true").fadeIn("slow");
			get_votes();
		});
}

function remove_vote() {
	$.post(base_url+"tattoo/remove_vote", { user_id: user_id, tattoo_id: tattoo_id },
		function(data) {
			$("div#user_voted_true").hide();
			$("div#user_voted_false").fadeIn("slow");
			get_votes();
		});
}

