this.vtip = function() {    
    this.xOffset = -10; // x distance from mouse
    this.yOffset = 10; // y distance from mouse       
    
    $(".tooltip").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="tooltip">' + this.t + '</p>' );
                        
            $('p#tooltip #vtipArrow').attr("src", 'images/vtip_arrow.png');
            $('p#tooltip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
            
        },
        function() {
            this.title = this.t;
            $("p#tooltip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
                         
            $("p#tooltip").css("top", this.top+"px").css("left", this.left+"px");
        }
    ).click(function() {
    	this.title = this.t;
    });            
    
};

projects = {
	theme: null,
	country: null,

	submitQueryDE: function ()
	{
//		var url = '/index.php?id=40&tx_ttnews[cat]=';
		var url = '/index.php?id=479&tx_ttnews[cat]=';
		if (projects.theme && projects.country)
			url = url + projects.theme + ',' + projects.country;
		if (projects.theme && !projects.country)
			url = url + projects.theme;
		if (!projects.theme && projects.country)
			url = url + projects.country;
		window.location.href = url;
	},
	
	submitQueryEN: function ()
	{
//		var url = '/index.php?id=40&tx_ttnews[cat]=';
		var url = '/index.php?id=479&tx_ttnews[cat]=';
		if (projects.theme && projects.country)
			url = url + projects.theme + ',' + projects.country;
		if (projects.theme && !projects.country)
			url = url + projects.theme;
		if (!projects.theme && projects.country)
			url = url + projects.country;
		window.location.href = url;
	},

	set: function (key, val)
	{
		if (key == "theme")
		{
			projects.theme = val;
			jQuery('ul.select-cont li:not(:first)').toggle();
		} else {
			projects.country = val;
			jQuery('ul.select-country li:not(:first)').toggle();
		}
		jQuery('li#'+key+val).toggle();
	}
};

products = {

	toggle: function (num)
	{
		var checkbox = jQuery('#del_'+num)[0];
		var img = jQuery('#img_'+num)[0];
		if (checkbox.checked == false)
		{
			checkbox.checked = true;
			img.src = '/images/icon-basket-removed.png';
		} else {
			checkbox.checked = false;
			img.src = '/images/icon-basket-remove.png';
		}
	}

}

font = {

	low: 13,
	high: 17,
	step: 1,

	init: function ()
 	{
		var size = getCookie('FontSize');
		if (!size)
			return;
		size = parseInt(size);
		if (size >= font.low &&
				size <= font.high)
			font.set(size);
	},
	plus: function ()
	{
		var cur = font.current();
		if (cur + font.step <= font.high)
			font.set(cur+font.step);
		return;
	},
	minus: function ()
	{
		var cur = font.current();
		if (cur - font.step >= font.low)
			font.set(cur-font.step);
		return;
	},
	current: function ()
	{
		var px = parseInt($('#main').css('font-size').replace(/px/g,''));
		return px;
	},
	set: function (px)
	{
		$('#header p').css('font-size',px+'px');
		$('#main').css('font-size',px+'px');
		$('#content').css('font-size',px+'px');
		var foo = new Date();
		foo.setTime(foo.getTime()+1000*3600*24);
		setCookie("FontSize",px,null,foo.toGMTString(),"/");
		return;
	}
};

zitatControl = {

	interval: null,
	timeout: null,
	active: 0,

	init: function () {
		this.blocks = $('blockquote',this);
		this.blocks.hide();
		$(this.blocks[0]).show();
		return;
	},

	toggle: function () {
		$(this.blocks[this.active]).hide();
		if (this.active+1 >= this.blocks.length)
			this.active = 0;
		else
			this.active++;
		$(this.blocks[this.active]).show();
	}

};

ecard = {

	show: function (obj) {
		var span = obj.parentNode.parentNode.parentNode;
		while (span.tagName !== 'SPAN')
			span = span.nextSibling;
		$.nyroModalManual({
			bgColor: '#000000',
			content: span.innerHTML,
			minHeight: 540,
			minWidth: 650
		});
		return false;
	},

	front: function (obj) {
		var span = obj.parentNode.parentNode.parentNode;
		$(span).hide();
		span = span.previousSibling;
		while (span.tagName !== 'SPAN')
			span = span.previousSibling;
		$(span).show();
	},

	back: function (obj) {
		var span = obj.parentNode.parentNode.parentNode;
		$(span).hide();
		span = span.nextSibling;
		while (span.tagName !== 'SPAN')
			span = span.nextSibling;
		$(span).show();
	},

	submit: function (obj) {
		while (obj.tagName !== 'FORM')
			obj = obj.parentNode;
		$.ajax({
			url: '/typo3conf/ext/12bis3_config/pi10/ecard.php',
			async: false,
			cache: false,
			data: $(obj).serialize(),
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				return false;
			},
			success: function (data, textStatus, XMLHttpRequest) {
				$('#nyroModalContent')[0].innerHTML = XMLHttpRequest.responseText;
			}
		});
	}

}

