﻿if ( typeof( travelport ) != "undefined" ) {
            
    function mediaCentre(  ) {
            var settings = {                 
                "features" : {
                    "opacity" : { "selected" : "0.99", "notSelected" : "0.0" },
                    "transition" : {
                        "duration" : "200",
                        "reset" : "200"
                        
                    },
                    "left" : "0px",
                    "top" : "0px"
                            
                }
            };
                                           
            var insightContainer;
            var insightCollection;
            var currentItem;
                                                
            //Constructor
            __init = function() {
                                       
                if ( $('#item-carousel').length == 0 ) {
                    return;
                }
            
                $('#item-carousel').click(function(e) {
                        showInsight(e, true)
                        this.blur();
                        return false;
                    } );
            
                
                insightContainer = $('.insights .features');
                insightCollection = $('.insights .features .insight');                                                
 
                if ( $('.insights .features .insight.selected').length > 0 ) {
                    $('.insights .features .insight.selected').each( function() {
                            currentItem = $('#item-carousel li:eq(' + $(this).parent().children().index(this) + ')');
                        } );
                } else { 
                    $('.insights .features .insight:eq(0)').each( function() { 
                            $(this).addClass("selected");
                            currentItem = $(this);
                        } );
                }
                resetAllInsights();                           
                
                $('#item-carousel li').hover(function(e) { showInsight(e, false, false); }, function(e) { showInsight(e, false, true ); } );
            }                        

            showInsight = function(e, persistent, hoverOut ) {                              
                $('.insights .features .insight').removeClass("preview");
                
                if ( hoverOut || typeof(e.target) == "undefined" || e == null ) {
                    resetAllInsights();
                    return;
                }

                var target = e.target.parentNode.hash || e.target.hash;
                
                if ( persistent ) {                
                    $('.insights .features .insight').removeClass("selected");
                    $(target).addClass("selected");
                } else {
                    $(target).addClass("preview");
                }
                resetAllInsights();
                                
                $('.insights .features .insight.selected').each( function() {
                        $(this).css({ "z-index" : "1", "display":"block"});                        
                        $(this).animate( 
                                        {   
                                            "top": "0px" ,
                                            "left": "0px", 
                                            "opacity": settings.features.opacity.selected 
                                        }, 
                                        settings.features.transition.duration );                   
                         } );
                
                $('.insights .features .insight.preview:not(.selected)').each( function() {
                        $(this).css({ "z-index" : "2", "display":"block"});
                        $(this).animate( 
                                        {   
                                            "top": 0 + "px" ,
                                            "left": 0 + "px", 
                                            "opacity": settings.features.opacity.selected 
                                        }, 
                                        settings.features.transition.duration );
                                                              
                         } );        
            }   

            //Return All Elements To original State 
            resetAllInsights = function () {
                $('.insights .features .insight').each( function() {
                        if ( !($(this).hasClass("selected")) && !($(this).hasClass("preview")) ) { 
                            $(this).css({ "z-index" : "0",
                                          "top": settings.features.top, 
                                          "left": settings.features.left, 
                                          "opacity": settings.features.opacity.notSelected                                                                                
                                        }); 

                        }                        
                } );
            }
            
            //
            iconState = function( e, offset ) {                
                $(e.target).css("background-position", "0 " + offset );
            }
            
            __init();
    }        
    
    $(document).ready(function() {travelport.web.common._prepCarousel(); travelport.web.mediacentre = new mediaCentre(); })
         
}
