/**
**	JSon Objekt für die Anmaitonselemente
**
**	Diese Elemente sind als Backup für die fehlende Pflege in Typo3
**
**	Sie werden überschrieben an der Zeile
**
**/
var animationElement_1 = {title:'Customers', bg:'customers.png'};
var animationElement_2 = {title:'Service Proposition', bg:'service_proposition.png'};
var animationElement_3 = {title:'Multichanneling', bg:'multichanneling.png'};
var animationElement_4 = {title:'SPOI', bg:'spoi.png'};
var animationElement_5 = {title:'End to End Service Process', bg:'end_to_end.png'};
var animationElement_6 = {title:'Levels of Competence', bg:'levels_of_competence.png'};
var animationElement_7 = {title:'Knowledge Management', bg:'knowledge_management.png'};
var animationElement_8 = {title:'Intelligeghdhgdfhgfnt Automation', bg:'intelligent_automation.png'};
var animationElement_9 = {title:'SPM', bg:'spm.png'};
var animationElement_10 = {title:'service Culture & Governance', bg:'service_culture_governance.png'};

var mood_counter = 0;
var setInt_mood;
var mood_time = 4000;


var tabSwitch_counter = 0;
var switchRegister_time = 3000;
var setInt_switchRegister;

var area_bg = new Array(animationElement_1,animationElement_2,animationElement_3,
						animationElement_4,animationElement_5,animationElement_6,
						animationElement_7,animationElement_8,animationElement_9,
						animationElement_10);

// Aktuelle Area der Animation
var actArea;
						
						
jQuery(document).ready(function(){
	/*Moodbild*/
	setInt_mood = window.setInterval('changeMood()',mood_time);
	setInt_switchRegister = window.setInterval('switchRegister()',switchRegister_time);
	jQuery('.mood:eq(0)').show();
	
	var animationscounter = 0;
	
	/**
	//An dieser Stelle werden die bereits gesetzte Elemente ersetzt
	**/
	jQuery('.popUp_items').children().each(function(){
		area_bg[jQuery(this).index()] = {title: jQuery(this).children('.area_title').html(), bg: jQuery(this).children('.area_bg').html()}
		jQuery(this).children('.area_title').remove();
		jQuery(this).children('.area_bg').remove();
	});
	
	
	jQuery('.tabSwitch').each(function(){
		tabSwitch_counter ++;
	});
	set_mood_changer_buttons();
	set_click_change_mood();
	
	/*** Selectboxen stylen : Newsletterformular ***/
	jQuery('select#nc_form_anrede').wrap('<div class="styled_select"></div>');
	
	/*** Selectboxen stylen : Kontaktformular ***/
	jQuery('.mailform-table-outer  select').wrap('<div class="styled_select"></div>');
	jQuery('div.styled_select select').each(function(){
		jQuery(this).before('<span class="selected_value">'+jQuery(this).children('option:selected').html()+'</span>');
	});
	
	jQuery('div.styled_select select').each(function(){
		jQuery(this).change(function(){
			jQuery(this).parent().children('span.selected_value').html(jQuery(this).children('option:selected').html());
		});
	});
	
	
	
	
	
	/****Error-Klassen für den Kontaktformular setzen****/
	jQuery('.tx_mailform_layout_error li').each(function(){
		var label_error = jQuery.trim(jQuery(this).html().replace(/:(.*)/, ""));
		jQuery('.tx_mailform_required .tx_mailform_div_label_left').each(function(){
			if(jQuery(this).children('label').html() == label_error){
				jQuery(this).addClass('tx_mailform_div_label_error');
			}
		});
	});
	
	/* Footer Stylen */
	jQuery('#footer li:eq(0)').children().addClass('first');
	
	/* Header navigation stylen */
	jQuery('#meta_topNav li:eq(0)').children().addClass('first');
	jQuery('#meta_topNav li').eq(-2).children().addClass('last');
	
	//Für die Animation
	jQuery('.animation_popUp_bg').click(function(){
		closeAnimationPopUp();
	});
	jQuery('.popUp_closeBtn').click(function(){
		closeAnimationPopUp();
	});
	initiale_animationItems();
	
	jQuery('.popUp_nav_next').click(function(){
		getNextArea();
	});
	jQuery('.popUp_nav_prev').click(function(){
		getPrevArea();
	});
	
	
	
	/* BEGIN: SUCHFELDVERWALTUNG */
	jQuery('#searchInput').focus(function(){ 
		if(jQuery(this).val() == ' Suchbegriff'){
			jQuery(this).val('');
		}
	});
  
	jQuery('#searchInput').blur(function(){
		if(jQuery(this).val() == '') {
			jQuery(this).val(' Suchbegriff');
		}
	});
	/* END: SUCHFELDVERWALTUNG */
	
	/* BEGIN: REGISTERKARTENVERWALTUNG */
	// Alle Bodies ausschalten
	jQuery('.tabs .tab_body').each(function(){
		jQuery(this).hide();
	});
	
	jQuery('.tabs').each(function(){
		jQuery(this).children('.tab_contents').children('.tab_body:eq(0)').show();
	}); // den ersten Body zeigen
	
	jQuery('.tabs').each(function(){
		jQuery(this).children('.tab_contents').children('.tab_body').children().children('.tabSwitch:eq(0)').show();
	}); // den ersten Switch-Body zeigen
	
	
	
	
	jQuery('.tabs .tab_header:eq(0)').addClass('active'); // den ersten Header aktivieren

	jQuery('.tabs .tab_headlines .tab_header').click(function(){ // Registerkarten umschalten 
		// den geklickten Tab-Header aktivieren
		jQuery(this).parent().children('.tab_header').each(function(){
		//jQuery('.tabs .tab_header').each(function(){
			jQuery(this).removeClass('active');
		});
		jQuery(this).addClass('active');

		// den entsprechenden tab-Body anzeigen
		jQuery(this).parent().parent().children('.tab_contents').children('.tab_body').each(function(){
		//jQuery('.tabs .tab_body').each(function(){
			jQuery(this).hide();
		});
		
		jQuery(this).parent().parent().children('.tab_contents').children('.tab_body').eq(jQuery(this).index()).show();
		//jQuery('.tabs .tab_body:eq('+jQuery(this).index()+')').show();
	});
	/* END: REGISTERKARTENVERWALTUNG */
	
	/* BEGIN: VERWALTUNG DER RECHTEN SPALTE */
	jQuery('#contentRight .block .blockHeader').click(function(){
		var block = jQuery(this).parent(); 
		var blockHeader = jQuery(this);
		var blockBody = block.children('.blockBody'); 
		if(!block.hasClass('off')){ 
			blockBody.slideToggle('slow', function(){
				block.addClass('off');
				blockHeader.css('background-image', 'url(fileadmin/templates/img/pfeil_right_column_down.png)');	
				//jQuery.cookie('block'+block.index(), 'off'); // z.B. block1 = off
			});
		} else {
			blockBody.slideToggle('slow', function(){
				block.removeClass('off');
				blockHeader.css('background-image', 'url(fileadmin/templates/img/pfeil_right_column_up.png)');	
				//jQuery.cookie('block'+block.index(), null); 
			});
		}
	});
	/* END: VERWALTUNG DER RECHTEN SPALTE */
});

