

SBH = {};

SBH.Main = function(){

	var main_config = {};
	
	return {
		init: function(config){
		  	main_config = config;
		},
		toggleTitleBar: function(obj, e) {			
			this.showHide(e);

			this.toggleClass(obj, "minus", "plus");
		},
		showHide: function(e){
			var e = document.getElementById(e);
			
			if (e) {
				if (e.style.display=="none" ) {
					e.style.display="block";
				} else {
					e.style.display="none";
				}
			}
		},			
		show:function(e) {
			var e = document.getElementById(e);
			
			if (e) {
				e.style.display="block";
			}
		},
		hide:function(e) {
			var e = document.getElementById(e);
			if (e) {
				e.style.display="none";
			}
		},					
		toggleClass:function(e,cl1,cl2) {
			if (e.className==cl1) {
				e.className=cl2;
			} else {
				e.className=cl1;
			}
		},
		toggleGadgetColumns: function() {
			if ($('body').hasClass('wide')) {
				var proceed = false;
				if(gadgets.container.gadgetsInColumns([3])) {
					proceed = confirm('Gadgets zullen opnieuw worden gerangschikt als u het aantal kolommen aanpast.' +
					        ' Weet u zeker dat u wilt doorgaan?');
				} else {
					proceed = true;
				}
				
				if(proceed) {
					$('body').removeClass('wide');
					$('#toggleColumnsCheck').attr('checked', false);
					gadgets.container.setColumns(3);
				}	
			} else {
				$('body').addClass('wide');
				$('#toggleColumnsCheck').attr('checked', true);
				gadgets.container.setColumns(4);
			}			
		},
		redirectAction: function(ri, action){
			var postdata = {
				action: action,
				params: {
					ri: ri
				}
			};			

//			if (new_window != null) {
//				var cmd = (this.current_config.opensocial ? 'parent.' : '') + 'window.open(\'' + this.current_config[gadget_id].web_root + 'login/?origin=' + $.toJSON(postdata) + '\')';
//			}
//			else {
				var cmd = 'window.open(\'' + main_config.web_root + 'login/?origin=' + $.toJSON(postdata) + '\');';
//			}
			eval(cmd);
		},
		verversPagina: function() {
			
			setTimeout(function() {
				window.location = ''+main_config.web_root+'Persoonlijke-pagina/'; //window.location;			
			}, 3000);
		}
	}
}();
function toggleWidgetUI() {
	var d = document.getElementById("footerwrapper");
	if (d) {
		if (d.style.display=="block")  {
			d.style.display="none";
			d = document.getElementById("tab");
			if (d) {
				d.className="tabclosed";
			}
		} else {
			d.style.display="block";
			document.location="#widgetfooter";
			d = document.getElementById("tab");
			
			if (d) {
				d.className="tabopen";
			}
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

$(document).ready(function() {
    //Voeg automatisch een print onclick event toe aan de Print link in het topmenu
    $("#topmenu ul li a[title='Print']").attr('onclick','javascript:print();');

    function cookieResize(selector, defaultSize) {

        var lastSize = defaultSize;

        function write(name, value, days) {
            var expires = "";
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 86400000));
                expires = "; expires=" + date.toGMTString();
            }
            document.cookie = name + "=" + value + expires + "; path=/";
        }

        function read(name) {
            name += "=";
            var ca = document.cookie.split(';');
            for(var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1, c.length);
                if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
            }
            return null;
        }

        function updateSizeFromCookie() {
            $('body').removeClass(lastSize);
            lastSize = read('size') || defaultSize;
            $('body').addClass(lastSize);
        }

        jQuery(selector).click(function() {
            write('size', this.className,365);
            updateSizeFromCookie();
            return false;
        });

        updateSizeFromCookie();
    }
    cookieResize('#topmenu a.resize', 'medium');
});