visualControl = {

	layers: null,
	interval: null,
	timeout: null,

	init: function () {
		visualControl.layers = new Array();
		layers = $('.visual');
		layers.each(function(index){
			visualControl.layers[index] = this.parentNode.parentNode;
		});
		for (var i = 1; i < visualControl.layers.length; i++) {
			$(visualControl.layers[i]).hide();
		}
		visualControl.genLinkList();
		visualControl.installInterval();
		return;
	},

	toggle: function () {
		for (var i = 0; i < visualControl.layers.length; i++) {
			var tmp = $(visualControl.layers[i]);
			if (tmp.is(':visible'))
			{
				tmp.hide();
				if ((i+1) == visualControl.layers.length)
					$(visualControl.layers[0]).show();
				else
					$(visualControl.layers[(i+1)]).show();
				break;
			}
		}
	},

	installInterval: function () {
		visualControl.interval = window.setInterval("visualControl.toggle()",13000);
		return;
	},

	show: function (index) {
		window.clearInterval(visualControl.interval);
		window.clearTimeout(visualControl.timeout);
		for (var i = 0; i < visualControl.layers.length; i++) {
			if (i == index)
				$(visualControl.layers[i]).show();
			else
				$(visualControl.layers[i]).hide();
		}
		visualControl.timeout = window.setTimeout("visualControl.installInterval()",15000);
		return;
	},

	genLinkList: function () {
		var list = document.createElement('div');
		var thumbs = $('.visual-thumbnail');
		for (var i = visualControl.layers.length -1; i >= 0; i--) {
			var a = document.createElement('a');
			a.href = "javascript: visualControl.show('"+i+"');";
			var img = document.createElement('img');
			// img.src = '/images/dummy-visual-teaser.jpg';
			img.src = thumbs[i].src;
			img.alt = 'dummy teaser';
			a.appendChild(img);
			list.appendChild(a);
		}
		thumbs.hide();
		for (var i = 0; i < visualControl.layers.length; i++) {
			visualControl.layers[i].appendChild(list.cloneNode(true));
			$(visualControl.layers[i].lastChild).addClass('visual-teaser');
		}
	}

};

jQuery(document).ready(function() {
	var contentshow;
	var countryshow;
	
	jQuery("ul.select-cont li:first a").click(function() {		
		if(!contentshow)
		{
			jQuery('ul.select-cont li:not(:first)').show();
			contentshow = 1;
		}
		else
		{
			jQuery('ul.select-cont li:not(:first)').hide();
			contentshow = 0;
		}
		return false;
	});
	
	jQuery("ul.select-country li:first a").click(function() {
		if(!countryshow)
		{
			jQuery('ul.select-country li:not(:first)').show();
			countryshow = 1;
		}
		else
		{
			jQuery('ul.select-country li:not(:first)').hide();
			countryshow = 0;
		}
		return false;
	});
	
	vtip();

	visualControl.init();

	font.init();

	$('.tx-12bis3config-pi9').each(function(){
		$.extend(true,this,zitatControl);
	});
	if ($('.tx-12bis3config-pi9').length)
	{
		$('.tx-12bis3config-pi9')[0].init();
		window.setInterval(function() {
			$('.tx-12bis3config-pi9').each(function(){this.toggle()});
		},10000);
	}

    $('#projects-box dl dt').css('cursor','pointer').click(function() {
		var href = $(this).next('dd').children('p').children('a:first').attr('href');
		if (href && href.length > 0) location.href = href;
    	return false;
	});
});

/* cookie helper functions */

function getCookie (name)
{
   var i=0  //Suchposition im Cookie
   var suche = name+"=";
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length);
         ende = (ende>-1) ? ende : document.cookie.length;
         var cook = document.cookie.substring(i+suche.length, ende);
         return unescape(cook);
      }
      i++
   }
   return null
}

function setCookie (name, wert, domain, expires, path, secure)
{
   var cook = name+"="+unescape(wert);
   cook += (domain) ? "; domain="+ domain : "";
   cook += (expires) ? "; expires="+expires : "";
   cook += (path) ? "; path="+path : "";
   cook += (secure) ? "; secure" : "";
   document.cookie = cook;
}


function openGeoInfo(id) {
	$.nyroModalManual({
			bgColor: '#000000',
			url: '/index.php?id=826&newscat='+id,
			forceType: 'iframe',
			autosizeable: true,
			//width: 0,
			//height: 0
			minHeight: 320,
			minWidth: 550
		});
}

