/*------Site Catalyst Variables----------------------------------------------------------------------------*/
    
	 	  var products_add_to_cart ="";
	 	  var products_accessory="";
	 	  var products_overview="";
  	
/*-------End Site Catalyst Variables ----------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: Product Controller
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 6/6/2008
** description: Adds Event Listners to DOM Elements. Delegates events to the approriate command function. 
***/

ProductController = {

		/* Constants */

		CONTENT_CONTAINER:"",  // Reference to the content container element
		SHOWCASE_CONTAINER:"", // Reference to the showcase container element
		ADDTOCART_CONTAINER:"", // Reference to the addtocart container element

        byPassNavExtend:false, // Bypasses navExtend functions when True

		/* Methods */

		init: function(){

			/* Set Constants */

			try {
				ProductController.CONTENT_CONTAINER = document.getElementById('content');
				ProductController.SHOWCASE_CONTAINER = document.getElementById('product_showcase');
				ProductController.ADDTOCART_CONTAINER = document.getElementById('addtocart');
			}
			catch(e){/*handles error when there is no div defined on the page*/}

			/* Global Event Listeners */

			/* CONTENT_CONTAINER */

			/* Delegate onclick events */
			ProductController.CONTENT_CONTAINER.onclick = function(e)
			{
				ProductCommands.clickEvent(e);
			}
			

			/* Delegate onmouseover events */
			ProductController.CONTENT_CONTAINER.onmouseover = function(e)
			{
				ProductCommands.mouseOverEvent(e);
			}

			/* Delegate onmouseout events */
			ProductController.CONTENT_CONTAINER.onmouseout = function(e)
			{
				ProductCommands.mouseOutEvent(e);
			}


			/* SHOWCASE_CONTAINER */
			
			try {
				ProductController.SHOWCASE_CONTAINER.onmouseover = function(e)
				{
					ProductCommands.mouseOverEvent(e);
				}
				
	
				/* Delegate onmouseout events */
				ProductController.SHOWCASE_CONTAINER.onmouseout = function(e)
				{
					ProductCommands.mouseOutEvent(e);
				}
	
				/* Delegate click events */
				
				ProductController.SHOWCASE_CONTAINER.onclick = function(e)
				{
					ProductCommands.clickEvent(e);
				}
			}
			catch(e) {}
			
			/* ADDTOCART_CONTAINER */
			
			try {
				/* Delegate onmouseover events */
				ProductController.ADDTOCART_CONTAINER.onmouseover = function(e)
				{
					ProductCommands.mouseOverEvent(e);
				}

				/* Delegate onmouseout events */
				ProductController.ADDTOCART_CONTAINER.onmouseout = function(e)
				{
					ProductCommands.mouseOutEvent(e);
				}

				/* Delegate click events */
				ProductController.ADDTOCART_CONTAINER.onclick = function(e)
				{
					ProductCommands.clickEvent(e);
				}

				/* Delegate onchange events */
				ProductController.ADDTOCART_CONTAINER.onchange = function(e)
				{
					ProductCommands.onChangeEvent(e);
				}
			}
			catch(e) {}
		},
		/* Disable all handlers. Presently used by media showcase to improve perfomance */
		disable: function()
		{
			ProductController.CONTENT_CONTAINER.onclick = null;
			ProductController.CONTENT_CONTAINER.onmouseover = null;
			ProductController.CONTENT_CONTAINER.onmouseout = null;
			ProductController.CONTENT_CONTAINER.onmousemove = null;
			ProductController.SHOWCASE_CONTAINER.onmouseover = null;
			ProductController.SHOWCASE_CONTAINER.onmouseout = null;
			ProductController.SHOWCASE_CONTAINER.onclick = null;
			ProductController.ADDTOCART_CONTAINER.onclick = null;
			ProductController.ADDTOCART_CONTAINER.onmouseout = null;
		}
}


/*--------------------------------------------------------------------------------------------------------*/

/***
** title: ProductCommands
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 6/6/2008
** description: Object contains commands that will execute functions depending upon the class or id of the element that 
** dispatched the event. Called from the FrontController.
***/




