function Frontpage() {
	this.fullWidth = "490px";
	this.halfWidth = "238px";
	this.fullHeight = "250px";
	this.halfHeight = "120px";
	this.baseUrl = "/TKdkcms/uploads/frontpage/";
	this.swfList = [];
}
Frontpage.prototype.run = function() {
	this.swfList = [];
	
	json(
		"frontpage",
		{}, 
		bind(this.showFrontpage, this)
	);
}
Frontpage.prototype.showFrontpage = function(result) {
	// welcome text, search box
	replaceChildNodes(
		"mainpage",
		DIV(
			{'id':"page", 'class' : "front"},
			DIV(
				{'class':"light"},
				H2(null,result.description),
				result.page.contents
			),
			DIV(
				{'class':"search"},
				H2({},"Søg"),
				FORM({
						'id'		:"form_frontsearch",
						'method'	:"get",
						'action'	:"page",
						'onsubmit'	:"return search.search(this,$('frontpage-loader-input'));"
					},
					FIELDSET(null,
						INPUT({
							'type'	:"hidden",
							'value'	:"search",
							'name'	:"action"
						}),
						LABEL({
								'for'	:"search"
							},
							"Skriv et søgeord her"
						),
						BR(),
						INPUT({
							'id'	:"frontsearch_input",
							'type'	:"text",
							'name'	:"q",
							'size'	: 20
						}),
						INPUT({
							'class'	:"searchbutton",
							'type'	:"submit",
							'value'	:"Søg"
						}),
						createLoader({id:'frontpage-loader-input', cssClass:'frontpage-loader'})
					),
					FIELDSET({},
						LABEL({
								'for'	:"need"
							},
							"...eller vælg et emne her"
						),
						BR(),
						SELECT({
								'id'	:"frontsearch_need",
								'name'	:"need",
								'onchange':"return search.search($('form_frontsearch'),$('frontpage-loader-select'));"
							},
							OPTION({
								'value'	:"__empty__"
							}),
							map( function(a){return OPTION({'value':a.value},a.text);},result.tagTextsList)
						),
						createLoader({id:'frontpage-loader-select', cssClass:'frontpage-loader'})
					)					
				)
				,BR({
					'class'	:"clear"
				})
			)
			,DIV({'class':"campaign",'id':"campaign"})
		)
	);
	colapseMenu();
	collapseAll();
	
	
	var box = result.page.data;
	//campaign box
	bind(this.drawType[box.layoutType], this, box)();
	//swfObject can't return DOM with flash, object stored in drawType to write into div see: selectBoxType(), addSwf(), getFlash()
	forEach(this.swfList, function(swf) {swf.write();});
	
}