function set_mood_changer_buttons(){
	jQuery('.mood').each(function(){
		mood_counter ++;
		if(jQuery(this).index() == 0){
			jQuery('<a class="active" href="javascript:void(0)"><img src="/fileadmin/templates/img/blank.gif" height="12"></a>').appendTo('#mood_changer');
		}else{
			jQuery('<a href="javascript:void(0)"><img src="/fileadmin/templates/img/blank.gif" height="12"></a>').appendTo('#mood_changer');
		}
	});
	jQuery('<div class="clearAll"></div>').appendTo('#mood_changer');
}


function set_click_change_mood(){
	jQuery('#mood_changer a').each(function(){
		jQuery(this).click(function(){
			window.clearInterval(setInt_mood);
			var i = 0;
			for(i = 0; i < mood_counter; i++){
				if(jQuery('.mood:eq('+i+')').is(':visible')){
					jQuery('.mood:eq('+i+')').fadeOut('slow');
					jQuery('#mood_changer a:eq('+i+')').removeClass('active');
				}
			}
			jQuery('.mood:eq('+(jQuery(this).index())+')').fadeIn('slow');
			jQuery('#mood_changer a:eq('+(jQuery(this).index())+')').addClass('active');
			setInt_mood = window.setInterval('changeMood()',mood_time);
		});
	});
}

