SNIPPETS = {
	added_to_basket: 'Artikel wurde dem Warenkorb hinzugefügt.  <a href="#">Warenkorb anzeigen</a> <a href="#">Zur Kasse gehen</a>'
};
COLORS = {
	alert: '#ff6b1c' ,
	basket: '#d6ffa7'
}


function addJavascriptCSS() {
//	var header = document.getElementsByTagName('head')[0];
//	new Insertion.After( header , '<link rel="stylesheet" href="css/praeser-jsonly.css" type="text/css" media="screen" title="no title" charset="utf-8" />' );
}
addJavascriptCSS();


/* --------------------------------*/
// common //

praeser = {
	// called when page has loaded
	init: function() {
		//css_browser_selector();
		praeser.subnav.init();
		praeser.tooltip.init();
		praeser.datechooser.init();
		praeser.style.useagain('praeserstyle');
	} ,
	// called when script is loaded (not dom)
	prepare: function() {
		praeser.style.useagain('praeserstyle');
	} ,
	finish: function() {
		praeser.style.remember('praeserstyle',60);
	} ,
	
	// style
	style: {
		getall: function() {
			if( !window.ScriptEngine && navigator.__ice_version ) { return document.styleSheets; }
			if( document.getElementsByTagName ) { var Lt = document.getElementsByTagName('link'), St = document.getElementsByTagName('style');
			} else if( document.styleSheets && document.all ) { var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
			} else { return []; } for( var x = 0, os = []; Lt[x]; x++ ) {
				var rel = Lt[x].rel ? Lt[x].rel : Lt[x].getAttribute ? Lt[x].getAttribute('rel') : '';
				if( typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) { os[os.length] = Lt[x]; }
			} for( var x = 0; St[x]; x++ ) { os[os.length] = St[x]; } return os;
		} , 
		activate: function() {
			window.userHasChosen = window.MWJss;
			for( var x = 0, ss = praeser.style.getall(); ss[x]; x++ ) {
				if( ss[x].title ) { ss[x].disabled = true; }
				for( var y = 0; y < arguments.length; y++ ) { if( ss[x].title == arguments[y] ) { ss[x].disabled = false; } }
		} } ,
		remember: function( cookieName, cookieLife ) {
			for( var viewUsed = false, ss = praeser.style.getall(), x = 0; window.MWJss && MWJss[x] && ss[x]; x++ ) { if( ss[x].disabled != MWJss[x] ) { viewUsed = true; break; } }
			if( !window.userHasChosen && !viewUsed ) { return; }
			for( var x = 0, outLine = '', doneYet = []; ss[x]; x++ ) {
				if( ss[x].title && ss[x].disabled == false && !doneYet[ss[x].title] ) { doneYet[ss[x].title] = true; outLine += ( outLine ? ' MWJ ' : '' ) + escape( ss[x].title ); } }
			if( ss.length ) { document.cookie = escape( cookieName ) + '=' + escape( outLine ) + ( cookieLife ? ';expires=' + new Date( ( new Date() ).getTime() + ( cookieLife * 86400000 ) ).toGMTString() : '' ) + ';path=/'; }
		} ,
		useagain: function( cookieName ) {
			for( var x = 0; x < document.cookie.split( "; " ).length; x++ ) {
				var oneCookie = document.cookie.split( "; " )[x].split( "=" );
				if( oneCookie[0] == escape( cookieName ) ) {
					var styleStrings = unescape( oneCookie[1] ).split( " MWJ " );
					for( var y = 0, funcStr = ''; styleStrings[y]; y++ ) { funcStr += ( y ? ',' : '' ) + 'unescape( styleStrings[' + y + '] )'; }
					eval( 'praeser.style.activate(' + funcStr + ');' ); break;
			} } window.MWJss = []; for( var ss = praeser.style.getall(), x = 0; ss[x]; x++ ) { MWJss[x] = ss[x].disabled; }
		}
	} , 
	
	// tooltip
	tooltip: {
		active: null ,
		show: function( elem ) {
			if ( elem == praeser.tooltip.active ) return;
			praeser.tooltip.active = elem;

			var msg = $('#tooltip');

			if ( elem ) {
				elem = $(elem);
				var content = $(elem).parent().find('.tooltipcontent');
				var msg_content = msg.find('.border');
				content = content.length ? content[0].innerHTML : elem.attr('title');
				if ( !content.length ) { alert('no content:'+content); return false; }
				msg_content.html( content );

				var direction = elem.attr('class').split(' ')[1];
				msg.attr( 'class' , direction );

				// position
				var pos = getElementPosition( elem );
				var dx = Math.round( elem.outerWidth() / 2 );
				var dy = Math.round( elem.outerHeight() / 2 );
				switch ( direction ) {
					case 'tooltipdown': dy *= 2; break;
					case 'tooltipup': dy = 0;
					case 'tooltipleft': dx = 0;
					case 'tooltipright': dx *= 2;
				}
				var pos = { 'left': ( pos.x + dx ) + 'px' , 'top': ( pos.y + dy ) + 'px' };
				//alert( msg.css('display') );
				if ( false && msg.css('display') != 'none' ) {
					msg.animate( pos , 0.5 , 'swing' );
				} else {
					msg.css( pos );
				}
				msg.stop().css('display','block').animate({opacity:1},300,'linear');
				if (console ) console.log('show');
			}
		} ,
		hide: function() {
			if (console ) console.log('hide');
			var msg = $('#tooltip');
			msg.stop().animate({opacity:0},700,'linear',function(){msg.hide()});
			praeser.tooltip.active = null;
		} ,
		init: function() {
			var tooltips = $( '.tooltip' );
			$('#tooltip').css('visibility','visible').css('display','none').css('opacity',0);
			var show = function() { praeser.tooltip.show(this); };
			var hide = function() { praeser.tooltip.hide(); };
			for ( var i=0 ; i<tooltips.length ; i++ ) {
				var isInput = tooltips[i].nodeName.toLowerCase() == 'input';
				$(tooltips[i])[ isInput ? 'focus' : 'mouseover' ]( show );
				$(tooltips[i])[ isInput ? 'blur' : 'mouseout' ]( hide );
			}
		}
	} , // end tooltip
	
	// subnav
	subnav: {
		init: function() {
			var e = $('#subnavigation a').click( function() { return praeser.subnav.toggle(this); } );
		} ,
		toggle: function( elem ) {
			$(elem).parent().siblings().removeClass('selected');
			if ( $(elem).parent().children('ul').length ) {
				$(elem).parent().toggleClass('selected');
				return false;
			} else {
				return true;
			}
		}
	} // end subnav
	,
	// datechooser
	datechooser: {
		init: function() {
			return;
		} ,
		update: function() {
			
		}
	}
}

