// name = string equal to the name of the instance of the object
// defaultExpiration = number of units to make the default expiration date for the cookie
// expirationUnits = 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days')
// defaultDomain = string, default domain for cookies; default is current domain minus the server name
// defaultPath = string, default path for cookies; default is '/'
function Cookiemanager(name,defaultExpiration,expirationUnits,defaultDomain,defaultPath) {
	// remember our name
	this.name = name;
	// get the default expiration
	this.defaultExpiration = this.getExpiration(defaultExpiration,expirationUnits);
	// set the default domain to defaultDomain if supplied; if not, set it to document.domain
	// if document.domain is numeric, otherwise strip off the server name and use the remainder
	this.defaultDomain = (defaultDomain)?defaultDomain:(document.domain.search(/[a-zA-Z]/) == -1)?document.domain:document.domain.substring(document.domain.indexOf('.') + 1,document.domain.length);
	// set the default path
	this.defaultPath = (defaultPath)?defaultPath:'/';
	// initialize an object to hold all the document's cookies
	this.cookies = new Object();
	// initialize an object to hold expiration dates for the doucment's cookies
	this.expiration = new Object();
	// initialize an object to hold domains for the doucment's cookies
	this.domain = new Object();
	// initialize an object to hold paths for the doucment's cookies
	this.path = new Object();
	// set an onlunload function to write the cookies
	window.onunload = new Function (this.name+'.setDocumentCookies();');
	// get the document's cookies
	this.getDocumentCookies();
	}
// gets an expiration date for a cookie as a GMT string
// expiration = integer expressing time in units (default is 7 days)
// units = 'miliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days') 
Cookiemanager.prototype.getExpiration = function(expiration,units) {
	// set default expiration time if it wasn't supplied
	expiration = (expiration)?expiration:7;
	// supply default units if units weren't supplied
	units = (units)?units:'days';
	// new date object we'll use to get the expiration time
	var date = new Date();
	// set expiration time according to units supplied
	switch(units) {
		case 'years':
			date.setFullYear(date.getFullYear() + expiration);
			break;
		case 'months':
			date.setMonth(date.getMonth() + expiration);
			break;
		case 'days':
			date.setTime(date.getTime()+(expiration*24*60*60*1000));
			break;
		case 'hours':
			date.setTime(date.getTime()+(expiration*60*60*1000));
			break;
		case 'minutes':
			date.setTime(date.getTime()+(expiration*60*1000));
			break;
		case 'seconds':
			date.setTime(date.getTime()+(expiration*1000));
			break;
		default:
			date.setTime(date.getTime()+expiration);
			break;
		}
	// return expiration as GMT string
	return date.toGMTString();
	}
// gets all document cookies and populates the .cookies property with them
Cookiemanager.prototype.getDocumentCookies = function() {
	var cookie,pair;
	// read the document's cookies into an array
	var cookies = document.cookie.split(';');
	// walk through each array element and extract the name and value into the cookies property
	var len = cookies.length;
	for(var i=0;i < len;i++) {
		cookie = cookies[i];
		// strip leading whitespace
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		// split name/value pair into an array
		pair = cookie.split('=');
		// use the cookie name as the property name and value as the value
		//this.cookies[pair[0]] = pair[1];
		if (pair[0] == 'efaSize') {
            this.cookies[pair[0]] = pair[1];
            }
		}
	}
// sets all document cookies
Cookiemanager.prototype.setDocumentCookies = function() {
	var expires = '';
	var cookies = '';
	var domain = '';
	var path = '';
	for(var name in this.cookies) {
		// see if there's a custom expiration for this cookie; if not use default
		expires = (this.expiration[name])?this.expiration[name]:this.defaultExpiration;
		// see if there's a custom path for this cookie; if not use default
		path = (this.path[name])?this.path[name]:this.defaultPath;
		// see if there's a custom domain for this cookie; if not use default
		domain = (this.domain[name])?this.domain[name]:this.defaultDomain;
		// add to cookie string
		cookies = name + '=' + this.cookies[name] + '; expires=' + expires + '; path=' + path + '; domain=' + domain;
		document.cookie = cookies;
		}
	return true;
	}