ProductCommands = {

		/* Execute onclick commands */
		clickEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t); // Add prototype methods

			/* Execute View More */
			if (t.hasClassName('view_more'))
			{
				showFeatures(t);
			}

			/* Execute Accordion List */
			if (t.hasClassName('al_open'))
			{
				AccordionList.toggleList(t);
			}

			/* Execute Media Showcase */

			if (t.hasClassName('showcase'))
			{
				MediaShowcase.open(t,e);
			}

			/* Execute product tab switch */
			if (t.up().hasClassName('tab'))
			{
				ProductTabs.onSwitchTab(t,e);
				ForeSee.run()
			}
			
			// Change the product hero when user changes the product color from the select input
			if(t.id == ('color'))
			{
				addToCartForm.changeHeroColor(t);
			}
			
			/* Execute Accessory Box */
			if(t.hasClassName('accessory_details'))
			{
				AccessoryRollover.showBox(t);
			}
			if(t.hasClassName('close'))
			{
				AccessoryRollover.closeBox(t);
			}	
			
		},

		/* Execute onmouseover commands */
		mouseOverEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t);
			/* Execute Product Color Change */
			if(t.hasClassName('colorchip'))
			{
				ProductColorChange.changeColor(t);
			}
			/* Show the media showcase rollover tip */
			if(t.hasClassName('showcase'))
			{
				ShowcaseRollover.onRollover(t);
			}
			
			if(t.hasClassName('accessory_details'))
			{
				RollOverImageSwap.rollover(t);
			}

		},

		/* Execute onmouseout commands */
		mouseOutEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t);
			if(t.hasClassName('colorchip'))
			{
				addToCartForm.changeHeroColor(t);
				ProductColorChange.resetRollover(t);
			}

			/* Hide the media showcase rollover tip */
			if(t.hasClassName('showcase'))
			{
				ShowcaseRollover.onRollout(t);
				
			}	
				
			// Change the product hero when user changes the product color from the select input
			if(t.id == ('color'))
			{
				addToCartForm.changeHeroColor(t);
			}
			
			if(t.hasClassName('accessory_details'))
			{
				RollOverImageSwap.rollout(t);
			}

		},

		/* Execute onmchange commands */
		onChangeEvent: function(e)
		{
			var t = getEventTarget(e);
			Element.extend(t);	
			
			// Change the product hero when user changes the product color from the select input
			if(t.id == ('color'))
			{
				addToCartForm.changeHeroColor(t);
			}

		}
}


/****** The following function checks to see what the default tab is, checks a variable on the page to see if the whole content div for that area is loaded, and then calls a function to display the content area. ******/

// When a page is loaded, if querystring object is undefined, set the overview tab to show. Otherwise use the querystring to determine which tab to show.

var tabLoaded = new Array();

tabLoaded["content_products"] = false;
tabLoaded["overview_content"] = false;
tabLoaded["inthebox_content"] = false;
tabLoaded["details_manuals_content"] = false;
tabLoaded["accessories_content"] = false;
tabLoaded["reviews_content"] = false;
tabLoaded["content_products"] = false;

ProductTabs = {
	
	sDisplayTab: "",
	sDefaultTab: "",
	
	getDefaultTab: function()
	{
		ProductTabs.sDefaultTab = window.location.querystring['tab']; // Get the querystring data

		if(ProductTabs.sDefaultTab == undefined) {
			ProductTabs.sDefaultTab = 'overview_content';
		}
	},
	
	onDefaultTabLoaded: function(tabName)
	{
		if(tabName == ProductTabs.sDefaultTab) {
			$(ProductTabs.sDefaultTab).className = 'show';
			var sImageClass = $(ProductTabs.sDefaultTab).id.gsub('content','img');
			var sImageName = $(ProductTabs.sDefaultTab).id.gsub('_content','');
			$(sImageClass).src = '/assets/images/navigation/product_tabs/tab_' + sImageName + '_over.gif';
			$(sImageClass).className = 'show';
			navExtend(ProductTabs.sDefaultTab);
		}
		if(tabLoaded[ProductTabs.sDefaultTab] == true) {
			for(var item in tabLoaded) {
				if((tabLoaded[item] == true) && (item != ProductTabs.sDefaultTab)) {
					var sImageClass = $(item).id.gsub('content','img');
					var sImageName = $(item).id.gsub('_content','');
					$(sImageClass).src = '/assets/images/navigation/product_tabs/tab_' + sImageName + '.gif';
					$(sImageClass).className = 'show';
				}
			}
		}
		
		// Fire SiteCatalyst event
		var sDefaultTab = window.location.querystring['tab'] == undefined ? "overview" : window.location.querystring['tab'];
		var tPageId = sPageID.replace(':Index','');
		
		if(s.pageName != tPageId + ':' + sDefaultTab){
			s.pageName=tPageId + ':' + sDefaultTab.capitalize();
			
			if(products_add_to_cart!=''){
				s.products = products_add_to_cart;
			}
			 
			if(products_accessory!='' && sDefaultTab=='accessories'){
				s.products = s.products +','+ products_accessory;
			}
			 
			if(products_overview!='' && sDefaultTab=='overview'){
				s.products = s.products + ',' + products_overview;
			}
			
			s.products = s.products.split(sPageID).join(s.pageName);
			s.events="prodView,event11";
		 }
	},
	
	onSwitchTab: function(t,e) {
		// Define image elements respresenting tabs
            var sTabImage = t;
			
		// Loop through and set all tab images to non-clicked state
		for(var item in tabLoaded) {
			if(tabLoaded[item] == true) {
				var sImageClass = $(item).id.gsub('content','img');
				var sImageName = $(item).id.gsub('_content','');
				$(sImageClass).src = '/assets/images/navigation/product_tabs/tab_' + sImageName + '.gif';
				$(sImageClass).className = 'show';
			}
		}
		        
        // Change the tab that was click on to be the selected state
        if(sTabImage.src.include('_over.gif') == false) {                    
            sTabImage.src = sTabImage.src.sub('.gif','') + '_over.gif';
        }
        
        // Define divs containing tab content
        var aTabName = t.up().id;  
        var aSections = $('content_products').childElements();
        
        // Loop through and hide all divs
        for(n=0; n<aSections.length; n++) {
            $(aSections[n]).className = 'hide';
        }
        
        // Display the tabbed content that was clicked on
        for(n=0; n<aSections.length; n++) {
            if(aSections[n].id.include(aTabName) == true) {
                $(aSections[n]).className = 'show';
                navExtend(aSections[n].id); // Since the height of the content may change, need to re-run the navExtend() function.
                break;
            }
        }
		
		// Run the SiteCatalyst page view code - on load of the tab	
		var tPageId = sPageID.replace(':Index','');

		if(s.pageName != tPageId + ':' + aTabName){
			s.pageName=tPageId + ':' + aTabName.capitalize();

			if(products_add_to_cart!=''){
				s.products = products_add_to_cart;
			}

			if(products_accessory!='' && aTabName=='accessories'){
				s.products = s.products +','+ products_accessory;
			}

			if(products_overview!='' && aTabName=='overview'){
				s.products = s.products + ',' + products_overview;
			}

			s.products = s.products.split(sPageID).join(s.pageName);
			s.events="prodView,event11";

			s.doPlugins=s_doPlugins;
			var s_code=s.t();
		}
		// Live Person block - sends aTabName to Live Person using sendData() function in echat.js DAC 6/24/2009
                if (typeof(eChatSendData.sendData) === 'function') // Make sure that eChat.js is loaded
                {
                  eChatSendData.sendData('session','ClickAction',aTabName);
                }
                // End of Live Person block		
	}
}

