
var Cookie = {
    'set': function(cookieName, cookieValue, sessionOnly){
        var sessionOnly = sessionOnly == null ? 0 : 1;
        var date = new Date("June 30, 2020");
        var cookieDate = date.toGMTString();
        var flag = 0;
        
        var cookies = new Array;
        cookies = document.cookie.split(';');
        for (var i = 0, j = cookies.length; i < j; i++) {
            if (cookies[i].substring(0, cookieName.length + 1) == (cookieName + '=')) {
                cookies[i] = cookieName + '=' + escape(cookieValue) + (sessionOnly ? '' : ";expires=" + cookieDate) + ";path=/";
                flag = 1;
                break;
            }
        }
        
        if (flag != 1) {
            document.cookie = cookieName + '=' + escape(cookieValue) + (sessionOnly ? '' : ";expires=" + cookieDate) + ";path=/;" + document.cookie;
        }
        else {
            document.cookie = cookies.join(';');
        }
        
        return cookieValue;
    },
    'read': function(cookieName){
        var cookies = document.cookie.split(';');
        for (var i = 0, j = cookies.length; i < j; i++) {
            cookies[i] = cookies[i].replace(/^[ ]*/g, '');
            if (cookies[i].substring(0, cookieName.length + 1) == (cookieName + '=')) {
                return decodeURIComponent(cookies[i].substring(cookieName.length + 1));
            }
        }
        return false;
    },
    
    'delete': function(cookieName){
    
        var date = new Date("June 30, 1998");
        var cookieDate = date.toGMTString();
        var flag = 0;
        var removedCookie = '';
        
        var cookies = document.cookie.split(';');
        for (var i = 0, j = cookies.length; i < j; i++) {
            cookies[i] = cookies[i].replace(/^[ ]*/g, '');
            if (cookies[i].substring(0, cookieName.length + 1) == (cookieName + '=')) {
                cookies[i] = '';
                removedCookie = cookieName + "=0;expires=" + cookieDate + ";path=/;";
                flag = 1;
                break;
            }
        }
        
        if (flag) {
            document.cookie = removedCookie + cookies.join(';');
        }
        
        return flag;
    },
    'enabled': function(){
        if (navigator.cookieEnabled != undefined) 
            return navigator.cookieEnabled;
        return false;
    }
    
}



 

var Popup = {
    'hideAll': function(){
        $('.popup_container').fadeOut('fast');
       	$('#dropsheet').fadeOut('fast');
    },
    'show': function(name){
        var id = '#' + name;
        
        
        if ($(id)[0]) {
        
            window.scrollTo(0, 0);
            
            if (this.currentShown.length > 0) {
                this.hideAll();
            }
			
			// show dropsheet
	        var pageY = WindowInfo.getPageY();
	        var viewY = WindowInfo.getViewportY();
	        var dropHeight = pageY > viewY ? pageY : viewY;
	        $('#dropsheet').height(dropHeight);
			$('#dropsheet_color').height(dropHeight);
	        $('#dropsheet').fadeIn('fast');

            // show popup
            var popupWidth = $(id).width();
            var popupHeight = $(id).height();
            var popupLeft = (WindowInfo.getViewportX() - popupWidth) /2;
            var popupTop = 40;
            
            $(id).css('left', popupLeft + 'px');
            $(id).css('top', popupTop + 'px');
			$(id).fadeIn('fast');
			
			// bind events
			$('#dropsheet').bind("click", function(e) {
				if (!Popup.mouseOverContent) Popup.hideAll();
			});			
			$(id).bind("mouseover", function(e){
				Popup.mouseOverContent = 1;
			});
			$(id).bind("mouseout", function(e){
				Popup.mouseOverContent = 0;
			});
            
        }
    },
    'currentShown': [],
	'mouseOverContent': 0
}






var WindowInfo = {
    'getViewportY': function(){ // viewport
        var height = 0;
        if (typeof(window.innerWidth) == 'number') {
            height = window.innerHeight;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            height = document.documentElement.clientHeight;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            height = document.body.clientHeight;
        }
        return height;
    },
    'getViewportX': function(){
        var height = 0;
        if (typeof(window.innerWidth) == 'number') {
            width = window.innerWidth;
        }
        else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            width = document.documentElement.clientWidth;
        }
        else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            width = document.body.clientWidth;
        }
        return width;
    },
    'getOffsetY': function(){ // scroll top edge offset
        var scrOfY = 0;
        if (typeof(window.pageYOffset) == 'number') {
            scrOfY = window.pageYOffset;
        }
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            scrOfY = document.body.scrollTop;
        }
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            scrOfY = document.documentElement.scrollTop;
        }
        return scrOfY;
    },
    'getOffsetX': function(){
        var scrOfX = 0;
        if (typeof(window.pageXOffset) == 'number') {
            scrOfX = window.pageXOffset;
        }
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            scrOfX = document.body.scrollLeft;
        }
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            scrOfX = document.documentElement.scrollLeft;
        }
        return scrOfX;
    },
    'getPageX': function(){ // total length
        return $(document).width();
    },
    'getPageY': function(){
        return $(document).height();
    }
}

