var dpAccordionIsWorking = false;
jQuery.iDpAccordion = {
	build : function(options)
	{
		return this.each(
		function()
		{
			/*
			panelWidth: 300,panelHeight: 400,speed: 300,rounded: false, // optional cornerWidth: 6, // optional cornerHeight: 6, // optional imgDir: 'imagedir/', // optional activeClass: 'classname', // optional hoverClass: 'classname', // optional hover: true, // optional scrollBars: false // optional
			*/
			var this_dd = $('#'+$(this).attr('id')+' > dd');
			var this_dt = $('#'+$(this).attr('id')+' > dt');
			if (!(options.scrollBars == null) && options.scrollBars == false) {
				$(this_dd).css("overflow","hidden");
			} else {
				$(this_dd).css("overflow","auto");
			}
			var currentTime = new Date();
			var aid = currentTime.getTime();
			$(this).wrap('<div id="wrapper'+aid+'"></div>');
			if (!(!(options.rounded == null) && options.rounded==false)) {
				$('#wrapper'+aid).prepend('<div id="tl'+aid+'"><!-- --></div><div id="tr'+aid+'"><!-- --></div><div id="br'+aid+'"><!-- --></div><div id="bl'+aid+'"><!-- --></div>');
			}
			$('#wrapper'+aid).css({ position: "relative", width: options.panelWidth});
			$(this_dt).css("cursor","pointer");
			if (!(!(options.rounded == null) && options.rounded==false)) {
				var cornerWidth = 6;
				if (!(options.cornerWidth == null) && !isNaN(options.cornerWidth)) cornerWidth = options.cornerWidth;
				var cornerHeight = 6;
				if (!(options.cornerHeight == null) && !isNaN(options.cornerHeight)) cornerHeight = options.cornerHeight;
				$('#tl'+aid).css({ width: cornerWidth, height: cornerHeight, position: "absolute", top: 0, left: 0, zIndex: "12", backgroundImage: "url('"+options.imgDir+"tl.gif')"});
				$('#tr'+aid).css({ width: cornerWidth, height: cornerHeight, position: "absolute", top: 0, right: 0, zIndex: "12", backgroundImage: "url('"+options.imgDir+"tr.gif')"});
				$('#br'+aid).css({ width: cornerWidth, height: cornerHeight, position: "absolute", bottom: 0, right: 0, zIndex: "12", backgroundImage: "url('"+options.imgDir+"br.gif')"});
				$('#bl'+aid).css({ width: cornerWidth, height: cornerHeight, position: "absolute", bottom: 0, left: 0, zIndex: "12", backgroundImage: "url('"+options.imgDir+"bl.gif')"});
			}
			$(this).css({ width: "auto", marginBottom: 0 });
			$(this).Accordion({headerSelector: 'dt', panelSelector: 'dd', activeClass: options.activeClass, hoverClass: options.hoverClass, panelHeight: options.panelHeight, speed: options.speed, onShow: function() { dpAccordionIsWorking = false; }, onClick: function() { dpAccordionIsWorking = true; } });
			if (!(options.hover == null) && options.hover == true) {
				$(this_dt).hover(function() { if (dpAccordionIsWorking == false) { $(this).trigger('click'); } });
			}
			if (!(options.currentPanel == null)) {
				$('#'+$(this).attr('id')+' > dt:eq('+options.currentPanel+')').trigger('click');
			}
		}
		);
	}
};
jQuery.DpSize = {
	dpgetsize: function()
	{
		var viewportwidth;
		var viewportheight;
		if (typeof window.innerWidth != 'undefined')
		{
			viewportwidth = window.innerWidth,
			viewportheight = window.innerHeight
		}
		else if (typeof document.documentElement != 'undefined'
		&& typeof document.documentElement.clientWidth !=
		'undefined' && document.documentElement.clientWidth != 0)
		{
			viewportwidth = document.documentElement.clientWidth,
			viewportheight = document.documentElement.clientHeight
		}
		else
		{
			viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
			viewportheight = document.getElementsByTagName('body')[0].clientHeight
		}
		if (isNaN(viewportwidth)) viewportwidth = $(window).width();
		if (isNaN(viewportheight)) viewportheight = $(window).height();
		return {width: viewportwidth, height: viewportheight};
	}
};
jQuery.DpCorners = {
	build: function(options) {
		return this.each(
		function()
		{
			var shadow = 'light';
			if ($.browser.safari || $.browser.mozilla) shadow = 'real';
			//if ($.browser.msie && $.browser.version == '7.0') shadow = 'real';
			
			var asize = 10;
			var imgTL = '';
			var imgTC = '';
			var imgTR = '';
			var imgML = '';
			var imgMC = '';
			var imgMR = '';
			var imgBL = '';
			var imgBC = '';
			var imgBR = '';
			if (!(options == null)) {
				if (!(options.imgTL == null)) {
					imgTL = options.imgTL;
				}
				if (!(options.imgTC == null)) {
					imgTC = options.imgTC;
				}
				if (!(options.imgTR == null)) {
					imgTR = options.imgTR;
				}
				if (!(options.imgML == null)) {
					imgML = options.imgML;
				}
				if (!(options.imgMC == null)) {
					imgMC = options.imgMC;
				}
				if (!(options.imgMR == null)) {
					imgMR = options.imgMR;
				}
				if (!(options.imgBL == null)) {
					imgBL = options.imgBL;
				}
				if (!(options.imgBC == null)) {
					imgBC = options.imgBC;
				}
				if (!(options.imgBR == null)) {
					imgBR = options.imgBR;
				}
			}

			if (!(options == null) && !(options.size==null)) asize = options.size;

			// wrapper erstellen
			var rc_wrap = document.createElement('div');
			$(rc_wrap).css({position: 'absolute'});
			
			if (shadow == 'real') {

				var rc_tl = document.createElement('div');
				$(rc_tl).css({	position: 'absolute',  zIndex: 12, backgroundImage: "url('"+imgTL+"')", width: asize, height: asize, top: 0, left: 0});
				$(rc_wrap).append(rc_tl);
	
				var rc_tr = document.createElement('div');
				$(rc_tr).css({	position: 'absolute', zIndex: 12, backgroundImage: "url('"+imgTR+"')", width: asize, height: asize, top: 0, right: 0});
				$(rc_wrap).append(rc_tr);
	
				var rc_bl = document.createElement('div');
				$(rc_bl).css({	position: 'absolute', zIndex: 12, backgroundImage: "url('"+imgBL+"')", width: asize, height: asize, bottom: 0, left: 0});
				$(rc_wrap).append(rc_bl);
	
				var rc_br = document.createElement('div');
				$(rc_br).css({	position: 'absolute', zIndex: 12, backgroundImage: "url('"+imgBR+"')", width: asize, height: asize, bottom: 0, right: 0});
				$(rc_wrap).append(rc_br);
	
				var rc_tm = document.createElement('div');
				$(rc_tm).css({	position: 'absolute', zIndex: 14, backgroundImage: "url('"+imgTC+"')", top: 0, left: asize, right: asize, height: asize});
				$(rc_wrap).append(rc_tm);
	
				var rc_bm = document.createElement('div');
				$(rc_bm).css({	position: 'absolute', zIndex: 14, backgroundImage: "url('"+imgBC+"')", bottom: 0, left: asize, right: asize, height: asize});
				$(rc_wrap).append(rc_bm);
	
				var rc_lm = document.createElement('div');
				$(rc_lm).css({	position: 'absolute', zIndex: 14, backgroundImage: "url('"+imgML+"')", left: 0, top: asize, bottom: asize, width: asize});
				$(rc_wrap).append(rc_lm);
	
				var rc_rm = document.createElement('div');
				$(rc_rm).css({	position: 'absolute', zIndex: 14, backgroundImage: "url('"+imgMR+"')", right: 0, top: asize, bottom: asize, width: asize});
				$(rc_wrap).append(rc_rm);

			}

			var newobj = $(this).clone(true);
			// inneren wrapper erstellen
			var rc_content = document.createElement('div');
			
			if (shadow == 'real') {
				$(rc_content).css({	margin: asize, backgroundImage: "url('"+imgMC+"')", position: 'relative'});
			} else if (shadow == 'light') {
				
				$(rc_content).css({	position: 'relative', backgroundImage: "url('"+imgMC+"')"});
				if (!(options==null) && !(options.alternative==null)) {
					$(newobj).css(options.alternative);
				}
			}
			
			$(rc_wrap).append(rc_content);

			if (!(options==null)) {
				if (!(options.id == null)) {
					$(rc_wrap).attr("id",options.id);
				}
				if (!(options.aclass == null)) {
					$(rc_wrap).attr("class",options.aclass);
				}
				if (!(options.position == null)) {
					$(rc_wrap).css("position",options.position);
				}

			}

			$(rc_content).append(newobj);

			$(this).replaceWith(rc_wrap);

			if (!(options==null)) {
				if (!(options.hidden == null) && options.hidden == true) {
					$(rc_wrap).hide();
				}
			}
		}
		);
	}
};
jQuery.fn.dpAccordion = jQuery.iDpAccordion.build;
jQuery.fn.dpSize = jQuery.DpSize.dpgetsize;
jQuery.fn.dpCorners = jQuery.DpCorners.build;