//ProductTabs.getDefaultTab();

/*--------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: Showcase Rollover
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 7/1/2008
** description: Displays showcase text on rollover, hides text on rollout
***/

ShowcaseRollover = {

	showcaseRolloverOffsetX:0,
	showcaseRolloverOffsetY:0,
	showcaseCompensateRollovers:false,
	showcaseCompensateOffsetX:0,

	onRollover: function(t)

	{
		$('rollover_content').childElements().each(function(el){
			if (el.hasClassName(t.className.substr(t.className.lastIndexOf(" ")+1)))
			{
				if (ShowcaseRollover.showcaseCompensateRollovers == true)
				{
					//alert(getElementPosition(t).left+","+getElementPosition(t).top);
					switch (t.className.substr(t.className.lastIndexOf(" ")))
					{
						case " s360":
						{
							el.childElements()[0].className = "img_head_s360";
							ShowcaseRollover.showcaseCompensateOffsetX = -10;
							break;
						}
						case " sPhotos":
						{
							el.childElements()[0].className = "img_head_sPhotos";
							ShowcaseRollover.showcaseCompensateOffsetX = -65;
							break;
						}
						case " sVideos":
						{
							el.childElements()[0].className = "img_head_sVideos";
							ShowcaseRollover.showcaseCompensateOffsetX = -129;
							break;
						}
					}
				}
				var pos = getElementPosition(t);
				el.style.top = (pos.top + 20 + ShowcaseRollover.showcaseRolloverOffsetY) + "px";
				el.style.left = (pos.left - 7 + ShowcaseRollover.showcaseRolloverOffsetX + ShowcaseRollover.showcaseCompensateOffsetX) + "px";
				el.style.visibility = 'visible';
			}
		});
		//alert(getElementPosition(t).top + " " + getElementPosition(t).left);
		//alert(t.className.substr(t.className.lastIndexOf(" ")));
	},
	onRollout: function(t)
	{
	$('rollover_content').childElements().each(function(el){
			el.style.visibility = 'hidden';
		});
	}

}


/*--------------------------------------------------------------------------------------------------------*/

/***
** title: getSelectedTabName
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0, tabLoaded Array
** last updated: 11/10/2008
** description: Return the name of the selected tab as a string. Used for tracking
***/


function getSelectedTabName()
{
	for(var item in tabLoaded)
	{
		if(tabLoaded[item] == true) {
			var sImageID = $(item).id.replace('content','img');
			var chkImage = $(sImageID);
			if(chkImage.src.indexOf('_over.')>0)
			{
				return sImageID.replace("_img","");
			}
		}
	}
}

/*--------------------------------------------------------------------------------------------------------*/


