// shows the image description
//  http://localhost:3000/image_shells/30/images/new?request_id=29#
function showImageDescription(target)
{
	$("#metadata").css("display", "block");
}

$("#delete_stock").click(function (e) { 
	if(e.target.checked)
	{
    $("#thumb_stock").css("display", "none");
    $("#upload_stock").css("display", "block");
	} 
	else
	{
    $("#thumb_stock").css("display", "block");
    $("#upload_stock").css("display", "none");
	}
});

if (typeof SHRELP == "undefined" || !SHRELP) {
    var SHRELP = {};
}
SHRELP.namespace = function() {
    var A = arguments,
    E = null,
    C,
    B,
    D;
    for (C = 0; C < A.length; C = C + 1) {
        D = ("" + A[C]).split(".");
        E = SHRELP;
        for (B = (D[0] == "SHRELP") ? 1: 0; B < D.length; B = B + 1) {
            E[D[B]] = E[D[B]] || {};
            E = E[D[B]];
        }
    }
    return E;
};
SHRELP.updateCart = function	() {
	// console.log("updateCart")
}
SHRELP.initLoginPage = function	() {
	/*
	* signup page.  Copies 
	*/
	$("#same_as_billing_na").click(function (e) {
		console.log("BLA " + e.target.checked);
		if(e.target.checked)
		{
			$("#user_billing_address").attr("value", 	$("#user_contact_address").attr("value") );
			$("#user_billing_state").attr("value", 		$("#user_contact_state").attr("value") );
			$("#user_billing_zip").attr("value", 			$("#user_contact_zip").attr("value") );
			$("#user_billing_city").attr("value", 		$("#user_contact_city").attr("value") );	
		}
	});
}
SHRELP.clearBox = function (e) {
	e.target.value = "";
	$(e.target).unbind('focus',SHRELP.clearBox);
}
SHRELP.initLoginBox = function() {
	$("#password").bind('focus',SHRELP.clearBox);
	$("#password").focus(function(e) {
		e.target.type = "password";
	});
	$("#login").bind('focus',SHRELP.clearBox);
	$("#sign_in_hide").click(function(e) {
		$("#sign_in_open").hide();
	});
	$(".sign_in_link").click(function(e) {
		$("#sign_in_open").show();
	});
}
SHRELP.initSearchBox = function() {
	$("#query").bind('focus',SHRELP.clearBox);
	$("#search_form").submit(function(){
		var searchTerm = $("#query").attr("value");
		if(searchTerm == "Search" || searchTerm == "" )	return false;
		else return true;
	})
}
SHRELP.initLeftNav = function() {
	var navs = $(".collapsible_nav");
	var navObj = [];
	for(var i = 0; i < navs.length; i++) {
		// console.log(navs[i]);
		var btn = $(navs[i]).children(".collapsible_btn")[0];
		var list = $(navs[i]).children(".collapsible_list")[0];

		$(btn).click( function() {
			var tList = $(this).siblings(".collapsible_list");
			
			if($(tList).css("display") == "none")  $(this).css("background-position","-16px");
			else																	 $(this).css("background-position","0px 0px");

			tList.toggle("blind");
		});

	}
	
}

$(document).ready(function() {
	SHRELP.initLoginBox();
	SHRELP.initSearchBox();
	SHRELP.initLeftNav();
});
