function clearSearch(t) {
	if(t.value==lang('SEARCHWORD')) {
		t.value='';
	}
}
function fillSearch(t) {
	if(t.value=='') {
		t.value=lang('SEARCHWORD');
	}
}
function autoUpdateFormField(t,old,focusblur) {
	if(!focusblur) {
		if(t.value==old) {
			t.value='';
		}
	}
	else {
		if(t.value=='') {
			t.value=old;
		}
	}
}
var curnid='';
function switchButtons(showid,nid,evt) {
	curnid=nid;
	if($(showid).visible()) {
		$(showid).hide();
		Event.stopObserving(document.body, 'click', hideAllSwitchButtons);
		return false;
	}
	hideAllSwitchButtons(evt,true);
	$(showid).show();
	Event.stop(evt);
	Event.observe(document.body, 'click', hideAllSwitchButtons);
	/*
	$$('#socialbuttons'+nid+' li').each(function (elm) {
		if(elm.id != $(showid).id) {
			elm.hide();
		}
		else {
			elm.show();
		}
	});
	*/
	return false;
}
function hideAllSwitchButtons(evt,all) {
	if(all) {
		$$('#socialbuttons'+curnid+' li').each(function (elm) {
			elm.hide();
		});	
	}
	else {
		var elm=Event.element(evt);
		var soc = elm.up('ul.socialbuttons');
		if(typeof(soc)=='undefined' || soc==document) {
			$$('#socialbuttons'+curnid+' li').each(function (elm) {
				elm.hide();
			});	
		}
	}
}	
var flashvars;
function copyToClipBoard(text,parentId) {
	var html='';
	var movieId = 'clipboardflash';
	flashvars=text;
	var width = 20;
	var height = 20;
	width = $('copybutton').getWidth();
	height = $('copybutton').getHeight();
	if (Prototype.Browser.IE) {
		html = '<object style="top: 0; right: 0; z-index: 2; position: absolute;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+ width +'" height="'+ height +'" id="'+movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="/admin/script/copyuri.swf" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent"/></object>';
	}
	else {
		html = '<embed style="top: 0; right: 0; z-index: 2; position: absolute" id="'+ movieId +'" src="/admin/script/copyuri.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+ width +'" height="'+ height +'" name="'+ movieId +'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" />';
	}
	$('copybuttonholder').innerHTML += html;
	$('bloggabout').hide();
	$('bloggabout').setStyle({top: '-72px', left: '54px'});
	if(Prototype.Browser.Gecko) {
		$('emailer').setStyle({top: '-82px', left: '88px'});	
	} 
}
function getEmbedTag() {
	alert('Koden är kopierad, klistra in den i din blogg.');
	hideAllSwitchButtons('',true);
	return flashvars;	
}
var LeksandsBrod=Class.create();
LeksandsBrod.prototype={
	initialize:function(){
		this.objecsrc='';
		this.rec='';
	},
	swapImage:function(evt){
		var elm=Event.element(evt);
		$('swapimageholder').update('<img id="obj_prodimage-0-'+web_iso_language+'" src="'+$(elm.id+'-full').src+'" alt="bild" />');		
	},
	swapOrigImage:function(evt){
		var elm=Event.element(evt);
		$('obj_prodimage-0-'+web_iso_language).src=LBImg.objectsrc;
	},
	setBackObject:function(evt){
		var elm=Event.element(evt);
		LBImg.objectsrc=$(elm.id+'-full').src;
	},
	addEventListeners:function(elm){
			elm.setStyle({cursor:'pointer'});
			var mo=LBImg.swapImage.bindAsEventListener();
			var mout=LBImg.swapOrigImage.bindAsEventListener();
			var cl=LBImg.setBackObject.bindAsEventListener();
			Event.observe(elm,'mouseover',mo,false);
			Event.observe(elm,'mouseout',mout,false);
			Event.observe(elm,'click',cl,false);
	},
	getHighResObject:function(){
		document.location='/mod/localoo.php?file='+encodeURIComponent(LBImg.objectsrc);
	},
	fixSizes:function() {
		var wid = document.viewport.getWidth();
		if(wid <= 960) {
			$('kurbitsr').hide();
			$('footerinner').setStyle({width:'1153px'});
			$('wrapper').setStyle({'overflow':'visible'});
		}
		else {
			$('kurbitsr').show();
			$('wrapper').setStyle({'overflow':'hidden'});
			$('footerinner').setStyle({'width':'1400px'});
		}
	},
	fixScrollTo:function(elm) {
		if($(elm.key)) {
			Event.observe($(elm.key).down('a'),'click', function(e) {Effect.ScrollTo(elm.value,{duration: 1}); Event.stop(e);},false);
		}
	},
	fireLightbox:function(lbid) {
		if($('lb-'+lbid)) {
			myLightBox.start($('lb-'+lbid));
		}
	},
	preparePages:function(parentId) {
		new Ajax.Request('/mod/ajax.php', {method:'post', postBody:'doAJAX=getFlashPages&pId='+parentId, onSuccess:LBImg.insertFlashPages});	
	},
	insertFlashPages:function(t) {
		$(document.body).insert('<div style="display:none;">'+t.responseText+'</div>');
		myLightBox.updateImageList();		
	}
}
LBImg=new LeksandsBrod();
function productImageSwapper() {
	LBImg.rec=$('obj_prodimage-0-'+web_iso_language);
	LBImg.objectsrc = LBImg.rec.src;
	if(!pageEdit){
		$A($$('img.imageswapper')).each(LBImg.addEventListeners);
		Event.observe($$('a.recept-ladda-ner')[0],'click',LBImg.getHighResObject,false);
	}
}
function changeVideo(target,videoid) {
	var str = '';
	if(Prototype.Browser.IE) {
		str += '<object width="624" height="375" type="application/x-shockwave-flash" >';
	}
	else {
		str += '<object width="624" height="375" >';
	}
	str += '<param name="movie" value="http://www.youtube.com/v/'+ videoid + '&amp;hl=sv&amp;fs=1&amp;rel=0&amp;border=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
	str += '<embed src="http://www.youtube.com/v/'+videoid+'&amp;hl=sv&amp;fs=1&amp;rel=0&amp;border=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="624" height="375"></embed>';
	str += '</object>';
	$(target).update(str);
	return false;
}
var lastReqPId='';
var flashPages= [];
var lightbox = null;
function addFlashPage(pId) {
	flashPages = pId;
	flashPages = $A(flashPages);
}
function getPartOfPage(pId) {
	if (!lightbox) {
		$(document.body).insert('<div id="flashAjaxPages" style="display:none;"></div>');
		var flashAjaxPages = $('flashAjaxPages');
		flashPages.each(function(pageId) {
			flashAjaxPages.insert('<a class="lightbox-ajax" href="/mod/ajax.php?doAJAX=getPage&pId='+pageId+'" />');
		});
		lightbox = new DestinatorLightbox({next:'Nästa',prev:'Föregående',close:'Stäng',enableSensorClickInsideLightbox:false});
	}
	for(var i in flashPages) {
		if (flashPages[i] == pId) {
			lightbox.show(i);
			break;
		}
	}
}
function recivePage(t) {
	Lightbox.show();
}
Event.observe(window,'load', function() {
	LBImg.fixSizes();
	Event.observe(window,'resize',LBImg.fixSizes);
	if(!pageEdit) {	
		var anchorArray = $H({'menu_826':'pressanchor','menu_827':'logoanchor','menu_828':'prodanchor','menu_829':'receptanchor','menu_805':'narodlat','menu_806':'miljo','menu_807':'atervinning','menu_808':'policy'}); 
		anchorArray.each(LBImg.fixScrollTo);
	}
});
function sharePageHideHolder(t,ajax) {
	if(t.responseText == 'OK') {
		$('sharePageForm'+_sharepageformid).reset();
		$('sharepageformloader'+_sharepageformid).hide();
		$('sharepageformdiv'+_sharepageformid).show();
		$('emailer'+_sharepageformid).hide();
	}
}