﻿var scripts = function($){
    var priv = {
          
        onResizePopup : function() {
		    if(priv.openPopupId != null){
		        var dimensions = scripts.getViewPort();
                var screenWidth = dimensions[0];
                var screenHeight = dimensions[1];
                var scrollX = dimensions[2];
                var scrollY = dimensions[3];
                var pageX = dimensions[4];
                var pageY = dimensions[5];
    		    
                if($('#popupOverlay').length > 0){
                    // set width of overlay
                    $('#popupOverlay').width(pageX);
                }
                
                if($('#'+priv.openPopupId).length > 0){
                    var topPopup = ((screenHeight/2) + scrollY)-($('#'+priv.openPopupId).height()/2);
                    if(topPopup < 0) {
                        topPopup = 10;
                    }
                    $('#'+priv.openPopupId).css({'top':topPopup+'px','left':((screenWidth/2)-($('#'+priv.openPopupId).width()/2))+'px'});
                }
            }
        }
    
    };
    
    return {
        
        /**
		 * should be triggered on $(document).ready
		 */
		OnReady	: function(){			
		    // show emailadressess
            $('a.mail-sales').text('sales@allevakantiehuizen.nl').attr('href', 'mailto:sales@allevakantiehuizen.nl');
            $('a.mail-info').text('info@allevakantiehuizen.nl').attr('href', 'mailto:info@allevakantiehuizen.nl');
            $('a.mail-partner').text('partner@allevakantiehuizen.nl').attr('href', 'mailto:partner@allevakantiehuizen.nl');
            $('a.mail-huiseigenaar').text('huiseigenaar@allevakantiehuizen.nl').attr('href', 'mailto:huiseigenaar@allevakantiehuizen.nl');
            
            if(typeof(newsletter) != "undefined"){
				newsletter.OnReady();
			}
			
			if(location.href.indexOf('email') != -1 && location.href.indexOf('actn=') != -1){
			    var response = $.ajax({
                                      url: resources.path_prefix + '/utilpages/newsletter.aspx',
                                      data: location.href.split('?')[1],
                                      cache: false,
                                      async: false
                                     }).responseText;
                $('#pEmailVerifyResponse').text(response);
			    scripts.showDefaultPopup('pEmailVerify');
			}
			
			$('#masterdiv').css('height','1100px');
		},
		
		OnResize	: function(){
			//triggered on resize
			priv.onResizePopup();
		},
		
		getViewPort : function (){ 
            var windowX = (document.documentElement && document.documentElement.clientWidth) || 
                            window.innerWidth || self.innerWidth || document.body.clientWidth; 
            var windowY = (document.documentElement && document.documentElement.clientHeight) || 
                            window.innerHeight || self.innerHeight || document.body.clientHeight; 
            var scrollX = (document.documentElement && document.documentElement.scrollLeft) || 
                            window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
            var scrollY = (document.documentElement && document.documentElement.scrollTop) || 
                            window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
            var pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
            var pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
            
            return [windowX, windowY, scrollX, scrollY, pageX, pageY];
        },
                
        showDefaultPopup : function (popupId, popupWidth){
            if(popupWidth == null){
                popupWidth = 500;
            }
            
            // reset popup
            //formsubmit.resetPopup(popupId);
        
            // close any open popups
            if(priv.openPopupId != null){
                $('#'+priv.openPopupId).hide();
            }
            
            // create page overlayDiv if it doesnt exist
            if($('#popupOverlay').length == 0){
                $('body').append($('<div id="popupOverlay">'));
                $('#popupOverlay').css({'z-index':'999','background-color':'#4d4d4d','position':'absolute','top':'0','left':'0','opacity':'.4','filter':'alpha(opacity=40)','display':'none'});
            }
            
            var dimensions = scripts.getViewPort();
            var screenWidth = dimensions[0];
            var screenHeight = dimensions[1];
            var scrollX = dimensions[2];
            var scrollY = dimensions[3];
            var pageX = dimensions[4];
            var pageY = dimensions[5];
            var htmlHeight = $('body').height()+20;
            // set heigth and width of overlay
            $('#popupOverlay').width(pageX);
            $('#popupOverlay').height(pageY);
            $('#popupOverlay').bind("click", 
	            function(){
	                scripts.hidePopup();
	            }
	        );
	        
	        // initialize popup
            if(!$('#'+popupId).is('.initialized')){
                // add title bar with close button
                var popupHtml = '<div class="header">'+$('#'+popupId+' #pTitle').html()+' <a href="javascript:scripts.hidePopup();">Sluiten</a></div>'+
                                '<div class="content">'+$('#'+popupId).html()+'</div>';
                $('#'+popupId).html(popupHtml);
                $('#'+popupId).css({'width':popupWidth+'px'});
			    
                $('body').append($('#'+popupId));
                
			    $('#'+popupId).addClass('initialized');
            }
            
            // set position of popup
            var topPopup = ((screenHeight/2) + scrollY)-($('#'+popupId).height()/2);
            if(topPopup < 0) {
                topPopup = 10;
            }
            $('#'+popupId).css({'top':topPopup+'px','left':((screenWidth/2)-(popupWidth/2))+'px'});
                        
            // show overlay if necessary
            $('#popupOverlay').show();
            
            // show the popup
            $('#'+popupId).show();
            
            priv.openPopupId = popupId;
        },
        
        hidePopup : function () {
            $('#popupOverlay').hide();
            $('#'+priv.openPopupId).hide();
            priv.openPopupId = null;
        }
        
    };
}(jQuery);


/**
 * Initiate onload methods and functions
 */
$(document).ready(
	function(){
		scripts.OnReady();
	}
);
$(window).bind('resize', 
	function(){
		scripts.OnResize();
});


jQuery(document).ready(function() {
    jQuery(".holidaysummary")
	        .hover(function() {
	            $(this).addClass("holidaysummaryhover");
	        }, function() {
	            $(this).removeClass("holidaysummaryhover");
	        })
	        .click(function() {
	            top.location.href = $(this).find("a:last").attr("href");
	        });
});

