// General Support v1.0
// Andrew Pettican (February 2010)
//
// Changelog:
// v1.0 - 10/02/2010 - Initial build
//////////////////////////////////////////////////////////////////

// ---------------------------------------------------------------
// Parameters
// ---------------------------------------------------------------

var gs_file_dummy_id_suffix = "_dummy";

// ---------------------------------------------------------------
// Parameters End
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// JS Events
// ---------------------------------------------------------------

jQuery(document).ready(function()
{
	// Preload some images - begin
	//////////////////////////////////////////////////////////////
	
	//jQuery('<img>').attr('src', 'images/layout/arrow-blue.gif');
	
	//////////////////////////////////////////////////////////////
	// Preload some images - end
	
	
	// Start banner rotation
	$('.banner_tall, .banner_short').cycle({ 
		timeout: 5000
	});
	
	
	// Show/Hide trigger links
	$('a.show_hide_trigger').click(function()
	{
		// Find the parent p tag
		var link_parent = this.parentNode;
		
		// Determine the new mode
		var show_block = ($(this).hasClass('active') === false);
		
		// Show/Hide the block
		if(show_block)
		{
			// Show the full block, and hide the summary block
			$(link_parent).siblings('.text_block_full').removeClass('hide').addClass('show');
			$(link_parent).siblings('.text_block_summary').removeClass('show').addClass('hide');
			$(this).html("Hide").addClass('active');
		}
		else
		{
			// Show the summary block, and hide the full block
			$(link_parent).siblings('.text_block_full').removeClass('show').addClass('hide');
			$(link_parent).siblings('.text_block_summary').removeClass('hide').addClass('show');
			$(this).html("Read more").removeClass('active');
		}
		return false;
	});
	
	// Rollover submit image form elements
	$('input.submit_img').mouseenter(function()
	{
		var old_img_src = $(this).attr('src');
		var new_img_src = old_img_src.replace("_nm.gif", "_hl.gif");
		$(this).attr('src', new_img_src);
	});
	$('input.submit_img').mouseleave(function()
	{
		var old_img_src = $(this).attr('src');
		var new_img_src = old_img_src.replace("_hl.gif", "_nm.gif");
		$(this).attr('src', new_img_src);
	});
	
	// Create a popup window
	$('a[rel=popup]').each(function()
	{
		// Update titles
		var old_title = $(this).attr("title");
		if(old_title !== "")
		{
			$(this).attr("title", old_title+" [Opens in new window]");
		}
		else
		{
			$(this).attr("title", "[Opens in new window]");
		}
		
		// Perform the popup when clicked
		$(this).bind("click", function()
		{
			// Default window attributes
			var window_width = 400;
			var window_height = 400;
			var window_resizable = 0;
			var window_status = 1;
			var scrollbars_status = 0;
			var d = new Date();
			var window_name = 'popup_'+d.getTime();
			
			// Determine window attributes
			// These should be attached to the "rev" attribute of the <a> tag in the format:
			// width=300; height=300; status=1; resizable=0; name=blahblah
			var window_attributes = $(this).attr("rev").split(";");
			for(i=0; i<window_attributes.length; i++)
			{
				if(window_attributes.hasOwnProperty(i))
				{
					var attrib_parts = window_attributes[i].split("=", 2);
					if(attrib_parts.length == 2)
					{
						// Determine what the value of this attribute is.
						// NB: attributes should alway be an integer
						var attribute_key = jQuery.trim(attrib_parts[0]);
						var attribute_value_str = jQuery.trim(attrib_parts[1]);
						var attribute_value = parseInt(attribute_value_str, 10);
						if(!isNaN(attribute_value))
						{
							if(attribute_key == "width" && attribute_value >= 100)
							{
								window_width = attribute_value;
							}
							else if(attribute_key == "height" && attribute_value >= 100)
							{
								window_height = attribute_value;
							}
							else if(attribute_key == "resizable" && attribute_value >= 0)
							{
								window_resizable = attribute_value;
							}
							else if(attribute_key == "status" && attribute_value >= 0)
							{
								window_status = attribute_value;
							}
							else if(attribute_key == "scrollbars" && attribute_value >= 0)
							{
								scrollbars_status = attribute_value;
							}
						}
						
						// For handling string attributes
						if(attribute_key == "name" && attribute_value_str != "")
						{
							window_name = attribute_value_str;
						}
					}
				}
			}
			
			var output_attributes = "width="+window_width+", height="+window_height+", resizable="+window_resizable+", status="+window_status+", scrollbars="+scrollbars_status+"";
			//alert(output_attributes +'\n'+ window_name);
			
			window.open(this.href,window_name,output_attributes);
			return false;
		});
	});
	
	
	// Load the page in a new window
	$('a[rel=external]').each(function()
	{
		// Set target and update titles
		$(this).attr("target", "_blank");
		var old_title = $(this).attr("title");
		if(old_title !== "")
		{
			$(this).attr("title", old_title+" [Opens in new window]");
		}
		else
		{
			$(this).attr("title", "[Opens in new window]");
		}
	});
});

// ---------------------------------------------------------------
// JS Events End
// ---------------------------------------------------------------



// ---------------------------------------------------------------
// Functions
// ---------------------------------------------------------------

/**
 * Email link generator
 */
function insertContact(theName, linkText, mode, linkclass)
{
	var theDomain = ('resoluteassetmanagement' + '.' + 'com');
	if(typeof(mode) != "undefined" && mode == "ram com")
	{
		theDomain = 'res-am' + '.' + 'com';
	}
	
	var theClass = "";
	if(typeof(linkclass) == "string")
	{
		theClass = 'class="' + linkclass + '" ';
	}
	
	theAddress = (theName + '&#064' + theDomain);
	if(linkText=='me'){
		linkText = theAddress;
	}
	document.write('<a ' + theClass + 'href="mailto:' + theAddress +'">' + linkText + '<\/a>');
}

// ---------------------------------------------------------------
// Functions End
// ---------------------------------------------------------------