// gets cookie value
// cookieName = string, cookie name
Cookiemanager.prototype.getCookie = function(cookieName) {
	var cookie = this.cookies[cookieName]
	return (cookie)?cookie:false;
	}
// stores cookie value, expiration, domain and path
// cookieName = string, cookie name
// cookieValue = string, cookie value
// expiration = number of units in which the cookie should expire
// expirationUnits = 'miliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days')
// domain = string, domain for cookie
// path = string, path for cookie
Cookiemanager.prototype.setCookie = function(cookieName,cookieValue,expiration,expirationUnits,domain,path) {
	this.cookies[cookieName] = cookieValue;
	// set the expiration if it was supplied 
	if (expiration) this.expiration[cookieName] = this.getExpiration(expiration,expirationUnits);
	// set path if it was supplied
	if (domain) this.domain[cookieName] = domain;
	if (path) this.path[cookieName] = path;
	return true;
	}

var cookieManager = new Cookiemanager('cookieManager',1,'years');






/**
* many JS help from Anja Bullin (thanks)
*/	
var tilesMenu = function() {
	var _count = 0;
	var _active = null;
	var _lis = null;
	
	var _fadeTileIn = function() {
		if (_count == _lis.length) {
			window.clearInterval(_active);
			return;
		}
		
		var _li = _lis[_count];
		$(_li).fadeIn('fast');
		
		_count++;	
	};
	
	var _animateIn = function() {
		_count = 0;

		var _subNav = $('ul', $(this));
		
		/**
		 * if sub navigation fades out but is still visible, then quit and set full opacity
		 */
					
		if (_subNav.css('display') == 'block') {
			_subNav.stop().css('opacity', 1);
			return;
		}
				
		_lis = $('li', _subNav);
				
		_subNav.show().css('left', 'auto');
		_lis.hide();
		
		/**
		 * fuer alle Browser ausser IE
		 */		 
		if (!$.browser.msie) {
			
			/**
			 * show menu tiles one by one 
			 */				
			_active = window.setInterval(_fadeTileIn, 30);
			return;
		}
		
		/**
		 * fuer den lahmen IE
		 */		 
		_lis.fadeIn('fast');
	};
	
	var _animateOut = function() {
	var _subNav = $('ul', $(this));
		
	_subNav.fadeOut('fast');
		
	window.setTimeout(function() {
		_subNav.css('left', '');
		}, 300);
	};

	this.animateOpacity = function() {
		$('.subnav').hide();
		
		/**
		 * show sub navigation after hover and hide after mouseout
		 */		 
		$('.nav > li').hover(_animateIn, _animateOut);
	};
	
	this.toggleOnSub = function() {
		if ($('body').hasClass('sub') === false) {
			return;
		}
		var _otherLis = $('.nav li').not('.nav li#home , .current, .act');
		_otherLis.hide();
			 
		$('.nav li#home').mouseenter(function() {
			_otherLis.fadeIn('fast');
		});
		$('.nav').mouseleave(function() {
			_otherLis.fadeOut('fast');
		});
	};
	
	this.showProductContent = function() {
		var productItems = $('#produkte li');
		
	if ($('body').hasClass('sub') !== false) {
		return;
	}
	
		productItems.click(function(event) {
			event.preventDefault();
			event.stopPropagation();
						
			var pid = this.id.split('produkteItem')[1];
			$('.infoblocks').hide();
			$('#productBlock' + pid).fadeIn('fast', function() {
				$('.subnav').fadeOut('fast').css('left', ''); 
			}); 
		});
	};
};

//$(document).ready(function () {

	//tilesMenu
//	var tMenu = new tilesMenu();
//	tMenu.animateOpacity();
//	tMenu.showProductContent();
//	tMenu.toggleOnSub();
//});



