/*	VAIO SPECIFIC CORE FUNCTIONS
 *	AUTHOR: Branden Thompson, Branden.Thompson@am.sony.com
 *	DATE: June 27, 2008
 *
 *	FUNCTION GUIDELINES:
 *	"If it's VAIO specific, it goes here, if not, it's a seperate file"
 *
 *	- ***DOCUMENT YOUR FUNCTIONS***
 *	- PRE-CONDITION and POST-CONDITION YOUR FUNCTIONS!
*/

function footnoteDispenser(buttonID, contentDivID, messageDivID, offClass, onClass)
{
	
	// let's get all the elements by ID, AND use prototype to extend those
	// objects so we can take advantage of some methods should we need them.
	
	var ourButton = $(buttonID);
	var checkDiv = $(contentDivID);
	var ourMessage = $(messageDivID);
	
	//alert(ourButton.className + "\n" + checkDiv.className);
	
	if(ourButton.className == onClass)
	{
		// this means that the footnotes are not showing so....
		
		// set the class of the button to "minus"
		ourButton.className = offClass;
		
		// display the footnote content.
		//checkDiv.style.display = 'block'; // OLD
		$(checkDiv).toggleClassName('hidden');
		
		// change our CTA message
		ourMessage.innerHTML = 'Hide footnotes';
	}
	else	// otherwise...
	{
		// set the class of the button to "plus"
		ourButton.className = onClass;
		
		// change the CTA messsage
		ourMessage.innerHTML = 'View footnotes';
		
		// hide the footnotes (prototype shortcut)
		//checkDiv.hide(); // OLD
		$(checkDiv).toggleClassName('hidden');
	}
}


/*	FUNCTION: shadowBoxInit()
 *	----------------------------------------------------------------------------
 *	PRE-CONDITIONS:		this file must be included in the calling HTML page.
 *						
 *						shadowbox.js must also be included in the calling HTML
 *						page BEFORE this file is linked.
 *
 *	POST-CONDITIONS:	defined Shadowbox options will be initialized when this
 *						function is called.
 *	----------------------------------------------------------------------------
*/

function shadowBoxInit()
{	
	// we're simply defining our customizable options in Shadowbox.
	// this is related to Shadowbox.js	
	var options = {
		loadingImage: '/wcsstore/SonyStyleStorefrontAssetStore/img/vaioimage/ajax-loading.gif',
		onClose: function(arg) {
			var overlayDiv = document.getElementById('shadowbox_overlay');
			if(overlayDiv) {
				overlayDiv.style.height = "0px";
				}
			
			
			}
	};


	// initialize the options we just defined in the Shadowbox.
	Shadowbox.init(options);		
}// end function

/*	FUNCTION: showSeriesTab([string]theContainerID, [string] theSeriesTabID, [string] theDefaultTabID)
 *	----------------------------------------------------------------------------
 *	PRE-CONDITIONS:		this file must be included in the calling HTML page.
 *
 *						theContainerID must be a valid, defined element within
 *						the calling HTML document.
 *
 *						all potential IDs that will be called by theSeriesTab
 *						must be within theContainerID, WITH THE EXCEPTIOON OF
 *						theDefaultTabID.	
 *
 *						theSeriesTabID must be valid, defined element ID witin
 *						the HTML document.
 *
 *	POST-CONDITIONS:	showSeriesTab will be displayed, while all other elements
 *						within theContainerID will be hidden.  
 *
 *						If theDefaultTabID is also specified, this element 
 *						will also be hidden unless if happens to also be the 
 *						element called by theSeriesTabID.
 *	----------------------------------------------------------------------------			
*/
function showSeriesTab(theContainerID, theSeriesTabID, theDefaultTabID)
{
	 // let's make an element for our Tab:
	var theTabWeWant = document.getElementById(theSeriesTabID);
	var ourContainer = document.getElementById(theContainerID);

	// this is our default tab... if it's specified.
	if(theDefaultTabID)
	{	
		var theDefaultTab = document.getElementById(theDefaultTabID);
		ourContainer.style.display = "block";
		theDefaultTab.style.display = "none";
	}
	
	// let's look for our div container with all the inline DIVs with tab content:
	var ourTabContainer = document.getElementById(theContainerID);
	
	// let's also create a new variable for us to parse through this stuff:
	var ourInsideElements = ourTabContainer.getElementsByTagName('div');
	
	
	// let's look for all of our nested DIVs within the container...
	for(var i = 0; i < ourInsideElements.length; i++)
	{
		
		// ...but we only want the first level of DIVS, all of which have the class "hidden":
		if(ourInsideElements[i].className == "hidden" || ourInsideElements[i].className == "jsEnabled" )
		{
			// alert (ourInsideElements[i].id);  //- for debugging purposes.
			
			// let's reset our displays to "off"
			ourInsideElements[i].style.display = "none";
									
		}
		
	}
	
	// now let's turn our tab "on":
	ourContainer.style.display = "block";
	ourContainer.className = 'jsEnabled';
	theTabWeWant.style.display = "block";
	theTabWeWant.className = 'jsEnabled';
	}
// end function.


