
var travelport = window.travelport || {};
travelport.web=travelport.web || {}
travelport.util={
    //utility functions
}


travelport.web.common={
    init:function(){
                
    var CMN=travelport.web.common;
    CMN._mainNavEffects();
    CMN._homeTips();
    CMN._sizeRequirements();
    CMN.industrySelect();
    CMN.businessSelect();
    CMN._sizeSeperator();
},

//private methods
    
    _mainNavEffects:function(){ //Rollover effects for main nav and drop nav	    
        $("#nav_main>li").hover(		                        
	        function(){ 
                var idx = $(this).parent().children().index(this);

                                                
                var bgPos = (((-36) * idx) - 36) + "px";
                $(this).parent().css("background-position", "0 " + bgPos );                
	            $(">ul", this).slideDown("fast");
	        }, 
	        function() {
	            $(">ul", this).slideUp(100); 
	            $(this).parent().css("background-position","0 0");
	        } 	        
        );	    	 	    	    	    	    
    },
    _homeTips:function(){ //Tooltip like elements on the homepage and category pages
        var maxHeight = 0;
    
        //Get the Maximum rendered tooltip so they are all sized uniformly                
        $('#nav_sub li div.content').each( function() {
                    var elementTotalHeight = $('p',this).height() + $('h1',this).height()
                    if ( elementTotalHeight > maxHeight )                    
                        maxHeight = elementTotalHeight;
                 } );
        
        //The additional 25 pixels is take into account the padding for the header and the paragraph
        $('#nav_sub li div div.content').css({"height": ( maxHeight + 25 )+ "px"});            
    
	    $("#nav_sub li a").mouseover(function(){
	        var container = $(this);
                        	        	        		        
	        $('>div', $(this).parent() ).each( function() {
	            $(this).css( { "left": ( container.position().left + 9 ) + "px", 
	                           "top": "-" +  ( $(this).height() - 3 ) + "px", 
	                           "visibility" : "visible" });
//	            $(this).css( { "left": ( container.position().left + 9 ) + "px", 
//	                           "top": "-" +  ( $(this).height() - 3 ) + "px" });
	            $('div',this).css( {"visibility" : "visible" });
	            
	            
	        } );		        
		    
	    });

	    $("#nav_sub li a").mouseout(function(){
		    $("#nav_sub li  div").css("visibility", "hidden");
	    });

        maxHeight = 0;
        $('#spotlight li div.content').each( function() {
                    var elementTotalHeight = $('p',this).height() + $('h1',this).height()
                    if ( elementTotalHeight > maxHeight )
                        maxHeight = elementTotalHeight;
                 } );
        $('#spotlight li div div.content').css({"height": ( maxHeight + 25 )+ "px"});
                        	    	    
	    $("#spotlight li a").mouseover(function(){
	        var spotlight = $(this); 
	        
            $('>div', $(this).parent() ).each( function() {                
	            $(this).css( { "left": spotlight.position().left - 3 +( ( spotlight.width() - $(this).width() ) / 2 )+ "px", 
	                           "top": "-" + ( $(this).height() - spotlight.height() - 23 ) + "px", 
	                           "visibility" : "visible" });
	            $('div',this).css( {"visibility" : "visible" });
            } );
            
	    });
	    	    
	     $("#spotlight li a").mouseout(function(){
                $("#spotlight li div").css("visibility", "hidden");
            } );

    },

    _sizeRequirements:function() { //Turn Off Drop Shadow if browser width gets too small,otherwise there will be a scrollbar at 1024x768
        var exceptions = [ "contact_us_wizard.aspx", "brands.aspx", "industry_experts.aspx","graphics_logos.aspx","photos.aspx" ];
        var isException = false;
                    
        function optimizeDimensions( force ) {
            var container = $('#page_container');
                            
            if ( container.height() < $(window).height() ) {
                container.css("height",$(window).height() );
            } else {
				container.css("height",$(document).height() + 50);
			}
			
            if ( $(window).width() < ( container.width() + 18 ) ) {
                if ( force ) {
                    container.css("padding","0");
                } else {
                    $('#page_container').animate( { "paddingLeft" : "0px", "paddingRight": "0px" }, { "duration": 300, "queue" : "false" }, function() { alert("here"); container.css("padding","0 0"); } ); 
                }
            } else {                
                $('#page_container').animate( { "paddingLeft" : "9px", "paddingRight": "9px" }, { "duration": 300, "queue" : "false" }, function() { container.css("padding","0 9px"); } );
            }                
        }
        
        //This is to avoid background distraction from the content in the third column if one exists
        if ( $('#features') != null ) {
            if ( ( $('#content_main').height() - $('#features').height() ) < 130 ) {
                for ( var exception in exceptions ) {
                    if ( ! window.location.href.match(exception) ) {
                        isException = true;
                    }
                }
                if ( ! isException ) {                    
                    $('#content_main').css("height", ( $('#features').height() + 130) + "px" );
                }
            }
        }
        
        optimizeDimensions( true );
        //$(window).resize( function() { optimizeDimensions( false ); } );
    },
    industrySelect:function(){	
	    $("#industryLinkBtn").click(function(e){
	        e.target.preventDefault;	        
	        var thisSelect = document.getElementById("industryLink");
	        document.location=thisSelect.value;
	    });
    },
    businessSelect:function(){	
	    $("#businessLinkBtn").click(function(e){
	        e.target.preventDefault;
	        var thisSelect = document.getElementById("businessLink");
	        document.location=thisSelect.value;
	    });
	    
    },
    _sizeSeperator:function(){
        var height = Math.max( $('#highlights #newsroom').height(),$('#highlights #facts').height());        
        height = Math.max( $('#highlights #categorynewsroom').height(),height);

        height = height - 80;        
        if ( height < 0 ) {
            height = 0;
        }        
        $('.vertical-seperator').html( "<div class='top'></div><div class='spacer'></div><div class='bottom'></div>");
        $('.vertical-seperator .spacer').css( {'height':height+'px'});
    }       
}

$(document).ready(travelport.web.common.init);