// Core Javascript File
// Copyright 2010 MARTINI Werbeagentur GmbH.  All rights reserved.

$(document).ready(function() {	
	if ($.browser.mozilla) {
		$('#flash').css('margin', '5px auto');	
	}			   
						   
	$('#lightbox .next').click(function(evt) {
		Lightbox.next();
	});
	$('#lightbox .prev').click(function(evt) {
		Lightbox.previous();
	});

	$('#lightbox .content img, #lightbox .hint a').live('click', function() {
		Lightbox.hide();											   
	});
	
	$('.close').live('click', function() {	
		$(this).parent().parent().hide();
	});
	
	/*
	popup = window.open('event.html','MARTINI Werbeagentur GmbH - Event', 'height=495,width=700');
	
	if (window.focus) {
		popup.focus();
	}	
	*/
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7579876-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

var Lightbox = {
	options: null,
	index: null,
	
	call: function(params) {
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		var flash = (isIE) ? window['mwa_flash'] : document['mwa_flash'];
	
		flash.call(params);	
	},
	
	showText: function(id) {
		$('#'+id).show();
	},
	
	show: function(label) {
		var image = null;
		for (var i in this.options.images) {
			if (this.options.images[i].label == label) {
				image = this.options.images[i];
				this.index = parseInt(i);
			}
		}
		if (image == null) {
			return;	
		}
		
		this._swap(image);
	
		$('#lightbox').show();
	},
	
	hide: function(id) {
		if (!id) {
			id = 'lightbox';
		}
		$('#'+id).hide();
		if (id == 'lightbox') {
			$('#lightbox .content img').remove();										
		}
	},
	
	next: function() {
		var image = this.options.images[++this.index] || null;
		if (image == null) {
			this.index--;
			return;	
		}
		
		this._swap(image);

		this.call({
			action: 'move',
			label: image.label
		});
	},
	
	previous: function() {
		var image = this.options.images[--this.index] || null;
		if (image == null) {
			this.index++;
			return;	
		}

		this._swap(image);
		
		this.call({
			action: 'move',
			label: image.label
		});
	},
	
	setOptions: function(options) {
		this.options = options;
	},
	
	_swap: function(image) {
		if ($('#lightbox .content img').length == 0) {
			$('#lightbox .content').append('<img />');
		}
		
		var img = $('#lightbox .content img');
				
		if (!image.fileName) {
			image.fileName = image.label+'.jpg';	
		}
		if (!image.text) {
			image.text = '';	
		}
		
		img.attr('src', 'assets/images/large/'+image.fileName);
		img.attr('alt', image.text);
		$('#lightbox .text').html(image.text);
	}
};

function abfrage() {
	window.open("abfrage/abfrage.htm","abfrage","width=520,height=590,left=0,top=0,screenX=0,screenY=0,directories=no,location=no,menubar=no,resizeable=no,scrollbars=no,status=no,toolbar=no,titlebar=yes");
}