/*	FUNCTION: 	displayFlashHeader([string]divID, [int]width, [int]height, 
 *				[string/html]headerString, [string]alignment, [int]offsetX, 
 *				[int]offsetY, [string]objectAlign,[string]leading)
 * 	----------------------------------------------------------------------------
 *	PRE-CONDITIONS:		divID must exist and be a properly defined element 
 *						within the HTML document.
 *
 *						width, height, and headerString all MUST be defined.
 *
 *
 *	POST-CONDITIONS:	function will write the flash Object 
 *						
 *						specified and/or default variables will be passed to 
 *						the flash object so it can render headerString into a 
 *						smooth, visually appealling font.
 *	----------------------------------------------------------------------------
*/

// let's define a global variable that the function can simply re-use, rather
// than taking up more memory by using a new copy of the variable every function
// call.
var thisSWFObjectHeader;


function displayFlashHeader(divID, width, height, headerString, alignment, offsetX, offsetY, leading)
{
	// let's start our by doing some fatal-error exception alerting.
	if((!(divID)) || (!(width)) || (!(height)) ) {
		alert("FATAL ERROR - displayFlashHeader(): Required arguments are missing.  Please review the page and fix accordingly.");
		return(false);
	}	
	
	// let's perform some basic logic tests here for our non-required variables:
	
	// if alignment is not specified, default to left:
	if((!(alignment)) || (alignment == '')) {
		alignment = "lt";
	}
	
	// if offsetY is null, not-defined or blank, set to 0:
	if ((!(offsetX)) || (offsetX == '')) {
		offsetX = 0;
	}
	
	// if offsetY is null, not-defined or blank, set to 0:
	if ((!(offsetY)) || (offsetY == '')) {
		offsetY = 0;
	}	
	
	// if leading is null, not-defined or blank, set to 0:
	if ((!(leading)) || (leading == '')) {
		leading = 0;
	}	
	
	// Now that we've made sure all parameters are defined one way or another, let's define our flash Object
	
	thisSWFObjectHeader = new SWFObject("/wcsstore/SonyStyleStorefrontAssetStore/flashfiles/swfs/headerText.swf?t=" +new Date().getTime(), "hero", width, height, "8", "#FFFFFF", true);
	
	thisSWFObjectHeader.addParam("wmode", "transparent");			// this parameter makes the background of the swf object transparent
	thisSWFObjectHeader.addParam("scale", "noscale");				// do we want to have the swfObject be scalable?
	thisSWFObjectHeader.addVariable("TextHTML",headerString);		// this paramater is the text to be displayed. HTML 1.0 is supported. <font> <p> <a> <b><br>...etc. For the font face, please use 'ITC Avant Garde Std Bk' or 'ITC Avant Garde Std Md', Flash defaults to ITC Avant Garde Std Bk
	thisSWFObjectHeader.addVariable("TextAlignment", alignment);	// this paramater is the horizontal offset from the left in pixel. 	
																// If TextAlignment "right" is used. the coordinate offset will start from the right
	thisSWFObjectHeader.addVariable("OffsetX",offsetX);	
	thisSWFObjectHeader.addVariable("OffsetY",offsetY);				// this paramater is the vertical offset form the top
	thisSWFObjectHeader.addVariable("TextLeading",leading);				// this paramater is the vertical offset form the top
	thisSWFObjectHeader.addParam("salign", "lt");					// how do we want this aligned?  lt = left, rt = right.		
	thisSWFObjectHeader.write(divID); 								// write the swf file into the Div with the ID passed below:
}
// end function.






// Flash will use this function the get the pageName from the template and use that for Flash tracking
function getOmniturePageName() { if (typeof(s) == 'object') { return s.pageName; }else {return 'undefined';} };


/*
	Functions called by vaio_series_footer_popups.swf
	FooterPop Function
	Takes and ID and X Coordinate and passes 	
*/
function footerPop(ID, xcoord)
{
	//If ID is nothing, we move it out of the screen
	if (ID == "null" || ID == "undefined")	{
		ID = '';
		$('vaioFooterFlashPopups').style.left = "-2000px";
	}else{
	// If ID has anything in it, we show the movie by putting it on stage
		$('vaioFooterFlashPopups').style.left = "0px";
	}
	//Calling popup module in the flash to popup the correct Series at the given x coordinate
	thisMovie("vaioFooterFlashPopupModule").footerPopCall(ID,xcoord);
	//Calling footer with the same parameters so it knows where the other flash is at.
	thisMovie("vaioFooterFlashModule").footerPopCall(ID,xcoord);
}

/*
	Flash uses this function to locate the correct SWF movie
*/
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	}
	else {
		return document[movieName]
	}
}


 /*Function for Alternative content when Flash isn't available*/
 
 function initVaioHeroAltContent(){
	/******************************/
	//Appending Alternative content for non-flash users
	// Adding onclick event to the CTA links for Hero banners
	$$('#vaioHero a.tabs').invoke('observe','click', function(evt){
			//reads the href and  rel to pass to the function
			_cmspotObject.trackCMSOmniture($(this).href, $(this).rel);
			//Stops href from being followed
			Event.stop(evt);
	});
 }

 
 
/* function used to open and close the ESpot area for more promotions information */
function openPromotions(openVar){
/* Parameters are a boolean true or false*/
	if(openVar)
		$('vaioPromotionsFlash').style.height = '177px';
	else
		$('vaioPromotionsFlash').style.height = '40px';
}