/***
** title: initCapUnderscoreToSpace
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0, tabLoaded Array
** last updated: 11/11/2008
** description: takes a string as an argument and returns the string with initial caps and underscores replaced with spaces.
** used in the SC tracking request sent on open of the media showcase app.
***/

function initCapUnderscoreToSpace(newStr)
{
	var myArraySplit = newStr.split("_");
	newStr = "";
	for (i = 0; i<myArraySplit.length; i++)
	{	
		// init cap only if lowercase alphabet char
		if ( myArraySplit[i].charCodeAt(0) > 96 && myArraySplit[i].charCodeAt(0) < 123 )
		{
			newStr += (String.fromCharCode(myArraySplit[i].charCodeAt(0)-32)+myArraySplit[i].slice(1))+" ";
		} 
		else
		{
			newStr += myArraySplit[i]+" ";
		}
	} 
	return newStr.slice(0,newStr.length-1);
}


/*--------------------------------------------------------------------------------------------------------*/

/***
** title: MediaShowcase
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 9/11/2008
** description: Open Lightwindow with media showcase
***/

/* add required support files */

	document.write('<script src="/js/swfobject.js" language="javascript"></script>');	


MediaShowcase = {

	windowWidth: "",
	windowHeight: "",
	contentWidth: 927,
	contentHeight: 609,
	margin: 10,
    lang: "",
	defaultLang: "en-us",
    	// Set default value of Live Person variable FlashDemoActive status to false. 
    	// Value of FlashDemo Active is reset in the open()/close() functions.	
        lpFlashDemoActive:false,
	init: function()
	{
		// Detect language Cookie
		MediaShowcase.lang = getCookie("langsel")

		// Map to 4 char lang code. Default to en-us if undefined. 
		switch(MediaShowcase.lang)
		{
			case "FR":
			MediaShowcase.lang = "fr-ca";
			break;
			case "FR-CA":
			MediaShowcase.lang = "fr-ca";
			break;
			case "fr-ca":
			MediaShowcase.lang = "fr-ca";
			break;
			case "EN":
			MediaShowcase.lang = "en-us";
			break;
			case "EN-US":
			MediaShowcase.lang = "en-us";
			break;
			case "en-us":
			MediaShowcase.lang = "en-us";
			break;
			default: 
			MediaShowcase.lang = MediaShowcase.defaultLang;
			break;
		}

		// Show the showcase buttons /
		$$('img.showcase').each(function(s) {   s.style.visibility = 'visible' }); 
	},

	open: function(t,e)
	{
		/* Added try to handle errors if content has not loaded */
		try{
		if($('mediaShowCase'))
			{
			var path = "";
			var msType = "";
			if (t.hasClassName('s360'))
			{
					path = media360_url;
					msType = "360";

			} else if (t.hasClassName('sPhotos'))
			{

					path = photos_url;
					msType = "Photos";

			}else if (t.hasClassName('sVideos'))
			{
					path = video_url;
					msType = "Videos";
			}

			
			if (ProductController.byPassNavExtend == false)
			{
				if (ProductLabel)
				{
					// Send a SiteCatalyst image request with the new page view
		
					s.pageName = "MS:"+initCapUnderscoreToSpace(ProductLabel)+":"+msType+":"+initCapUnderscoreToSpace(getSelectedTabName())+":Index";
					s.doPlugins=s_doPlugins;
					var s_code=s.t();
				}
			}


		
			// Kill the event listners to improve performance.
			ProductController.disable();
			GlobalController.disable();

			// get the window dimensions
			MediaShowcase.windowWidth = getWindowDimensions().w;
			MediaShowcase.windowHeight = getWindowDimensions().h
			
			// get the body element
			var msBody = $(document.body);


			// Calculate Page Height
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = document.body.scrollWidth;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ 
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { 
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}

			var oHeight = msBody.clientHeight;

			var oHeight = yScroll;
			var oWidth = xScroll;

			if (xScroll < screen.availWidth)
			{
				oWidth = screen.availWidth;
			}
			if (yScroll < msBody.clientHeight)
			{
				oHeight = msBody.clientHeight
			}

			// Position the window
			
			var msTop = MediaShowcase.margin;
			var msLeft = MediaShowcase.margin; 
			if (MediaShowcase.windowWidth > (MediaShowcase.contentWidth+(MediaShowcase.margin*2)))
			{
				msLeft = (MediaShowcase.windowWidth - MediaShowcase.contentWidth)*0.5;
			}

			if (MediaShowcase.windowHeight > (MediaShowcase.contentHeight+(MediaShowcase.margin*2)))
			{
				msTop = (MediaShowcase.windowHeight - MediaShowcase.contentHeight)*0.5;
			}

			// hide all the selects so they don't overlap the overlay
			var selects = document.getElementsByTagName('select');

			for(var i = 0; i < selects.length; i++) {
				selects[i].style.visibility = 'hidden';
			}

			// get the new elements
			var msOverlay = $('msOpacityOverlay');
			var msShowcase = $('mediaShowCase');

			// Show the overlay
			msOverlay.style.width = oWidth+'px';
			msOverlay.style.height = oHeight+'px';
			msOverlay.style.visibility = 'visible';
			
			// Show the flash content
			msShowcase.style.top = msTop+'px';
			msShowcase.style.left = msLeft+'px';
			msShowcase.style.visibility = 'visible';

			// Load the Flash 
			var flashContent = {};    

			// substring(1) to remove the '?'   
			var pairs = path.substring(1).split("&");   
			var splitPair;   
		  
			// Load the key/values of the return collection   
			for (var i = 0; i < pairs.length; i++) {   
				splitPair = pairs[i].split("=");   
				flashContent[splitPair[0]] = splitPair[1];   
			}
			// Swap the default language extension with the detected cookie language

			flashContent["source"] = flashContent["source"].replace(MediaShowcase.defaultLang,MediaShowcase.lang);
			// Used to test app on Mozilla browsers in the teamsite environment. Leave blank at all other times.
			var hostLocation = ""; //"http://"+window.location.host+window.location.pathname+"?url=";
		
			var checkFlashPlayer = new deconcept.SWFObjectUtil.getPlayerVersion();
			var requiredFlashPlayer = new deconcept.PlayerVersion([9,0,103]); // Enter required version of flash here. Use array format [major,minor,revision].
			if (checkFlashPlayer.versionIsValid(requiredFlashPlayer)){
			
					var so = new SWFObject("/assets/flash/media_showcase/mediaShowcase.swf", "mainflash", MediaShowcase.contentWidth, MediaShowcase.contentHeight, "9,0,124");
					so.addParam("quality", "high");
					so.addParam("align", "middle");
					so.addParam("salign", "");
					so.addParam("loop", "false");
					so.addParam("scale", "showall");
					so.addParam("devicefont", "false");
					so.addParam("menu", "true");
					so.addParam("allowFullScreen", "false");
					so.addParam("allowScriptAccess","sameDomain");
					so.addParam("FlashVars", "initView="+flashContent["action"]+"&appXML=./assets/flash/media_showcase/data/media_showcase_app_"+MediaShowcase.lang+".xml&productXML=."+flashContent["source"]+"&hostLoc="+hostLocation+"&trackingSuite="+s.fun+"&trackingHost=metrics.bose.com");
					so.write("mediaShowCase");
				}
				else
				{
					var altHTML = '<div id="altContent" style="position:relative;text-align:center"><p>You need the latest Flash Player to view this content. <a href="http://www.adobe.com/go/getflash/" target="_blank">Install Adobe Flash Player</a>.</p><p><a style="text-decoration:none;" href="javascript:MediaShowcase.close()">Close &raquo;</a></p></div>';

					var cAlt = $("mediaShowCase");

					cAlt.style.background = "#000000";
				
					cAlt.innerHTML = altHTML;

					var altContent = cAlt.down(0);

					altContent.style.top = '300px';

				}
				
                        // Send FlashDemoActive status to Live Person using sendData() function in echat.js 
                        // FlashDemoActive is set to true here.	DAC 6/24/2009
                        MediaShowcase.lpFlashDemoActive = true;
                        if (typeof(eChatSendData.sendData) === 'function') // Make sure that eChat.js is loaded
                        {
                          eChatSendData.sendData('session','FlashDemoActive',MediaShowcase.lpFlashDemoActive);              
                        }				

			// Add listener to close the Media showcase if the user clicks outside the showcase area

			$('msInnerWrap').onclick = function(e)
			{
				MediaShowcase.close();
			}

			// Hide any rollover

			$('rollover_content').childElements().each(function(el){
				el.style.visibility = 'hidden';
			});
			} // end conditional
	} catch(e){
	
		//alert(e.message);
	};






	},
	close: function()
	{
		// remove the elements
		var msOverlay = $('msOpacityOverlay').style.visibility = 'hidden';
		var msShowcase = $('mediaShowCase');
		msShowcase.style.visibility = 'hidden';
		msShowcase.innerHTML = "";

		// show all the selects that were hidden
		var selects = document.getElementsByTagName('select');
		for(var i = 0; i < selects.length; i++) {
			selects[i].style.visibility = 'visible';
		}

		/* Enable the page listeners */
		ProductController.init();
		GlobalController.init();
		//myLightWindow.deactivate();

                // Send FlashDemoActive status to Live Person using sendData() function in echat.js 
                // FlashDemoActive is set to false here. DAC 6/24/2009
                MediaShowcase.lpFlashDemoActive = false;          
                if (typeof(eChatSendData.sendData) === 'function') // Make sure that eChat.js is loaded
                {
                  eChatSendData.sendData('session','FlashDemoActive',MediaShowcase.lpFlashDemoActive);              
                }		
	}

}

