﻿/**
 * Result list logic and functionallity
 * depends on jQuery, jQuery-cookie, and sunweb static "logic" object
 */
var accoDetails = function($){
	var priv = {
		onResizePopup : function() {
		    var width = $(window).width();
		    
            if($('#popupOverlay').length > 0){
                // set width of overlay
                $('#popupOverlay').width(width);
            }
            
            if($('#location-googlemaps-lightbox').length > 0){
                var topPopup = logic.getCurrentCenterHeight()-(585/2);
                if(topPopup < 0) {
                    topPopup = 10;
                }
                $('#location-googlemaps-lightbox').css({'top':topPopup+'px','left':((width/2)-(643/2))+'px'});
            }
        }		
	};
	
	return {
	    showSendAccoPopup : function () {
	        $('#sendAccoContent').show();
	        $('#sendAccoMessage').hide();
	        logic.resizePopup();
	        logic.showPopup('pSendAcco', true, 625, 0);
	    },	
	    
	    showAccoMoreInfo : function (popupid) {
	        $('#movieObject').hide();
	        logic.resizePopup();
	        logic.showPopup(popupid, true, 625, 0);	    
	    },
	    
	    showLocationGooglemaps : function() {
	        var id = $('#curacco').attr("title");
	        if (id == null || id == "")
	        {
	            id = -1;
	        }

            var screenWidth = $(window).width();
            var screenHeight = $(window).height();
            var scrollY = $(document).scrollTop();
            var pageX = $(document).width();
            var pageY = $(document).height();
	        
            // set heigth and width of overlay
            $('#popupOverlay').width(pageX);
            $('#popupOverlay').height(pageY);
            
            // set position of popup
            var topPopup = ((screenHeight/2) + scrollY)-(585/2);
            if(topPopup < 0) {
                topPopup = 10;
            }
            $('#location-googlemaps-lightbox').css({'top':topPopup+'px','left':((screenWidth/2)-(643/2))+'px'});            
	        
	        $('#popupOverlay').show();
	        if ($('#location-googlemaps-lightbox').hasClass('initialized'))
	        {
    	        $('#location-googlemaps-lightbox').show();
	        }
	        else
	        {
	            $('#location-googlemaps-lightbox').addClass('initialized');
    	        $('#location-googlemaps-lightbox').show();
	            searchmap.loadGoogleMaps(false, id);
	        }
	    },    	   
		/**
		 * should be triggered on $(document).ready
		 */
		OnReady	: function(){				
			var Timer1 = new Timer();
			photoCarousel  = new PCarousel2({"listItem" : $("#image-carousel div.image ul").get(0) , "prevButton" : $("#image-carousel .prev").get(0) , "nextButton" : $("#image-carousel .next").get(0) , "direction" : "horizontal"},
			    function(){
			        $("#image-carousel-counter").html(photoCarousel.GetCurrentIndex() + 1);
			    }
			);			
    			
                
                
                
               	$("#trip-descriptions div.content-multiple-rooms").jHelperTip({
                     trigger: "hover", 
                     topOff: -185,	
                     leftOff: -100,            	            	                
                     source: "container", 
                     dC:'#content-multiple-rooms-info',
                     opacity: 0.8, 
                     autoClose:true                     
                    });
                
                $("#trip-descriptions div.content-children").jHelperTip({
                     trigger: "hover", 
                     topOff: -285,
                     leftOff: -225,	            	            	                
                     source: "container", 
                     dC:'#content-children-info',
                     opacity: 0.8, 
                     autoClose:true                     
                    });
                $("#trip-descriptions div.content-babies").jHelperTip({
                     trigger: "hover", 
                     topOff: -175,
                     leftOff: -275,	            	            	                
                     source: "container", 
                     dC:'#content-babies-info',
                     opacity: 0.8, 
                     autoClose:true                     
                });    
			logic.writeDebug("adjustAccoName time was: " + (Timer1.Stop()) + "ms ", -1);
			
			// event when clicked on the lowest price on the acco page
			$('div.sidebar span.price').bind("click", function(){
			    var lowestPriceMonth = $('span.lmonth', $(this).parent()).text();
			    var lowestPriceVacationLength = $('span.lvacationlength', $(this).parent()).text();
			    if(lowestPriceMonth != '0' && lowestPriceMonth != null && lowestPriceMonth != ''){
			        // set the lowest price parameters and reload the pricetab
			        Prices.setLowestPriceMonth(lowestPriceMonth);
			        // get the lowest price vacation length to load the correct pricetable (short, medium or long)
			        if(lowestPriceVacationLength != '0' && lowestPriceVacationLength != null && lowestPriceVacationLength != ''){
			            if (parseInt(lowestPriceVacationLength) > 0 && parseInt(lowestPriceVacationLength) < 8){
			                Prices.filterPriceTab('short');
			            }
			            else if (parseInt(lowestPriceVacationLength) < 11){
			                Prices.filterPriceTab('medium');
			            }
			            else{
			                Prices.filterPriceTab('long');
			            }
			        }
			        else{
			            Prices.reloadPriceTab();
			        }
			        
			        // scroll to the pricetable
			        var selectedPosX = 0;
	                var selectedPosY = 0;	                
	                var theElement = $("#prices")[0];
        	        
	                while(theElement != null){
	                    selectedPosX += theElement.offsetLeft;
	                    selectedPosY += theElement.offsetTop;
	                    theElement = theElement.offsetParent;
	                }        	        
	                window.scrollTo(selectedPosX,selectedPosY);
			    }
			});
		},
		OnResize	: function(){
			//triggered on resize
			priv.onResizePopup();
		}	
	};
}(jQuery);

/**
 * Bind resize eventes
 */
$(window).bind('resize', 
	function(){
		accoDetails.OnResize();
});
