﻿

/// <reference path="../../../../jQuery/1.3.2/jquery-1.3.2-vsdoc.js" />


/**
 *****************************************************************
 * CoreAssetConfiguration
 *****************************************************************
 *
 * General display asset configuration
 *
 * Encapsulated assets configuration and post-page-load STYLING (common and page specific)
 *
 * Author : Liam Prescott
 */


	//Check that namespace into which the Class definition will be creates has been defined & if not then create
	if (!mrm.global.isNamespaceDefined("mrm.lexus.display")) mrm.global.createNamespace("mrm.lexus.display", "1.0");
	
	
	mrm.lexus.display.CoreAssetConfiguration = Object.subClass(
		{
			/*
			 =============================
			 CONSTANTS
			 =============================
			 */
				CLASS_AUTO_CONFIGURATION_BUTTONS : "auto-configured-sifr-button",
				CLASS_AUTO_CONFIGURATION_BUTTONS_LIGHTBOX : "auto-configured-sifr-button-lightbox",
				
				JQ_CLASS_PATH_UI_LIGHTBOX_CONTENT : "div.ui-lightbox-container > div.ui-lightbox-body > div.ui-lightbox-content",
				
			
			/*
			 =============================
			 CONFIGURATION PROPERTIES (instance configuration)
			 =============================
			 */
				instanceString : undefined,
			
			
			
			/*
			 =============================
			 CONSTRUCTOR
			 =============================
			 */
				init : function (instanceReferenceString)
				{
					this.instanceString = instanceReferenceString;
					
					var __this = this;
					
					
					// CONFIGURE BUTTON FUNCTIONALITY
//
// [ sIFR buttons ]
//					this.autoActivateSifrButtons();
//					this.autoActivateSifrLightboxButtons();
					this.autoActivateButtons();
					this.autoActivateLightboxButtons();
										
					// STYLE BUTTONS
					//sIFR.runDelayedStyling(sIFR.styles.STYLE_BUTTONS_STANDARD);
				
				
					//
					//
					// TODO ::
					//
					// NEED TO MAKE THESE TEST IF PAGE VALID BEFORE ATTEMPTING TO RUN
					//
					//
					
					
					// STYLE ADVANCED SEARCH PANEL
					if (sIFR.runDelayedStyling) sIFR.runDelayedStyling(sIFR.styles.STYLE_ADVANCED_SEARCH);
				
					
					// STYLE SEARCH RESULTS
					//if (sIFR.runDelayedStyling) sIFR.runDelayedStyling(sIFR.styles.STYLE_SEARCH_RESULTS_LIST_MODE);
					
					
					
					// BIND LIGHTBOX LOAD COMPLETE EVENT HANDLER : To style internal assets
					$(document).bind("LIGHTBOX-LOAD-COMPLETE", function (e)
					{
						__this.handleLightBoxOpen(e);
					});
					
					
					
					
				},
				
					
			
						
			
			/*
			 =============================
			 INTERNAL METHODS
			 =============================
			 */
				/*
				 =============================
				 SETUP
				 =============================
				 */
					/*
					 =============================
					 SIFR BUTTON ACTIVATION METHODS
					 =============================
					 */
//						
// [ sIFR button ] activation
//						autoActivateSifrButtons : function ()
						autoActivateButtons : function ()
						{
							var __this = this;
												
							var buttons = $("div." + this.CLASS_AUTO_CONFIGURATION_BUTTONS);
							
							buttons.each
							(
								function (i) 
								{
									var ___this = $(this);
									var link	= ___this.find(sIFR.styles.DEFAULT_BUTTON_STYLE_TARGET_STRING_INTERNAL_PATH + " a");
									
									var href = link.attr("href");

									link.removeAttr("href"); // [ UPDATE : non sIFR buttons ]
//
// [ sIFR button ] activation
//									
//									// Remove href attribute if !ie
//									if (!$.browser.msie)
//									{
//										link.attr("href", "");
//									}
									
									// Attach click event to button
									___this.click
									(
										function (e) {
											__this.loadNewUrl(href);
										}
									);
								}
							)
							
//
// [ sIFR button ] styling
//							// Style buttons
//							if (buttons.length > 0)
//								sIFR.runDelayedButtonStyling("div." + this.CLASS_AUTO_CONFIGURATION_BUTTONS + " " + sIFR.styles.DEFAULT_BUTTON_STYLE_TARGET_STRING_INTERNAL_PATH);
						},
						

//						
// [ sIFR button ] activation
//						autoActivateSifrLightboxButtons : function ()
						autoActivateLightboxButtons : function ()
						{
							var __this = this;
							
							var buttons = $("div." + this.CLASS_AUTO_CONFIGURATION_BUTTONS_LIGHTBOX);
							
							//var hrefFragment = "javascript:" + this.instanceString + ".launchLightBox("
							
							buttons.each
							(
								function (i) 
								{
									var ___this = $(this);
									
									var link = ___this.find(sIFR.styles.DEFAULT_BUTTON_STYLE_TARGET_STRING_INTERNAL_PATH + " a");
									
									var href = link.attr("href");
									
									link.removeAttr("href"); // [ UPDATE : non sIFR buttons ]
									
//
// [ sIFR button ] activation
//
//									// Remove href attribute if !ie
//									if (!$.browser.msie)
//									{
//										link.attr("href", "");
//									}
//									else
//									{
//										var newHref = hrefFragment + "'" + String(href) + "');";
//										
//										link.attr("href", newHref);
//									}
									
									// Attach click event to button
									___this.click
									(
										function (e) {
											__this.launchLightBox(href);
										}
									);
								}
							)
		
//
// [ sIFR button ] styling
//							// Style buttons
//							if (buttons.length > 0)
//								sIFR.runDelayedButtonStyling("div." + this.CLASS_AUTO_CONFIGURATION_BUTTONS_LIGHTBOX + " " + sIFR.styles.DEFAULT_BUTTON_STYLE_TARGET_STRING_INTERNAL_PATH);
							
						},
					
					
					
						loadNewUrl : function (url)
						{
							if (url)
								window.location.href = url;
						},
						
						
						
						launchLightBox : function (url)
						{
							if (url)
								uiBox_Trigger(url);
						},
				
				
				/*
				 =============================
				 INTERNAL EVENT HANDLERS
				 =============================
				 */
					 /*
					 =============================
					 LIGHTBOX
					 =============================
					 */
						handleLightBoxOpen : function (e)
						{
							var styleTarget = (e.targetContainerId != undefined) ? ("#" + e.targetContainerId + " " + this.JQ_CLASS_PATH_UI_LIGHTBOX_CONTENT) : ("body " + this.JQ_CLASS_PATH_UI_LIGHTBOX_CONTENT);
							
							sIFR.runDelayedLightBoxHeaderStyling(styleTarget);
							
							
							// Png fix header images if required
							if ($.browser.msie && $.browser.version < 7)
							{
								var h2 = $(styleTarget).find("h2:first")[0];
								if (h2) fix_PNG(h2);
							}
							
							//alert(e.targetContainerId + " // " + styleTarget);
						}
			
				
				
				/*
				 =============================
				 UTILITIES
				 =============================
				 */
			
			
		}
	);