/* Call function rather then method to fix Flex External Interface Error when calling a js object method */

function closeMediaShowcase()
{
	var t=setTimeout('MediaShowcase.close()',250);
}

/*--------------------------------------------------------------------------------------------------------*/


/***
** title: Product Color Change
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 9/17/2008
** description: Change the product color when the user rolls over a color chip.
***/


var ProductColorChange =
{

	// Vars
	colorChips:"",
	productHero:"",
	productColors: new Array(),
	targetColor:"",

	productHeroImgEnd:"_lg.jpg",

	// Methods
	init: function()
	{
		try {
            ProductColorChange.colorChips = $('colors').childElements();
    		ProductColorChange.productHero = $('product_hero');
    		var ipath = ProductColorChange.colorChips[0].down(1).src;
    		ProductColorChange.targetColor = ipath.slice(ipath.lastIndexOf('_'),ipath.lastIndexOf('.'));
    		
    		//Pre Load the different product colors
    		
    		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
    			ProductColorChange.productColors[i] = new Image();
    			var path = ProductColorChange.colorChips[i].down(1).src;
    			var color = path.slice(path.lastIndexOf('_'),path.lastIndexOf('.'));
    			ProductColorChange.productColors[i].src = '/assets/images/shop_online/' + ProductLabel + '/' + ProductLabel + color + ProductColorChange.productHeroImgEnd;
    		}
			
			// set the first chip as selected
			var cImg = ProductColorChange.colorChips[0].down(1);
			sExt = getFileExt(cImg);
			cImg.src = cImg.src.sub('.' + sExt,'_over.' + sExt);
		}
        catch(e){/*handles error when there is no color change on a product*/}
	},

	changeColor: function(t)
	{
		// First, set all colorchips on the page to their default state
		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
			var cImg = ProductColorChange.colorChips[i].down(1);
			cImg.src = cImg.src.sub('_over.','.');
		}

		// Now, flip the colorchip that is currently being moused over to its selected state
		sExt = getFileExt(t);
		t.src = t.src.sub('.' + sExt,'_over.' + sExt);

		// Swap in the new hero image
		var path = t.src.sub(t.src.slice(t.src.lastIndexOf('_'),t.src.lastIndexOf('.')),'');
		var color = path.slice(path.lastIndexOf('_'),path.lastIndexOf('.'));
		ProductColorChange.productHero.src = '/assets/images/shop_online/' + ProductLabel + '/' + ProductLabel + color + ProductColorChange.productHeroImgEnd;
		ProductColorChange.targetColor = color;
	},

	resetRollover: function(t)
	{

		// First, set all colorchips on the page to their default state
		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
			var cImg = ProductColorChange.colorChips[i].down(1);
			cImg.src = cImg.src.sub('_over.','.');
		}

		// get the selected color
		var dropdownColor = $('color').value;

		// reset the color chip to the selected color
		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
			var cImg = ProductColorChange.colorChips[i].down(1);
			if (cImg.src.search("_"+dropdownColor+".")!= -1)
			{
				sExt = getFileExt(cImg);
				cImg.src = cImg.src.sub('.' + sExt,'_over.' + sExt);
			}
			
		}

	}

}

