/***********************************************************

Developed for use on www.baltimorejewishlife.com by

Navid Raoofian - Web Interactive Technologies / www.webintech.com

For licensing information please contact us at www.webintech.com

***********************************************************/

function MakeAd(elem,width)
{
	var button_offsetX = "-15px";
	var button_offsetY = "1px";
	var state = GetAdState();
	// Create Object
	var obj = $(elem);
	// Get the ID
	var id = obj.attr("id");
	// Set the width explicitly
	obj.width( width );
	// Set the position to relative, if you need absolute positioning, add one parent DIV with abs pos
	obj.css({"position" : "relative"});
	// Create button to show/hide
	obj.append("<div id='btn_" + id + "' ></div>");
	$("#btn_" + id).addClass("ad_expand");

	if( !state )	// collapse state
	{
		// Hide bigger image
		obj.find(".rbig").hide();
	}
	else
	{
		// Hide bigger image
		obj.find(".rsmall").hide();
		$("#btn_" + id).addClass("a3");
	}

	$("#btn_" + id).hover(
			function()
			{
				// Add Hover class to highlight on mouse hover
				var ths = $(this);
				var parent = ths.parents("div");
				var expand = parent.find(".rbig").is(':visible');
				if(expand)
					ths.addClass("a4");
				else
					ths.addClass("a2");
			},
			function()
			{
				// Remove highlight class
				var ths = $(this);
				var parent = ths.parents("div");
				var expand = parent.find(".rbig").is(':visible');
				if(expand)
					ths.removeClass("a4");
				else
					ths.removeClass("a2").removeClass("a3");
			}).css(
				{
					"position" : "absolute",		/* Make the button to stay at RHS */
					"right" : button_offsetX,
					"bottom" : button_offsetY,
					"z-index" : 10
			}).click(function()
			{
				var ths = $(this);
				var parent = ths.parents("div");
				var hide = parent.find(".rbig").is(':visible');
				if( hide )
					ths.removeClass("a3").removeClass("a4");
				else
					ths.addClass("a3").addClass("a4");
				// Toggle Images
				parent.find(".rbig").toggle();
				parent.find(".rsmall").toggle();
			});
	function GetAdState()
	{
		var rand = Math.ceil(Math.random()*3);
		return rand == 3;
	}
}