Frontpage.prototype.drawType = [];
Frontpage.prototype.drawType[1] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_hor"
			 ,'style'	:"margin-bottom: 11px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getHorizontalFlash
				,this.getHorizontalImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_hor"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getHorizontalFlash
				,this.getHorizontalImage
				,"box2"
			)
		)
	);
}
Frontpage.prototype.drawType[2] = function(box) {
		appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_hor"
			 ,'style'	:"margin-bottom: 5px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getHorizontalFlash
				,this.getHorizontalImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin: 5px 0 5px 5px;"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box3LayoutType  /*Floating right so 3 before 2*/
				,box.box3LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box2"
			)
			
		)
		,DIV({
			   'class'	:"campaign_box"
			 ,'style'	:"margin: 5px 5px 5px 0;"
			  ,'id'		:"box3"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box3"
			)
		)
	);
}
Frontpage.prototype.drawType[3] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin: 0 0 5px 5px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin: 0 5px 5px 0;"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box2"
			)
			
		)
		,DIV({
			   'class'	:"campaign_box"
			  ,'style'	:"margin: 5px 0 5px 5px;"
			  ,'id'		:"box3"
			},
			this.selectBoxType(
				 box.box3LayoutType
				,box.box3LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box3"
			)
		)
		,DIV({
			   'class'	:"campaign_box"
			  ,'style'	:"margin: 5px 5px 5px 0;"
			  ,'id'		:"box4"
			},
			this.selectBoxType(
				 box.box4LayoutType
				,box.box4LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box4"
			)
		)
	);
}
Frontpage.prototype.drawType[4] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin: 0 0 5px 5px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin: 0 5px 5px 0;"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box2"
			)
			
		)
		,DIV({
			  'class'	:"campaign_hor"
			 ,'style'	:"margin-top: 5px;"
			 ,'id'		:"box3"
			},
			this.selectBoxType(
				 box.box3LayoutType
				,box.box3LayoutValue
				,this.getHorizontalFlash
				,this.getHorizontalImage
				,"box3"
			)
		)
	);
}
Frontpage.prototype.drawType[5] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_ver"
			 ,'style'	:"margin-left: 11px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getVerticalFlash
				,this.getVerticalImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_ver"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getVerticalFlash
				,this.getVerticalImage
				,"box2"
			)
			
		)
	);
}
Frontpage.prototype.drawType[6] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin-bottom: 8px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_ver"
			 ,'style'	:"margin-right: 11px;"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getVerticalFlash
				,this.getVerticalImage
				,"box2"
			)
			
		)
		,DIV({
			   'class'	:"campaign_box"
			  ,'id'		:"box3"
			},
			this.selectBoxType(
				 box.box3LayoutType
				,box.box3LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box3"
			)
		)
	);
}
Frontpage.prototype.drawType[7] = function(box) {
	appendChildNodes("campaign",
		 DIV({
			  'class'	:"campaign_ver"
			 ,'style'	:"margin-left: 11px;"
			 ,'id'		:"box1"
			},
			this.selectBoxType(
				 box.box3LayoutType
				,box.box3LayoutValue
				,this.getVerticalFlash
				,this.getVerticalImage
				,"box1"
			)
		)
		,DIV({
			  'class'	:"campaign_box"
			 ,'style'	:"margin-bottom: 8px;"
			 ,'id'		:"box2"
			},
			this.selectBoxType(
				 box.box2LayoutType
				,box.box2LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box2"
			)
			
		)
		,DIV({
			   'class'	:"campaign_box"
			  ,'id'		:"box3"
			},
			this.selectBoxType(
				 box.box1LayoutType
				,box.box1LayoutValue
				,this.getSmallFlash
				,this.getSmallImage
				,"box3"
			)
		)
	);
}
Frontpage.prototype.drawType[8] = function(box) {
	appendChildNodes("campaign",
		this.selectBoxType(
			 box.box1LayoutType
			,box.box1LayoutValue
			,this.getLargeFlash
			,this.getLargeImage
			,"campaign"
		)
	);
	
}
Frontpage.prototype.addSwf = function(swf,id) {
	this.swfList[this.swfList.length] = {
		'write': function() {
			this.swfCallback().write(id);		
		}
		,'swfCallback':swf
		,'id' :id
	};
}
Frontpage.prototype.selectBoxType = function(type, value, flashCallback, imageCallback, id) {
	switch(type) {
	case 1: //flash
		this.addSwf(bind(flashCallback, this, value), id);
		break;
	case 2: //image
		return bind(imageCallback, this, value.split(',')[1], value.split(',')[0]);
	case 3: //text
		return this.getTextBox(value);
	}
}
Frontpage.prototype.getTextBox = function(text) {
	var div = DIV({'class':"campaign_text"});
	div.innerHTML = text;
	
	return div;
}
Frontpage.prototype.getFlash = function(url,width,height) {
	var swf = new SWFObject(this.baseUrl + url, "flashBanner", width, height, "8", "#ffffff");
	swf.addParam("quality", "high");
	swf.addParam("base", this.baseUrl);
	swf.addParam("align", "middle");
	swf.addParam("allowScriptAccess", this.baseUrl);
	swf.addParam("wmode", "transparent");
	
	return swf;
}
Frontpage.prototype.getHorizontalFlash = function(url) {	return this.getFlash(url, this.fullWidth, this.halfHeight); }
Frontpage.prototype.getSmallFlash = function(url) { 		return this.getFlash(url, this.halfWidth, this.halfHeight); }
Frontpage.prototype.getVerticalFlash = function(url) { 		return this.getFlash(url, this.halfWidth, this.fullHeight); }
Frontpage.prototype.getLargeFlash = function(url) {			return this.getFlash(url, this.fullWidth, this.fullHeight); }

Frontpage.prototype.getImage = function(url,src,width,height) {
	return A({'href':url},
		IMG({
			 'src'		:this.baseUrl + src
			,'style'	:"width: " + width + "; height: " + height + ";"
		})
	);
}
Frontpage.prototype.getHorizontalImage = function(url, src){return this.getImage(url, src, this.fullWidth, this.halfHeight); }
Frontpage.prototype.getSmallImage = function(url, src) { 	return this.getImage(url, src, this.halfWidth, this.halfHeight); }
Frontpage.prototype.getVerticalImage = function(url, src) { return this.getImage(url, src, this.halfWidth, this.fullHeight); }
Frontpage.prototype.getLargeImage = function(url) { 		return this.getImage(url, src, this.fullWidth, this.fullHeight); }

addLoadEvent(function () {
	frontpage = new Frontpage();
});

function fixFF(){
	if (navigator && navigator.appCodeName=="Mozilla"){
		setNodeAttribute(document.getElementsByTagName("embed")[1],"wmode","transparent");
        if ( document.getElementsByTagName("embed")[1] ) {
		    document.getElementsByTagName("embed")[1].style.display="none";
		    document.getElementsByTagName("embed")[1].style.display="block";
	    }
	}	
}
setTimeout("fixFF()",5000);