/*--------------------------------------------------------------------------------------------------------*/


/***
** title: Product Hero Image and Add to Cart color dropdown synch
** author: Dan DeRose
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 9/17/2008
** description: Changes the color on the Product Hero image to match whatever is selected in the Add to Cart color dropdown
***/

addToCartForm = {

	changeHeroColor: function(t)

	{
		var dropdownColor = $('color');
		//alert(dropdownColor.value);
		$('product_hero').src = $('product_hero').src.substr(0, $('product_hero').src.length-9) + dropdownColor.value + ProductColorChange.productHeroImgEnd;

		// First, set all colorchips on the page to their default state
		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
			var cImg = ProductColorChange.colorChips[i].down(1);
			cImg.src = cImg.src.sub('_over.','.');
		}

		// get the selected color
		var dropdownColor = $('color').value;

		// reset the color chip to the selected color
		for(i=0;i<ProductColorChange.colorChips.length-1;i++) {
			var cImg = ProductColorChange.colorChips[i].down(1);
			if (cImg.src.search("_"+dropdownColor+".")!= -1)
			{
				sExt = getFileExt(cImg);
				cImg.src = cImg.src.sub('.' + sExt,'_over.' + sExt);
			}
			
		}
	}
}

/*--------------------------------------------------------------------------------------------------------*/

/***
** title: View More Script
** author: Dan DeRose
** company: Bose Corporation
** requires: scriptaculous 1.7.0, Prototype 1.5.0
** last updated: 5/26/2008
** description: Cycles through all images with a class of view_more and shows/hides the content in a div places directly under the image in the html
***/


