/*	SONY STYLE TAB & TOGGLER FUNCTIONS
 *	Author: Branden Thompson, Front End Architect - Branden.Thompson at am dot sony dot com
 *	Date:	May 19, 2009
*/

/* -------------------------------------------------------------------------------------------
	Method: 			ToggleLayer
	Arguments:
						idToShow [string]
						classToHide [string]

	Pre-Conditions:
						* Prototype must be included before this file.
						* idToShow, classToHide must not be null or undefined.
						* idToShow, classToHide must correspond to valid HTML elements with
						  the corresponding ID and class existing within the page.

	Post-Conditions:
						* All elements with classToHide will be set to hide
						* HTML element with the corresponding ID matching idToShow will be
						  displayed.

------------------------------------------------------------------------------------------- */
function toggleLayer(idToShow, classToHide)
{
	// Let's turn off all the elements that have the classToHide as a defined class:
	$$("."+classToHide).invoke('hide');

	// ...and then let's show the element that has the corresponding idToShow:
	if($(idToShow))
	{
		$(idToShow).removeClassName('hidden');
		$(idToShow).appear();
	}
}

/* -------------------------------------------------------------------------------------------
	Method: 			toggleDefaultElement
	Arguments:
						defaultClassName [string]
						candidateClassName [string]

	Pre-Conditions:
						* Prototype must be included before this file.
						* defaultClassName, classToHide must not be null or undefined.
						* candidateClassName, classToHide must correspond to valid HTML elements with
						  the corresponding classes existing within the page.

						* This function relies on the fact that a server-side directive will be able
						  to determine which candidate element is set to be "default" via a content
						  management system, and can append the defaultClassName to the appropriate
						  page element prior to the page being served to the client.

	Post-Conditions:
						* All elements with candidateClassName will be set to hide
						* HTML element with the corresponding class matching defaultClassName will be
						  displayed.

------------------------------------------------------------------------------------------- */
function toggleDefaultElement(defaultClassName, candidateClassName)
{
	$$("."+candidateClassName).invoke('hide');
	$$("."+defaultClassName).invoke('appear');
}


/* -------------------------------------------------------------------------------------------
	Method: 			toggleDefaultElement
	Arguments:
						defaultClassName [string]
						candidateClassName [string]

	Pre-Conditions:
						* Prototype must be included before this file.
						* defaultClassName, classToHide must not be null or undefined.
						* candidateClassName, classToHide must correspond to valid HTML elements with
						  the corresponding classes existing within the page.

						* This function relies on the fact that a server-side directive will be able
						  to determine which candidate element is set to be "default" via a content
						  management system, and can append the defaultClassName to the appropriate
						  page element prior to the page being served to the client.

	Post-Conditions:
						* All elements with candidateClassName will be set to hide
						* HTML element with the corresponding class matching defaultClassName will be
						  displayed.

------------------------------------------------------------------------------------------- */
function changeIMGSource(htmlElementId, filePath, fileName, extension)
{
	ourNewImagePath = filepath + fileName + extension;
	return(ourNewImagePath);
}


function addItemToWishlist(ourHTMLLinkElement)
{
	// let's define the variables we need:

	var ourInProgressMessage = "Adding item to your wishlist...";
	var ourInProgressClass = "";

	//  so on click of the element (an <a>) we're going to need to:
	//
	//	- Take the attribute data-relatedProduct and use that for the AJAX command
	//  - make our Ajax Call
	//  - depending on the response change the message and the class of the object


	// Since this function is happening on click, we need to immediately change the content of the
	// item to the "adding to your wishlist..."
	ourHTMLLinkElement.innerHTML = ourInProgressMessage;
	ourHTMLLinkElement.addClassName(ourInProgressClass);

	$(ourHTMLLinkElement.parentNode).addClassName("wishListMessageWrap");
}

function displayWishlistMessage(ourHTMLLinkElement, success)
{
	var ourSuccessMessage = "Item has been added to your wishlist";
	var ourSuccessClass = "";

	var ourFailureMessage = "Could not add item to wishlist!";
	var ourFailureClass ="";

	if(success == 'true')
	{
		ourHTMLLinkElement.innerHTML = ourSuccessMessage;
		ourHTMLLinkElement.addClassName(ourSuccessClass);
	}
	else
	{
		ourHTMLLinkElement.innerHTML = ourFailureMessage;
		ourHTMLLinkElement.addClassName(ourFailureClass);
	}
}
