/*
 * /web/js/core.js -- Commonly used JavaScript functions.
 *
 * Copyright 2007, 2008 Andreas Tolfsen <ato@sny.no>
 * Licensed under the GNU GPL v2 or later.  Share and enjoy.
 */

$(document).ready(function(){

	/* cluetip */
	/*$("#top_menu a.messages").click(function(){
		$("#tab-1").show();
	});*/

	/* talko-specific */

	/*$("#top_menu a.messages").cluetip({
		local: true,
		sticky: true,
		activation: "click",
		positionBy: "fixed",
		topOffset: 22,
		leftOffset: -92,
		showTitle: false,
		arrows: false,
		width: 240,
		height: 295,
		fx: { open: "slideDown" }
	});

	$("#top_menu a.groups").cluetip({
		local: true,
		sticky: true,
		activation: "click",
		positionBy: "fixed",
		topOffset: 22,
		leftOffset: -92,
		showTitle: false,
		arrows: false,
		width: 240,
		fx: { open: "slideDown" }
	});*/

	$("a.show-tab-1").click(function(){
		$("#tab-1").fadeIn();
		$("#tab-2").hide();
	});

	$("a.show-tab-2").click(function(){
		$("#tab-2").fadeIn();
		$("#tab-1").hide();
	});

	/* messaging */
	$("div.messaging_sendbox").hide();
	$("a.toggle_messaging_box").click(function(){$("div.messaging_sendbox").toggle("slow")});

	/* textile */
	$("div.toggle_textile_helper").click(function(){
		if ($("div.textile_helper").is(":hidden")) {
			$(this).css("background-image", "url('./graphics/icons/silk/arrow_up.png')");
		} else {
			$(this).css("background-image", "url('./graphics/icons/silk/arrow_down.png')");
		}
		$("div.textile_helper").toggle("slow");
	});

	/* search */
	$("h3.toggle_search_news").click(function(){$("div.hits_news").toggle("slow")});
	$("h3.toggle_search_content").click(function(){$("div.hits_content").toggle("slow")});
	$("h3.toggle_search_journal").click(function(){$("div.hits_journal").toggle("slow")});

	/* tags */
	$("h3.toggle_tags_news").click(function(){$("div.tags_news").toggle("slow")});
	$("h3.toggle_tags_content").click(function(){$("div.tags_content").toggle("slow")});
	$("h3.toggle_tags_journal").click(function(){$("div.tags_journal").toggle("slow")});

	$("h2.toggle_shop_cart").click(function(){$("div.shop_cart").toggle("slow")});

	/* images */
	$("input#new_album").click(function(){
		$("input#new_album_text").focus();
	});

	/* comments quote button */
	var quote_text = $("#comments div.quote").html();
	$("#comments div.quote").html("<input class='quote_action' type='button' value='" + quote_text + "' />");

	$("input.quote_action").click(function(){
		var current_comment = $("#comment").text();
		$(this).parent().parent("div.text").siblings("p").each(function(){
			alert($(this).html());
		});

		//alert(comment);

		/*
		$(this).parent().parent().siblings("div.text p").each(function(n, i){
			var line = i.innerHTML;
			alert(line);
		});
		*/

		//alert(comment);

		//comment = "bq. " + jQuery.trim(comment) + "\n\n";
		//$("#comment").val(current_comment + comment);
	});

});