function showFeatures(t) {
    var name = t.up(1).previousSiblings()
    
    if(t.src.include('button_view_more.gif') == true) {
        t.src = '/assets/images/global/button_view_less.gif';
		t.alt = 'Minimize';
        name[0].style.display = 'block';
		if (ProductController.byPassNavExtend == false) navExtend(t.up(2).id);
		
		// Fire SiteCatalyst event
		var tempPageName = s.pageName;
		s.prop13 = tempPageName;
		var aString = tempPageName.split(':');
		var iLength = aString.length;
		s.tl(this,'o','view more:' + aString[iLength-2]);
    }
    else {
        t.src = '/assets/images/global/button_view_more.gif';
		t.alt = 'More info';
        name[0].style.display = 'none';
		
		if (ProductController.byPassNavExtend == false) navExtend(t.up(2).id);
		
		// Fire SiteCatalyst event
		var tempPageName = s.pageName;
		s.prop14 = tempPageName;
		var aString = tempPageName.split(':');
		var iLength = aString.length;
		s.tl(this,'o','minimize:' + aString[iLength-2]);
    }
}

/*--------------------------------------------------------------------------------------------------------*/

/*
title: BeKK Accordion List
author: Isaac Chellin, modified for PEP by Dan DeRose
company: Bose Corporation
requires: scriptaculous 1.7.0, 1.5.0
last updated: 8/29/2007
*/

var AccordionList = {
	
	//vars
	
	toOpen: "",
	toClose: "",
	i: 1,

	// methods

	init: function() {
	
		document.getElementsByClassName('accordion_list').each(function(al) { 

			al.id = 'al_list'+AccordionList.i; // assign a unique id to each element
			AccordionList.i++;
			
			document.getElementsByClassName('al_body',al).each(function(ab){ ab.hide(); });

			al.setStyle({ visibility: 'visible' }); 

		});
		
	},

	toggleList: function(target)
	{
			var ah = target.up();
            var ap = ah.up(0);
			var ab = ah.next();
			var pb = AccordionList.toClose;
			AccordionList.toOpen = ab;
            
			if (pb && (ab != pb))
			{
				ah.down().addClassName('open');
				pb.previous().down().removeClassName('open');
				pb.previous().down().next().show();
                ap.style.background = '#ffffff';
                pb.up().style.background = '#f8f8f8';
				if (pb.visible())
				{
					AccordionList.toggleImage(pb.previous());
				}
				
				Effect.BlindUp(pb, {duration:0.2, afterFinish: AccordionList.onBlindFinish } );
			}
			else 
			{
				if (ah.down().hasClassName('open')){
					ah.down().removeClassName('open');
					ah.down().next().show();
                    pb.up().style.background = '#f8f8f8';
				}
				else {
					ah.down().addClassName('open');
                    ap.style.background = '#ffffff';
				}
				Effect.toggle(ab,'blind',{duration:0.2});
				
			}
			AccordionList.toClose = ab;

			AccordionList.toggleImage(ah);
	},
	
	toggleImage: function(ah){
		if(ah.down().src.include('plus') == true) {
			    ah.down().src = '/assets/images/global/icon_faq_minus.gif';
            }
		else {
			ah.down().src = '/assets/images/global/icon_faq_plus.gif';
			// Fire SiteCatalyst event - Only when a FAQ is selected; not when one is closed
			/*var tempPageName = s.pageName;
			s.prop15 = tempPageName;
			s.tl(this,'o','view more');
			s.pageName = tempPageName;*/
		}
	},
	onBlindFinish: function(obj) {
		Effect.BlindDown(AccordionList.toOpen,{duration:0.2});
	}

}

/***
** title: Accessory Rollover
** author: Isaac Chellin
** company: Bose Corporation
** requires: Prototype 1.5.0
** last updated: 09/23/08
** description: Add details rollover for all divs with the class product_accessory
***/

