﻿(function($) {

	/**** SETTINGS BLOCK ****/
	
    //Disabled navIcon = $('<img alt="" src="/img/alpha.gif" class="navicon"/>'); 
	$topTeaserNav = $('<div class="nav"><a class="left prev" href="#" onclick="return false;">left</a><a class="right next" href="#" onclick="return false;">right</a></div>');
	//$galleryOverlay = $('<div class="simple_overlay" id="gallery"><a class="prev">prev</a><a class="next">next</a>	<div class="info"></div><img class="progress" src="http://static.flowplayer.org/tools/img/overlay/loading.gif" /></div>');

	
	/**** SETTINGS BLOCK END ****/

	/**** Top Slider Script END ****/

	/**** Box Heights Script - Set Height of the last inner Box ****/

	$.setHeights = function(){
	
			//alert($('#contentframe').height());
		/*if ($('#contentframe').height() <= 655) {
			possibleHeight = $('#contentframe').height()-$('#breadcrumb').outerHeight()-15; //-15 for the margins
			if($('.box').length > 1) {	possibleHeight = possibleHeight - $('.box').height(); }
			if(jQuery.browser.msie && jQuery.browser.version < 7){
				$('#content .box:last').css('height',possibleHeight);
			} else {
				$('#content .box:last').css('min-height',possibleHeight);
			}
		}
		return true;
		*/
	}
	/**** Box Heights Script - Set Height of the last inner Box END ****/
	
})(jQuery);

jQuery().ready(function(){ 
	
	$('#fanBox #accordion').tabs("#accordion div", {tabs: 'h3', effect: 'slide', initialIndex: null});
	
	$('.data-table tr').each(function(){ if ($('.data-table tr').index(this) % 2 != 0){ $(this).addClass('second-row');}	});
	
	$('.year-tabs li').not('li li').click(function(){  // Tab Functionality for Newsarchiv
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
	});
	
	
	// Flowplayer Konfiguration
	
	
	
	
	flowplayer("a.myPlayer", { wmode: 'opaque', src: "/modules/flowplayer-3.1.5.swf"}, {	
	
		canvas: {backgroundGradient: 'none'},	

		clip: { 
    	 //autoBuffering: true, 
    	 scaling: 'fit'
	    }, 
	    
    	plugins:  { 
	        controls: {                    
            	// setup a background image 
        	    background: 'url(/img/bg-player-control.jpg) repeat top', 
             
	            backgroundGradient: 'none', 
             
            	// these buttons are visible 
        	    all:false, 
				play:true, 
				volume:true,
				mute:true, 
				time:true, 
				stop:false, 
				playlist:false, 
				fullscreen:true, 
				scrubber: true,
		             
        	    // custom colors 
    	        bufferColor: '#333333', 
	            progressColor: '#000000', 
				progressGradient: 'none', 
            	buttonColor: '#064f3c', 
        	    buttonOverColor: '#0b6049', 
			
				timeColor: '#025844',
				durationColor: '#025844',
				timeBgColor: '#011614',
	            tooltipColor: '#064f3c', 
				
				timeBgHeightRatio: 0,
				
            	// custom height 
        	    height: 25, 
             
    	        // setup auto hide 
	            autoHide: 'always'            
             
	        }	
		},
	    
	    // our fake fullscreen action. 
		/* DISABLED
	    onBeforeFullscreen: function()  { 
			
			
			if(jQuery.browser.msie && jQuery.browser.version < 7){
			} else {
        	// 1. launch overlay 
    	    $("div.overlay").overlay({effect: 'apple'}).load(); 
 
    	    // 2. pause the player and make it hidden while overlay "grows" 
        	this.hide().pause(); 
 
	        // 3. disable fullscreen button when overlayed 
	        this.getControls().enable({fullscreen:false}); 
 
        	// 4. disable normal fullscreen action by returning false 
    	    return false; 
			}
	    }, */
		
    	onKeyPress: function(key) { 
        	if (key == 27) { 
            	$("div.overlay").overlay().close(); 
	        } 
    	}   	
	    
	});
	
	// IE6 Version of 3.level Navigation	
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		$('.sub').hover(
			function () { $(this).addClass('hover')}, 
			function () { $(this).removeClass('hover')}
		 )
	}
	
	/**
	 * Use fancybox for two different types of content
	 * Differ between itemshop and payment to set different
	 * iframe sizes.	 
	 */
	$("a.iframe.payment").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 820,
		'frameHeight': 650,
		'centerOnScroll': true,
		'overlayOpacity': .75,
		'width': 820,
		'height': 650,
        onClosed : function() {
            $.ajax({
                type : 'POST',
                data : 'reloadUserCash=' + 'true'
            })
        }
	});
	
	$("a.iframe.itemshop").fancybox({
		'hideOnContentClick': false,
		'frameWidth': 800,
		'frameHeight': 599,
		'centerOnScroll': true,
		'overlayOpacity': .75,
		'width': 800,
		'height': 599,
        onClosed : function() {
            $.ajax({
                type : 'POST',
                data : 'reloadUserCash=' + 'true'
            })
        }
	});
	
	// setup overlay 
