function getInnerWindowSize()
{
	if (window.innerWidth)
	{
		return new Array(window.innerWidth, window.innerHeight);
	}
	else if (document.documentElement.clientWidth)
	{
		return new Array(document.documentElement.clientWidth, document.documentElement.clientHeight);
	}
	else
	{
		return new Array(document.body.clientWidth, document.body.clientHeight);
	}
}

function centerContent()
{
	var intStepWidth = 113;
	var intHorizontalCorrection = 0;
	var intVerticalCorrection = -1;

	var arrWindowSize = getInnerWindowSize();
	var objContent = document.getElementById('content');
	if (objContent != null)
	{
		var arrContentSize = new Array(parseInt(objContent.style.width), parseInt(objContent.style.height));	//Groesse des Content-Bereichs ermitteln

		var intPosLeft = Math.round((arrWindowSize[0] - arrContentSize[0]) / 2);
		var intRest = intPosLeft % intStepWidth;
		var intPosLeft = intRest < intStepWidth / 2 ? intPosLeft - intRest + intHorizontalCorrection : intPosLeft - intRest + intStepWidth + intHorizontalCorrection;	//Position auf glatte Schrittweite einstellen
		objContent.style.left = (intPosLeft < 0 ? 0 : intPosLeft) + 'px';

		objContent.style.display = 'block';
	}
}
/**
 * DBJ-SOUND 1.0.2
 * jQuery dbj_sound plugin (no flash, or any other simillar control used)
 */

(function($) {

    $.dbj_sound = {
        tracks: {},
        enabled: true,
        
        url : function ( host_element ) {
             var url = $(host_element).attr("href") ;
             if ( "undefined" == typeof(url) ) throw new Error(0xFF,"DBJ-SOUND EXCEPTION: host element invalid or missing a valid HREF attribute") ;
             return url ;
         },
        
        loop: function ( host_element ) { this.play (host_element,true) ; },

        play: function(host_element, looping ) {
            //
        var sound_jq = function(src) {
                //
                return $('<embed />').attr({
                    style: "height:0",
                    loop: ( looping ? "true" : "false" ) ,
                    src: options.track,
                    autostart: "true",
                    hidden: "true"
                });
            }

            // sanity checks
            if (!this.enabled) return;
            if (!host_element) return;

            var options = { track: this.url(host_element) }; 

            if (this.tracks[options.track]) {
                var current = this.tracks[options.track];
                current.remove();
            }

            var element = sound_jq();
                element.appendTo(document.body);
                    this.tracks[options.track] = element;
            return element; // which is jQuery object 
        }

        // DBJ added
        , stop: function(host_element) {
            var url = this.url(host_element);
            if (this.tracks[url]) {
                var current = this.tracks[url];
                // Check when Stop is avaiable, but not on a jQuery object
                if ('undefined' != typeof [0].Stop) current[0].Stop();
                else if ('undefined' != typeof current[0].stop) current[0].stop();
                current.remove();
                this.tracks[url] = null;
            }
        }

        // DBJ added
        , playing: function(host_element) {
            if (!$.dbj_sound.enabled) return false;
            return this.tracks[this.url(host_element)] != null;
        }

        // DBJ added
        , enabledisable: function() {
            this.enabled = !this.enabled;
            if (this.enabled == false)
                for (var j in this.tracks) {
                if (this.tracks[j]) {
                    this.tracks[j].remove();
                    this.tracks[j] = null;
                }
            }
            return this.enabled;
        }

    };

})(jQuery);
/*////////////////////////////////////////////////////////////////////////*/
$(document).ready(function(){
	centerContent();
	var resizeTimer = null;
	$(window).bind('resize', function() {
	    if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(centerContent, 100);
	});
	$("div.scrollable").scrollable({vertical:true, size: 1});
		$("*[href$=.mp3]").mouseout(function() {
			$.dbj_sound.stop(this);
		}).mouseover(function() {
			$.dbj_sound.loop(this);
		});

		$("*[href$=.wav]").mouseout(function() {
			$.dbj_sound.stop(this);
		}).mouseover(function() {
			$.dbj_sound.loop(this);
		});	
		///////////////////////// 

	var margin=35;
	var height=71;
	var width=113;

	$(".img_1").stop().css({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'});	
	$(".img_2").stop().css({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'});

	$(".img_1").css("position","absolute");	
	$(".img_2").css("position","absolute");	
	$("li.spiel .hide").css("visibility","hidden");	

	$("li.spiel").click(function() {
		var id = $(this).attr('id');
		if ($(this).hasClass("none")){	
			$(this).removeClass("none");
			$(this).addClass("open");
			$("#"+id).find(".img_1").stop().animate({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'},{duration:500});	
			window.setTimeout(function() {
				$("#"+id).find(".img_2").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});	
			},500);
			window.setTimeout(function() {
				$("#"+id).find(".hide").css("visibility","visible");	
			},501);
		}	
		else if ($(this).hasClass("close")){
			$(this).removeClass("close");
			$(this).addClass("open");
			$("#"+id).find(".img_1").stop().animate({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'},{duration:500});
			window.setTimeout(function() {
				$("#"+id).find(".hide").css("visibility","visible");	
			},50);	
			window.setTimeout(function() {
				$("#"+id).find(".img_2").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});	
			},500);
			window.setTimeout(function() {
				$("#"+id).find(".hide").css("visibility","visible");	
			},501);				
		}else if ($(this).hasClass("open")){	
			$("#"+id).find(".hide").css("visibility","visible");	
			$(this).addClass("close");	
			$(this).removeClass("open");
			$("#"+id).find(".img_2").stop().animate({height:'0px',width:''+width+'px',marginTop:''+margin+'px',opacity:'0.5'},{duration:500});	
			window.setTimeout(function() {
				$("#"+id).find(".img_1").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});	
			},500);	
			window.setTimeout(function() {
				$("#"+id).find(".img_1").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'1'},{duration:500});	
			},700);	
			window.setTimeout(function() {
				$("#"+id).find(".hide").css("visibility","hidden");
				$("#"+id).find(".img_1").stop().animate({height:''+height+'px',width:''+width+'px',marginTop:'0px',opacity:'0.5'},{duration:500});	
			},1200);
		}
		$('li.spiel a').unbind('click'); 
		return false;
	});

});
