

window.addEvent('domready', function()	{

	/*
	 * Toggle DMS Secions
	 */
	$$("#dms_content .dms_section_dynamic .dms_section_header").each(function(item){
		item.addEvent('click', function(e){
			var e = new Event(e);
			var t = new Element(e.target);
			while (!t.hasClass('dms_section_dynamic') && t.getParent() ){
				t = t.getParent();
			} 
			if (t.hasClass('dms_section_dynamic') ){
				if (!t.hasClass('dms_section_opened') ) {
					t.addClass('dms_section_opened');
					t.removeClass('dms_section_closed');
				} else {
					t.addClass('dms_section_closed');
					t.removeClass('dms_section_opened');
				}			
			}
		});
	});
	/*
	 * Popup Funcions
	 */			
		// global reference to poup window
	dms_popup_window = false;
	
	$$("#dms_content a.dms_popup, span.dms_popup, div.dms_popup").each(function(item){
		
		var options = {
			width  : item.getProperty('dms:popup_width'),
			height : item.getProperty('dms:popup_height'),
			resizable : item.getProperty('dms:popup_resizable')
		}
		item.setStyle('cursor','pointer');
		item.addEvent('click', function(e,options){
			var e = new Event(e);
			var t = new Element(e.target);
			while ( !t.hasClass('dms_popup') && t.getParent() ) {
				t = t.getParent();
			}
			e.stop();
			if ( t.hasClass('dms_popup') ) {
					// close exyisting window
				if (dms_popup_window){
					dms_popup_window.close();
				}
					// open window
				
				if ( this.params && this.params != "" ){
					dms_popup_window = window.open(t.getProperty("href"), "dms_popup" , 'width='+this.width+",height="+this.height+","+this.params );
				} else if ( this.resizable == "true" || this.resizable == "yes" || this.resizable == "1" ){
					dms_popup_window = window.open(t.getProperty("href"), "dms_popup" , 'width='+this.width+",height="+this.height+",resizable=yes,scrollbars=yes" );
				} else {
					dms_popup_window = window.open(t.getProperty("href"), "dms_popup" , 'width='+this.width+",height="+this.height+",resizable=no,scrollbars=no" );
				}
				dms_popup_window.focus();
			}
		}.bind(options));
	});
	
	$$("#dms_content .dms_info_show_more").each(function(item){
		item.setStyle('cursor','pointer');
		item.addEvent('click', function(e){
			e = new Event(e);
			t = new Element(e.target);

			var parent = t.getParent();
			while (!parent.hasClass("dms_info") && parent.getParent() ){
				parent = parent.getParent();
			}
			$ES('.dms_info_show_more',parent).each(function(el){  el.setStyle('display','none');   });
			$ES('.dms_info_more',parent).each(function(el){       el.setStyle('display','inline'); });
			$ES('.dms_info_hide_more',parent).each(function(el){  el.setStyle('display','inline'); });
		});
	});
	
		
	$$("#dms_content .dms_info_hide_more").each(function(item){
		item.setStyle('cursor','pointer');
		item.addEvent('click', function(e){
			e = new Event(e);
			t = new Element(e.target);
			var parent = t.getParent();
			while (!parent.hasClass("dms_info") && parent.getParent() ){
				parent = parent.getParent();
			}
			$ES('.dms_info_show_more',parent).each(function(el){  el.setStyle('display','inline');  });
			$ES('.dms_info_more',parent).each(function(el){       el.setStyle('display','none');    });
			$ES('.dms_info_hide_more',parent).each(function(el){  el.setStyle('display','none');    });
		});
	});
	
});