$("div.overlay").overlay({ 
 
    // use the Apple effect for overlay 
    effect: 'apple',     
     
    // 1. start expose effect when overlaying begins 
    expose: '#123448', 
 
    // 2. when overlay is loaded, we reposition and resize the player on top of it 
    onLoad: function() { 
 
        // get handle to the embed element 
			var embed = $("#flashContainer :first"); 
			//var embed = $("a#flashContainer object, a#flashContainer embeded"); 
 
        /* and reposition / resize it. you will propably have to tweak 
            these when placing this on your site */ 
			
			
			//$closeIcon = $('<div class="custemized-close"></div>');
			
			//$('body').prepend
 
        var el = this.getContent(); 
        var height = el.height(); 
 
        embed.css({ 
            // size 
            //width:parseInt(el.width()) -80, 
            //height:parseInt(height) -80, 

            width: 760, 
            height:430, 
 
            // position 
            //left: parseInt(el.css("left")) + 40, 
            //top: parseInt(el.css("top")) + 40 
			
			top: -50,
			left: -125
            //top: parseInt(el.css("top")) + 40 
		}) 
		
		
		$('div.overlay .close').insertAfter(embed);
		
		//embed.after($closeIcon);
		//$closeIcon.click(function(this){o.close(p)})}
 
        // while overlay was growing we were in the paused state 
        $f().resume(); 
    }, 
 
    // when overlay closes 
    onClose: function() { 
		$('#flashContainer .close').appendTo('div.overlay');
 
        // 1. return our player to its original size/position 
			$("#flashContainer :first").css({top: null, left: null, width: null, height: null}); 
 
        // 2. enable the fullscreen button again 
        $f().getControls().enable({fullscreen:true}); 
    } 
});
	
	
	/******* INIT BLOCK *******/
	
	//$('body').prepend($galleryOverlay); //Gallery Overlay einfuegen
	
	// JQuery Tools Gallery Plugin
	if($('.gallerycont li a:first').exists()){
		$(".gallerycont").find('a').not('span a').overlay({		
		target: '#gallery', expose: '#222'}).gallery({ speed: 200, autohide: false });
	}
	if($('.gallerycont a.lightbox:first').exists()){
		$(".gallerycont").find('.lightbox').overlay({		
		onLoad: function(){
			if($('#flashContainer object').exists() || $('#flashContainer embed').exists()){
				$f().toggle();
			}
		},
		onClose: function(){
			if($('#flashContainer object').exists() || $('#flashContainer embed').exists()){
				$f().toggle();
			}
		},
		target: '#gallery', expose: '#222'}).gallery({ speed: 200, autohide: false });
	}
	

	
	//$(window).resize(function(){ setHeights() });
	
	
	// initiating the css-image preload script
	$.preloadCssImages(); 
	
	// Initiating the Formular Validation
	if($(".loginform").exists()){	
		$(".loginform").validate({
			invalidHandler: function(form, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {      
					var message = errors == 1
					? 'Leider konnten wir deine Daten nicht bestätigen. Es wurde ein Feld nicht korrekt ausgefüllt, bitte fülle das rot markierte Feld korrekt aus und versuche es erneut.'
					: 'Leider konnten wir deine Daten nicht bestätigen. Es wurden <strong>' + errors + '</strong> Felder nicht korrekt ausgefüllt, bitte fülle die rot markierten Felder korrekt aus und versuche es erneut.';
					$("p.error-big").html(message);
					$("p.error-big").show();
				} else {
				$("p.error-big").hide();
				}
			} 
		})
	}
	
	
	
	
	// JS for the TopTeaser on Startpage
	if($('#topTeaser').find('li').length>1){
		$('#topTeaser').append($topTeaserNav);  // activates the slider nav buttons		
			
		$('.slidecnt').scrollable({ //	SLIDESHOW SCROLLABLE JQUERY TOOLS
			size: 1,
			loop: true,
			keyboard: false,
			easing: "swing"
		}).circular().navigator().autoscroll({autoplay: true, interval: 16000});	
 
	}
	
	
	// Fading Script for Character Section
	$('#characterNav li a').click(function(){
		effectSpeed = 200; // Fading Time
		
		$('#characterNav li').removeClass('active');
		$(this).parent().addClass('active');		
	
		$newActive = $('#'+$(this).attr('rel'));
		$('.box > div:visible').not('#characterNav, .footer').fadeOut(effectSpeed, function(){
			$newActive.fadeIn(effectSpeed);
		});
		return false;
	})	
	
	
	
	// Accordion JS
	$(".accordionBlock").removeClass('accordionBlock').addClass('accordion'); // Activating Accordion JavaScript
	$(".accordion").tabs(".accordion div.textblock", {
		tabs: 'h3',  
		//effect: 'slide', 
		initialIndex: 0,
		onClick: function() { 
			if(jQuery.browser.msie && jQuery.browser.version < 7){
			}
			//.setHeights();
		} 
	});
		
	// if IE6 or lower - Fixing Footer View
	if(jQuery.browser.msie && jQuery.browser.version < 7){
		$('.loginform').css('position','absolute').css('position','relative');
	}

	
	// Tab Activating for Startpage
	//$("#highscores ul").tabs(".time-table-container > .time-table", {fadeOutSpeed: 400, fadeInSpeed: 400}); 
	
	$("ul.tabs").tabs(".time-table-container", {
		onClick: function(index){
		//$('.server-list, #characterClass').sSelect().resetSS();
		//$('.server-list').resetSS();
		}
	}); 
	
		
	// Tool Tip Activating
    $(".toolTipItem").tooltip('#toolTip'); 
	
	//styling select box with jquery	
		
	$('#highscores').addClass('active');
	$('.time-table-container').each(function(){
		activeNode = parseInt($(this).find('select.server-list option:selected').attr('value'));
		$(this).find('.time-table:eq('+(activeNode-1)+'), .serverlink:eq('+(activeNode-1)+')').removeClass('hide');
	})
	//$('.tabs li.second').css('position', 'relative');
	
	
	$('.server-list, #characterClass').sSelect().change(function(){
		$activeContainer = $('.time-table-container:visible').closest('.time-table-container');
		activeNode = parseInt($activeContainer.find('select.server-list option:selected').attr('value'));
		
		$activeContainer.find('.time-table, .serverlink').addClass('hide');
		$activeContainer.find('.time-table:eq('+(activeNode-1)+'), .serverlink:eq('+(activeNode-1)+')').removeClass('hide');
	});

	// Set Height of the inner Box
	$.setHeights();
})