﻿

/// <reference path="../../../../../jQuery/1.3.2/jquery-1.3.2-vsdoc.js" />


/**
*****************************************************************
* LightboxExtender
*****************************************************************
*
* Extends the lightbox implementation to give custom Lexus functionality
*
* Author : Rob Earlam
*/

//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.controls")) mrm.global.createNamespace("mrm.lexus.display.controls", "1.0");

    mrm.lexus.display.controls.LightboxExtender = Object.subClass(
		{
		    /*
			 =============================
			 CONSTRUCTOR
			 =============================
			 */
			init : function (instanceReferenceString, targetContainer)
			{
				//approved benefits constats
			    this._approvedBenefitsClass = "approved-benefits";
			    this._approvedBenefitsLinkClass = "approved-benefits-link";
			    this._approvedBenefitsWarrentyLinkClass = "approved-benefits-warranty-link";
			    this._approvedBenefitsPreparationAndValetingLinkClass = "approved-benefits-preparation-and-valeting-link";
			    this._approvedBenefitsHistoryCheckLinkClass = "approved-benefits-history-check-link";
			    this._approvedBenefitsServiceHistoryLinkClass = "approved-benefits-service-history-link";
			    this._approvedBenefitsExchangeLinkClass = "approved-benefits-exchange-link";
			    this._approvedBenefitsRoadsideAssistanceLinkClass = "approved-benefits-roadside-assistance-link";
			    this._approvedBenefitsWarrentyContainerClass = "summary-warranty";
			    this._approvedBenefitsPreparationAndValetingContainerClass = "summary-preparation";
			    this._approvedBenefitsHistoryCheckContainerClass = "summary-history-mileage";
			    this._approvedBenefitsServiceHistoryContainerClass = "summary-service-history";
			    this._approvedBenefitsExchangeContainerClass = "summary-exchange";
			    this._approvedBenefitsRoadsideAssistanceContainerClass = "summary-rac";
			    this._lightBoxContainer = $(document).find('.ui-lightbox-container');
			    			    
			    //vehicle view constants
			    this._vehicleEquipmentIframe = $(document).find('iframe.lightbox-extender-vehicle-equipment');
			    this._vehicleContainer = $(document).find('.vehicle-display-container');

			    //select the setup function to run depending on what html elements are present on the page
			    var _this = this;
			    if($("." + _this._approvedBenefitsClass).length > 0) {
			        _this._configureApprovedBenefitsExtensions();
			    }
			    
//			    if(_this._vehicleContainer.length > 0) {
//			    	_this._configureVehicleViewExtensions();
//			    }
			},


			/*
			=============================
			INTERNAL / PRIVATE METHODS
			=============================
			*/
			    /*
			    =============================
			    SETUP
			    =============================
			    */
			    
//			    _configureVehicleViewExtensions : function () 
//			    {
//					var _this = this;
//					_this._vehicleContainer.find('a.vehicle-equipment-more-info-link').unbind('click').click(function(event) {
//						
//						event.preventDefault();
//						_this._vehicleEquipmentIframe.attr('src', "/Glossary.aspx?glk=" + $(this).attr('rel'));


//						var url = this.href || this.alt;
//						var parameters = uiBox_GetQueryString(url);

//						uiBox_Show(parameters, url);
//					});
//			    },
			    
	
			    
			    _configureApprovedBenefitsExtensions : function() 
			    {
			        var _this = this;
			        _this._bindEventsOnLightboxLoad();
			    },
			    
	
			    
			    _bindEventsOnLightboxLoad : function () 
			    {
			        var _this = this;

			        //when the base lightbox broadcasts its load function, hook into the newly created content
			        _this._lightBoxContainer.bind("load", function() {

			            _this._bindApprovedBenefitsEvents();

			            if ($('div.ui-lightbox-content div#divBenefit01').length > 0) {
			            	$('.ui-lightbox-content-footer a.previous').hide();
			            }
			            else {
			            	$('.ui-lightbox-content-footer a.previous').show();
			            }

			            if ($('div.ui-lightbox-content div#divBenefit06').length > 0) {
			            	$('.ui-lightbox-content-footer a.next').hide();
			            }
			            else {
			            	$('.ui-lightbox-content-footer a.next').show();
			            }
			            
			        });
			    },
			    
		
			    
			    _bindApprovedBenefitsEvents : function() 
			    {
			        var _this = this;

			        _this._lightBoxContainer.find("a." + _this._approvedBenefitsLinkClass).click(function(event) {
                        event.preventDefault();

                        //find the currently displayed panel
                        var _currentPanel = _this._lightBoxContainer.find('.ui-lightbox-content .ui-lightbox-content-container');
                        
                        if($(this).hasClass(_this._approvedBenefitsWarrentyLinkClass)) {
                            _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsWarrentyContainerClass,'01');
                            _this.switchPrevNextButtons(true);

		                }
		                else if ($(this).hasClass(_this._approvedBenefitsPreparationAndValetingLinkClass)) {
		                    _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsPreparationAndValetingContainerClass,'02');
							$('.ui-lightbox-content-footer a.previous').show();
		                }
		                else if ($(this).hasClass(_this._approvedBenefitsHistoryCheckLinkClass)) {
		                    _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsHistoryCheckContainerClass,'03');
		                }
		                else if ($(this).hasClass(_this._approvedBenefitsServiceHistoryLinkClass)) {
		                    _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsServiceHistoryContainerClass,'04');
		                }
		                else if ($(this).hasClass(_this._approvedBenefitsExchangeLinkClass)) {
		                    _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsExchangeContainerClass,'05');
		                }
		                else if ($(this).hasClass(_this._approvedBenefitsRoadsideAssistanceLinkClass)) {
		                    _this._switchApprovedBenefitsPanel(_currentPanel, _this._approvedBenefitsRoadsideAssistanceContainerClass,'06');
		                    _this.switchPrevNextButtons(false);
		                }		            
		            });			            			            
			    },
			    
		
			    
			    _switchApprovedBenefitsPanel : function(panel,newPanelClass,id) 
			    {
			        var _this = this;
			        panel.html('');
			        panel.html($(document).find("." + newPanelClass + " .benefit-details").html());
			        panel.attr('id','divBenefit' + id);
			        _this._bindApprovedBenefitsEvents();
			        
			        
			        /*
					var previouslink = $('.ui-lightbox-content-footer a.previous');
			        var nextlink = $('.ui-lightbox-content-footer a.next');
			        
			        var classDisabledPrevious	= "a-button-round-arrow-left-disabled";
			        var classDisabledNext		= "a-button-round-arrow-right-disabled";
			        
			       
			        //show or hide the previous and next buttons if we're in the first or last state
			        if(id == '01') {
						//$('.ui-lightbox-content-footer a.previous').hide();
						if (!previouslink.hasClass(classDisabledPrevious)) link.addClass(classDisabledPrevious);
			        }
			        else {
			        	//$('.ui-lightbox-content-footer a.previous').show();
			        	if (previouslink.hasClass(classDisabledPrevious)) link.removeClass(classDisabledPrevious);
			        }
			        
			        
			        if(id == '06') {
			        	//$('.ui-lightbox-content-footer a.next').hide();
			        	if (!nextlink.hasClass(classDisabledNext)) nextlink.addClass(classDisabledNext);
			        }
			        else {
			        	//$('.ui-lightbox-content-footer a.next').show();
			        	if (nextlink.hasClass(classDisabledNext)) nextlink.removeClass(classDisabledNext);
			        }
			        */
			        
			        /* Fire a document level overlay loaded event */
					var lightboxLoadedEvent	= jQuery.Event("LIGHTBOX-LOAD-COMPLETE");
					$(document).trigger(lightboxLoadedEvent);
			    },
			    
			    _switchPrevNextButtons : function(isFirstScreen)
			    {
					if(isFirstScreen)
					{
						$('.ui-lightbox-content-footer a.next').show();
		                $('.ui-lightbox-content-footer a.previous').hide();
					}
					else
					{
						$('.ui-lightbox-content-footer a.next').hide();
		                $('.ui-lightbox-content-footer a.previous').show();
					}
			    }				
		}
    )