function getElementPosition(obj) {
	obj = $( obj );
	return {x: obj.offset().left, y: obj.offset().top};
}


function toggleClassName( elem , name ) {
	$(elem).toggleClass( name );
}

function hasClassName( elem , value ) {
	return $(elem).hasClass(value);
}



/* --------------------------------*/
// navigation //






/* --------------------------------*/
// resizing //

var isBig = true;
window.onload = function() {
	ie_fix();
	praeser.init();
}

window.onunload = function() {
	praeser.finish();
}


function ie_fix() {
	return;
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ( document.all ) {
		// that's for layout purposes - necessary because ie doesn't know selector:after
		// var alldivs = document.getElementsByTagName('div');
		// for ( var i=0 ; i<alldivs.length ; i++ ) {
		// 	var div = alldivs[i];
		// 	if ( hasClassName( div , 'content') ) {
		// 		var newdiv = document.createElement('div');
		// 		newdiv.className = 'clearfloat';
		// 		newdiv.appendChild( document.createTextNode(' ') );
		// 		div.appendChild( newdiv );
		// 	}
		// }
		var alldivs = $$('div.content');
		for ( var i=0 ; i<alldivs.length ; i++ ) {
			var div = alldivs[i];
			var newdiv = document.createElement('div');
			newdiv.className = 'clearfloat';
			newdiv.appendChild( document.createTextNode(' ') );
			div.appendChild( newdiv );
		}
		// when user clicks on image in an article list, ie wouldn't follow the link
		// the following loop-through fixes this bug
		var links = document.getElementsByTagName('a');
		for ( var i=0 ; i<links.length ; i++ ) {
			var link = links[i];
			if ( link.parentNode.parentNode.className.indexOf('artlist_') >= 0 ) {
				link.onclick = function() { document.location.href = this.getAttribute('href'); return false; };
			}
		}
		ie_transparentpng();
	}
}

function ie_transparentpng() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {

		var i, elements;
		var src_spacer = "https://www.praeser.ch/media/shared/spacer.gif";

		elements = document.getElementsByTagName("img");
		for (var i=0; i<document.images.length; i++) {
			var img = document.images[i];
			var imgName = img.src.toLowerCase();
			if (imgName.substring(imgName.length-3, imgName.length) != "png") continue;

			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='" + img.src	+ "', sizingMethod='image')";
			img.src = src_spacer;

		}

		elements = document.getElementsByTagName("input");
		for (i = 0; i < elements.length; i++) {
			var input = elements[i];
			if (input.getAttribute("type") != "image") continue;
			var imgName = input.getAttribute("src").toLowerCase();
			if (imgName.substring(imgName.length-3, imgName.length) != "png") continue;

			input.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='" + input.src	+ "', sizingMethod='image')";
			input.src = src_spacer;
		}
	}
}

// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var 
		ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();



// shopping //


function reportError(request) {
	alert('Sorry. There was an error.');
}