AccessoryRollover = {
		showBox: function(t)
		{
			var sAccessoryDiv = t.up(1).previous(1);

			// Get all divs with the accessory_rollover class and put them in an array
			var aAccessoryBoxes = $$('div.accessory_rollover'); 
			
			// Now, loop through all accessory moduels and make sure the details content is hidden and the containers (product_accessory) all have position:relative
			for(i=0;i<aAccessoryBoxes.length;i++) {
				aAccessoryBoxes[i].hide();
				aAccessoryBoxes[i].up().style.position = 'relative';
			}
			
			try {
				t.up(2).next().style.position = 'static'; // Sets the next product_accessory div to static to avoid IE bug with z-index
				t.up(2).next(3).style.position = 'static'; // If this is the last accssory in a section, this will target the next product_accessory div, skipping over a couple other for the section divider
				} catch(e) {}
				sAccessoryDiv.style.visibility = 'hidden';
				sAccessoryDiv.style.display = 'block';
			
			// Ie6 hack to deal with select elements and z-index problems
			 var is_ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
			 if (is_ie6)
			{
				// Finally, open the selected accessory box and set the div underneath to static so there are no z-index issues in IE; it will be reset to relative every time another details link is clicked on
				try {
					t.up(2).next().style.position = 'static'; // Sets the next product_accessory div to static to avoid IE bug with z-index
					t.up(2).next(3).style.position = 'static'; // If this is the last accssory in a section, this will target the next product_accessory div, skipping over a couple other for the section divider
				} catch(e) {}
				sAccessoryDiv.style.visibility = 'hidden';
				sAccessoryDiv.style.display = 'block';
				// Add iframe to hide the select
			    var html =
				"<iframe style=\"position: absolute; display: block; " +
				"z-index: -1; width: "+sAccessoryDiv.offsetWidth+"px; height: "+sAccessoryDiv.offsetHeight+"px; top: 0; left: 0;" +
				"filter: mask(); background-color: #FFFFFF; \"></iframe>";
				if (sAccessoryDiv) sAccessoryDiv.innerHTML += html;
				// force refresh of div
				var olddisplay = sAccessoryDiv.style.display;
				sAccessoryDiv.style.display = 'none';
				sAccessoryDiv.style.display = olddisplay;
				// show the div
			};
			sAccessoryDiv.style.visibility = 'visible';
			
			/*for(i=0;i<aAccessoryBoxes.length;i++) {
				aAccessoryBoxes[i].up().style.position = 'static';
			}
			t.up(2).style.position = 'relative';*/
			
			/* Fire SiteCatalyst event. This one is a little tricky because the requirement is not just to track the event, but to also track which accessory rollover box was revealed (by accessory name). To do this, I navigated up to the parent div containing that accessory, then navigate down to the acccessory_info div inside, which always starts with the Web Display name of the accessory. Since the structure of the html is very controlled and doesn't change, I can do this. So, I navigate down to the H4 tag containing the Web Display Name, grab the content inside the H4 tag using innerHTML and then strip any html tags that may be still inside. Lastly, I replace all non alpha-numeric characters with a space to get rid of things like trademark or registered symbols. EDIT 09/01/08 - They no longer want the Web Display Name, but I'm leaving the code in just in case they change their minds. */
			/* var tempPageName = s.pageName;
			var sWebDisplayName = t.up(2).childElements();
			sWebDisplayName = sWebDisplayName[0].down(1).innerHTML.stripTags().replace(/\W+/g," ");
			s.prop14 = tempPageName;
			s.tl(this,'o','Accessory Detail Rollover');
			s.pageName = tempPageName;*/
		},
		
		closeBox: function(t)
		{
			// Hide the div
			t.up().style.visibility = 'hidden';
		}
};

/***
** title: setAccessoryATPMessage
** author: Clark Bilawchuk
** company: Bose Corporation
** requires: 
** last updated: 09-23-08
** description: used for all add to cart modules and accessory xsl module, on product page and accessory hub
***/
function setAccessoryATPMessage(form, message, allocdiv, add_to_cart_button){

	var messageElements = message.split('|') ;

	if(message==''){
		messageElements="|||".split('|') ;
	}
	var element;
	var productName;

	for (var i=0; i < form.elements.length; i++) {
	  element = form.elements[i];
	  if (element.id=='colorvariant'){
		element.value=messageElements[2];
	   }
	   if (element.id=='product'){
		productName=element.value ;
	   }
	  
	}

	element = document.getElementById(allocdiv)
	element.innerHTML=messageElements[0];

	element = document.getElementById(add_to_cart_button);

	if(messageElements[3]!='' && messageElements[3]!='undefined' && messageElements[3]=='X'){
		element.disabled=true;
		element.src="/assets/images/global/button_addtocart_small_disabled.gif";

	}else{
		element.disabled=false;
		element.src="/assets/images/global/button_addtocart_small.gif";
	}
}
/***
** title: submitAccessoryForm
** author: Clark Bilawchuk
** company: Bose Corporation
** requires: 
** last updated: 09-23-08
** description: used for all add to cart modules and accessory xsl module, on product page and accessory hub
***/
function submitAccessoryForm(formObject){
	formObject.submit;
}

new PeriodicalExecuter( function(products_pe) {  
	try{
	if ($(ProductTabs.sDefaultTab)){		
		products_pe.stop();
		ProductController.init();
		ProductColorChange.init();
		AccordionList.init();
		MediaShowcase.init();
    }
	else if($('footer')) {
		products_pe.stop();
		ProductController.init();
		ProductColorChange.init();
		AccordionList.init();
		navExtend(sContentArea); //sContentArea is set inline in the accessory product and accessory hub pages
	}

	}catch(e){};
}, .1);















