

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions

// style switch: liquid <> fixed
function setPagewidth(){

  	var currentWidth = $('#page').css('width');
   //	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    if (currentWidth=="95%") newWidth = "960px";
    else if (currentWidth=="960px") newWidth = "95%";
    else newWidth = "960px";
	$('#page').css('width', newWidth);

  createCookie('pageWidth', newWidth, 365);
}

function initTooltips(o) {

	var showTip = function() {
		var el = $('.tip', this).css('display', 'block')[0];

		var ttHeight = $(el).height();
		var ttOffset =  el.offsetHeight;
		var ttTop = ttOffset + ttHeight;

		$('.tip', this)
			.stop()
			.css({
				'opacity': 0,
				'top': 2 - ttOffset
			})
			.animate({
				'opacity': 1,
				'top': 18 - ttOffset
			}, 250);
	};

	var hideTip = function() {

		var self = this;
		var el = $('.tip', this).css('display', 'block')[0];

		var ttHeight = $(el).height();
		var ttOffset =  el.offsetHeight;
		var ttTop = ttOffset + ttHeight;

		$('.tip', this)
			.stop()
			.animate({
				'opacity': 0,
				'top': 10 - ttOffset
			}, 250, function() {
				el.hiding = false;
				$(this).css('display', 'none');
			});


	};

	$('.tip').hover(
		function() { return false; },
		function() { return true; }
	);

	$('.tiptrigger, .cat-item').hover(
		function(){
			var self = this;
			showTip.apply(this);
			if (o.timeout) this.tttimeout = setTimeout(function() { hideTip.apply(self) } , o.timeout);
		},
		function() {
			clearTimeout(this.tttimeout);
			hideTip.apply(this);
		}
	);

}

function tabmenudropdowns(){
//$(" #tabs ul ").css({display: "none"}); // Opera Fix
$(" #tabs li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(333);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

// fade background position (not used yet ;)
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);