function toggleOption( checkbox , prefix , container ) {
	var cbox = checkbox;
	var cwrap = $(container);
	var elems_yes = cwrap.find('.'+prefix+'selected').css( { 'display' : cbox.checked ? 'block' : 'none' } );
	var elems_no = cwrap.find('.'+prefix+'unselected').css( { 'display' : !cbox.checked ? 'block' : 'none' } );
}




// rating

function rating_mouse2percent( obj , evt ) {
	var offsets = getEventOffsets( evt );
	var percent =  offsets.offsetX / obj.offsetWidth * 100;
	if ( percent < 10 ) return 0;
	else return Math.min( 100 , ( Math.floor( percent / 20 ) + 1 ) * 20 );
}

function rating_progresselem( obj ) {
	var p = obj.childNodes[0].childNodes;
	for ( var i=0 ; i<p.length ; i++ ) {
		if ( p[i].className == 'progress' ) {
			return p[i];
		}
	}	
}

function rating_setprogress( obj , percent ) {
	rating_progresselem( obj ).style.width = percent + '%';
}

function rating_setvalue( obj , percent ) {
	var p = obj.parentNode.childNodes[1];
	p.value = percent;	
}

function rating_getvalue( obj ) {
	var p = obj.parentNode.childNodes[1];
	return parseInt( p.value );	
}

// html event handlers

function rating_move( obj , evt ) {
//	rating_progresselem( obj ).style['background-color'] = '#333333';
	rating_setprogress( obj , rating_mouse2percent( obj , evt ) );
}
function rating_stop( obj , evt ) {
	rating_setprogress( obj , rating_getvalue( obj ) );
}
function rating_set( obj , evt ) {
	var v = rating_mouse2percent( obj , evt );
	rating_setprogress( obj , v );
	rating_setvalue( obj , v );
}

function getEventOffsets (evt) {
	if ( evt.offsetX != undefined ) {
		return { offsetX: evt.offsetX , offsetY: evt.offsetY };
	}
  var target = evt.target;
  if (typeof target.offsetLeft == 'undefined') {
    target = target.parentNode;
  }
  var pageCoords = getPageCoords(target);
  var eventCoords = { 
    x: window.pageXOffset + evt.clientX,
    y: window.pageYOffset + evt.clientY
  };
  var offsets = {
    offsetX: eventCoords.x - pageCoords.x,
    offsetY: eventCoords.y - pageCoords.y
  }
  return offsets;
}

function getPageCoords (element) {
  var coords = {x : 0, y : 0};
  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
    element = element.offsetParent;
  }
  return coords;
}


// notification

function closeNotify( closelink ) {
	var $box = $(closelink).parent().parent();
	$box.animate( { opacity: 0 , 'height':'toggle' , 'margin-bottom': -10 } , 500 , 'swing' , function() { $(this).remove() } );
	//$(closelink).parent().parent().fadeOut( function() { $(this).remove() } );
	$box.slideUp();
}

function appearBox( id ) {
	var elem = $(id);
	if ( elem.length == 0 ) { elem = $('#'+id); }
	elem.slideDown();
}


praeser.prepare();









// article detail


function zoomArtDetailImage( src ) {
	var box = document.getElementById( 'zoomimage' );
	var content = document.getElementById( 'zoomimagecontent' );
	toggleClassName( box , 'selected' );
	content.innerHTML = '<img src="' + src + '">';
}

function closeArtDetailImage() {
	var box = document.getElementById( 'zoomimage' );
	toggleClassName( box , 'selected' );
}













/*
 * jQuery Simple Templates plugin 1.1.1
 *
 * http://andrew.hedges.name/tmpl/
 * http://docs.jquery.com/Plugins/Tmpl
 *
 * Copyright (c) 2008 Andrew Hedges, andrew@hedges.name
 *
 * Usage: $.tmpl('<div class="#{classname}">#{content}</div>', { 'classname' : 'my-class', 'content' : 'My content.' });
 *
 * The changes for version 1.1 were inspired by the discussion at this thread:
 *   http://groups.google.com/group/jquery-ui/browse_thread/thread/45d0f5873dad0178/0f3c684499d89ff4
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html

(function($) {
    $.extend({
    	// public interface: $.tmpl
    	tmpl : function(tmpl, vals) {
    		var rgxp, repr;
    		
			// default to doing no harm
			tmpl = tmpl   || '';
			vals = vals || {};
    		
    		// regular expression for matching our placeholders; e.g., #{my-cLaSs_name77}
    		rgxp = /#\{([^{}]*)}/g;
    		
    		// function to making replacements
    		repr = function (str, match) {
				return typeof vals[match] === 'string' || typeof vals[match] === 'number' ? vals[match] : str;
			};
			
			return tmpl.replace(rgxp, repr);
		}
	});
})(jQuery);
*/



/*
jQuery toJSON

(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);


*/