function changeMood(){
	var i = 0;
	for(i = 0; i < mood_counter; i++){
		if(jQuery('.mood:eq('+i+')').is(':visible')){
			jQuery('.mood:eq('+i+')').fadeOut('slow');
			jQuery('#mood_changer a:eq('+i+')').removeClass('active');
			if(i == (mood_counter - 1)){
				jQuery('.mood:first').fadeIn('slow');
				jQuery('#mood_changer a:first').addClass('active');
			}else{
				jQuery('.mood:eq('+(i+1)+')').fadeIn('slow');
				jQuery('#mood_changer a:eq('+(i+1)+')').addClass('active');
			}
			return false;
		}
	}
}

function switchRegister(){
	var i = 0;
	for(i = 0; i < tabSwitch_counter; i++){
		if(jQuery('.tabSwitch:eq('+i+')').is(':visible')){
			jQuery('.tabSwitch:eq('+i+')').hide();
			if(i == (tabSwitch_counter - 1)){
				jQuery('.tabSwitch:first').show();
			}else{
				jQuery('.tabSwitch:eq('+(i+1)+')').show();
			}
			return false;
		}
	}
}






/*Speichert alle Elemente der Animation ab*/
function initiale_animationItems(){
	var i = 0;
	for(i = 0; i < area_bg.length; i++){
		area_bg[i].content = jQuery('.popUp_items .an_popUp_center_text').eq(i);
	}
	jQuery('.popUp_items').empty();
}



/*Setzt den Inhalt des PopUps der Animation auf den aktuellen Element*/
function setActuelAnimationItem(index){
	//Actuelles Inhalt löschen
	jQuery('.popUp_items').empty();

	//Actuelles Inhalt neu laden
	jQuery('.popUp_items').append(area_bg[index].content);

	//Ausblenden bzw. Einblenden des Titels der vorherigen Area
	if(index == 0){
		jQuery('.popUp_nav_prev').hide();
	}else{
		jQuery('.popUp_nav_prev').html(area_bg[index - 1].title);
		jQuery('.popUp_nav_prev').show();
	}
	
	//Ausblenden bzw. Einblenden des Titels der nächsten Area
	if(index == (area_bg.length -1)){
		jQuery('.popUp_nav_next').hide();
	}else{
		jQuery('.popUp_nav_next').html(area_bg[index + 1].title);
		jQuery('.popUp_nav_next').show();
	}
	
	//Vertikale Zentrierung des PopUps
	//setVerticalPosPopUp();
	jQuery('a.popUp_closeLink').click(function(){
			closeAnimationPopUp();
	});
	
	//Den Wert der aktuellen Area neu setzen
	actArea = index;
}


function setVerticalPosPopUp(){
	var top = (477 - jQuery('.an_popUp_content').height())/2;
	alert(jQuery('.an_popUp_content').height());
	jQuery('.an_popUp_content').css('top',top+'px');
}

function getNextArea(){
	hoverArea(actArea + 1);
	setActuelAnimationItem(actArea + 1);
}

function getPrevArea(){
	hoverArea(actArea - 1);
	setActuelAnimationItem(actArea - 1);
}

/*Wird aufgerufen, sobald eine Area angeklickt wurde*/
function getInArea(index){
	jQuery('.hovredArea').addClass('clicked');
	setActuelAnimationItem(index);
	jQuery('.animation_popUp_bg').parent().show();
}

/*Wechselt den Hintergrund der Animation, jenachdem welche Area gehovert wird*/
function hoverArea(index){
	jQuery('.hovredArea').css('background-image',"url('"+ area_bg[index].bg +"')");
}

/*Setzt den Hintergrund der Animation auf none und damit ist keine Area gehovert*/
function hoverOutArea(index){
	if(! jQuery('.hovredArea').hasClass('clicked')){
		jQuery('.hovredArea').css('background','none');
	}
}

/*Schließt den PopUp der Animation*/
function closeAnimationPopUp(){
	jQuery('.hovredArea').removeClass('clicked');
	jQuery('.animation_popUp').fadeOut('fast');
}

/** 
*  The function manages the state of the blocks within the session  
*/
/*jQuery(window).load(function() {
	var blocks = jQuery('.block');
	// runs through all the blocks
	for(var i = 0; i < blocks.length; i++){
		// checks if the appropriate cookie has been set 
		if(jQuery.cookie('block'+i) != null){
			blocks.eq(i).addClass('off');
			blocks.eq(i).children('.blockHeader').css('background-image', 'url(fileadmin/templates/img/pfeil_right_column_down.png)');	
			blocks.eq(i).children('.blockBody').hide(); 
		}
	}	
});
*/


/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*

jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};*/
