var Cms;
(function(){
	var isEditor = false;
	
	//define the Cms Object
	Cms = {
		//isEditor is true if the page is being edited by an administrator
		isEditor:function(){
			isEditor = true;
		}
	};
	
	var init = function(){
		if(isEditor){
			parent.iframeLoaded();
			$(window).bind("load",parent.resizeFunction);
			$(window).bind("resize",parent.resizeFunction);
			$(window).bind("scroll",parent.resizeFunction);
		} else {
			$("#cms .removeempty").each(function(){
				if(!$(this).find("div[id^=cmscontentitem]").length)
					$(this).remove();
			});
			$("#cms *[cms-minheight]").each(function(){
				minheight = parseInt($(this).attr('cms-minheight'));
				if($(this).height() < minheight){
					$(this).height(minheight);
				}
			});
			$("#cms *[cms-alignheight]").each(function(){
				alignto = $('#'+$(this).attr('cms-alignheight'));
				if(alignto.length){
					target = {
						vpadding:parseInt(alignto.css('padding-top')) + parseInt(alignto.css('padding-bottom')),
						offset:alignto.offset().top,
						cssheight:alignto.height(),
						height:function(){
							return this.cssheight + this.vpadding;
						}
					};
					align = $(this);
					thisItem = {
						vpadding:parseInt(align.css('padding-top')) + parseInt(align.css('padding-bottom')),
						offset:align.offset().top,
						cssheight:align.height()
					};
					offsetDiff = target.offset - align.offset().top;
					align.height(target.height() + offsetDiff - thisItem.vpadding);
				}
			});
		}
	};
	//define what happens on page ready
	$(init);
})();

