function addCssRules(css) {
	var head, styleElement;
	head = document.getElementsByTagName('head')[0];
	if (!head) { return; }
	styleElement = document.createElement("style");
	styleElement.type = 'text/css';
   
	if (styleElement.styleSheet) {
		styleElement.styleSheet.cssText = css;
	} else {
		styleElement.textContent = css;
	}
	head.appendChild(styleElement);
}
function shop_teaser(){
	if($('#overlay')){
		addCssRules(
			'#gw_teaser{position:absolute; background:#FFFFFF; border: 1px solid #D8001a; padding: 0 18px 5px;'
			+'margin-bottom: 20px; width: 582px; overflow:hidden; height:273px;z-index:10;'
			+'-moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px;}'
			+'#gw_teaser .content {clear:left;padding-top:1px;}'
			+'#gw_teaser .content h2{color:#707173; margin:1em 0 1ex;}'
			+'#gw_teaser #price{display:block; margin:1ex 0;font-weight:bold;}'
			+'#gw_teaser #price span{color:#d8001a;}'
			+'#gw_teaser #gw_hdr { background: #D8001a; color: #FFF; margin: 0 -18px; padding: 7px 18px; width:45%;'
			+'-moz-border-radius-bottomright:3px; -webkit-border-right-radius:3px; border-right-radius:3px;}'
			+'#gw_teaser #productimg {float:right; margin-top:18px; margin-left:18px; max-width: 250px; border:0;max-height: 220px;}'
			//+'#gw_teaser #gw_goimg {position:absolute;}'
		);
		var url_prefix="http://www.ricosta.de/shop/";
		var maxlength=460;
		$.ajax({
			url:"http://www.ricosta.de/shop/xhr.php?a=teaser"
			,async:false
			,timeout:2000
			,success: function(res) {
				var doc=$(res);
				var realUrl=doc.siblings('link[rel="canonical"]')[0].href;
				var txt=doc.find('#product');
				txt.removeAttr('id');
				$(txt).find('p+p').remove();
				var para=$(txt).find('h2+p');
				var descr_txt=para[0].innerHTML;
				if(descr_txt.length>maxlength){
					para[0].innerHTML=descr_txt.slice(0,maxlength)+'...';
				}
				
				var link=document.createElement('a');
				link.href=realUrl;
				var pimg=doc.find('#productimg');
				var imgName=pimg[0].src.substr(pimg[0].src.lastIndexOf('/'));
				pimg[0].src=url_prefix+'img/products/'+imgName;
				pimg.removeAttr('width');
				
				link.appendChild(pimg[0]);
				
				var priceEl=document.createElement('p');
				var currencyEl=txt.find('#itemprice').parent()[0];
				var currency=currencyEl.innerText || currencyEl.textContent;
				var priceVal=txt.find('#itemprice').attr('value');
				priceEl.id='price';
				txt.find('#pd').remove();
				priceEl.innerHTML='Jetzt ab <span>'+currency+' '+priceVal+'</span>';
				
				/*
				var shopLink=document.createElement('a');
				shopLink.textContent='weiter zum Online Shop';
				var shopLinkP=document.createElement('p');
		
				shopLink.href=realUrl;
				shopLinkP.appendChild(shopLink);
				
				var goImg=document.createElement('img');
				goImg.src="http://www.ricosta.de/img/content/button_shop_280_de.png";
				goImg.id='gw_goimg';*/
		
				var header=document.createElement('div');
				header.textContent='Aus unserem Shop-Angebot:';
				header.innerText='Aus unserem Shop-Angebot:';
				header.id='gw_hdr';
				var wrap=document.createElement('div');
				wrap.id='gw_teaser';
		
				wrap.appendChild(header);
				wrap.appendChild(link);
				wrap.appendChild(txt[0]).appendChild(priceEl);
				//wrap.appendChild(shopLinkP);
				$('#overlay').prepend(wrap);
			}
		});
	}
}
