var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var videoFlash = '';
var recaptchaPublicKey = '6LdntQYAAAAAADdejfLK4X5rojFsZu5YYom6aqtw';
var datepickerConf = {
	showOn: 'button', 
	buttonImage: globalPath + '/_img/_common/bt_calendar.jpg', 
	buttonImageOnly: true
}

function init() {
	startSifr();
	startFlashMovie();
}

$(document).ready(function () {
	startTooltips();
	startNutzenAlbum();
	startScrollPanels();
	
	if(globalLang == 'de') {
		datepickerConf = {
			showOn: 'button', 
			buttonImage: globalPath + '/_img/_common/bt_calendar.jpg', 
			buttonImageOnly: true,
			dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
			monthNames: ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']
		}
	}
	
});

function startSifr(){
	if (typeof sIFR == "function") {
	
		// This is the preferred "named argument" syntax
		sIFR.replaceElement(named({
			sSelector: ".content h2",
			sFlashSrc: globalPath + "/_media/sifr/univers.swf",
			sColor: "#07598F",
			sWmode: "transparent"
		}));
		
		sIFR.replaceElement(named({
			sSelector: "#box-home h2",
			sFlashSrc: globalPath + "/_media/sifr/univers.swf",
			sColor: "#23A0F3",
			sLinkColor: "#23A0F3",
			sWmode: "transparent"
		}));
		
		sIFR.replaceElement(named({
			sSelector: "#teaser h2",
			sFlashSrc: globalPath + "/_media/sifr/univers.swf",
			sColor: "#FFFFFF",
			sWmode: "transparent"
		}));
		
		sIFR.replaceElement(named({
			sSelector: "#teaser li.teaser-content-referenzen h3",
			sFlashSrc: globalPath + "/_media/sifr/univers.swf",
			sColor: "#47AFF5",
			sWmode: "transparent"
		}));
		
		sIFR.replaceElement(named({
			sSelector: "h5",
			sFlashSrc: globalPath + "/_media/sifr/univers.swf",
			sColor: "#09619B",
			sWmode: "transparent"
		}));
		
	}
}

function startFlashMovie() {
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	if (section == 'home') {
		if (hasReqestedVersion) {
			videoFlash = new SWFObject(globalPath + "/" + globalLang + "/_media/swf/loader.swf", "homeConcept", "100%", "100%", "8", "");
			videoFlash.addVariable('swfFile', globalPath + "/" + globalLang + "/_media/swf/home_concept.swf");
			videoFlash.addVariable('link01', globalPath + "/" + globalLang + "/loesung");
			videoFlash.addVariable('link02', globalPath + "/" + globalLang + "/loesung");
			videoFlash.addVariable('link03', globalPath + "/" + globalLang + "/loesung");
			videoFlash.addParam('wmode', 'transparent');
			videoFlash.write('teaser-home');
		}
		else {		
			var html = '<div id="slideshow">' +
			'<img src="' + globalPath + "/" + globalLang + '/_img/_common/teaser_home01.jpg" alt="Sales Adventure 2.0" class="active" usemap="#Map" />' +
			'<img src="' + globalPath + "/" + globalLang + '/_img/_common/teaser_home02.jpg" alt="Die Neue Lern-dimension" usemap="#Map02" />' +
			'<img src="' + globalPath + "/" + globalLang + '/_img/_common/teaser_home03.jpg" alt="CEBIT 2010" usemap="#Map03" />' +
			'</div>' +
			'<map name="Map" id="Map"><area shape="rect" coords="905,416,970,437" href="' + globalPath + "/" + globalLang + '/loesung" title="Mehr" /></map>' +
			'<map name="Map02" id="Map02"><area shape="rect" coords="905,416,970,437" href="' + globalPath + "/" + globalLang + '/loesung" title="Mehr" /></map>'+
			'<map name="Map03" id="Map03"><area shape="rect" coords="905,416,970,437" href="' + globalPath + "/" + globalLang + '/loesung" title="Mehr" /></map>';			
			$('#teaser-home').html(html);
			
			setInterval("slideSwitch()", 5000);
		}
	}
	else {
		if (section == 'unternehmen' && subsection == 'differenzierung') {
			if (hasReqestedVersion) {
				videoFlash = new SWFObject(globalPath + "/" + globalLang + "/_media/swf/differenzierung_concept.swf", "homeConcept", "100%", "100%", "8", "");
				videoFlash.addParam('wmode', 'transparent');
				videoFlash.write('teaser');
			}
			else {				
				var html = '<div id="teaserDifferenzierung">'+
					'<a class="ball1" href="#"><img class="imgball1" src="'+ globalPath + "/" + globalLang + '/_img/_common/teaser_differenzierung_ball01.jpg" /></a>'+
					'<a class="ball2" href="#"><img class="imgball2" src="'+ globalPath + "/" + globalLang + '/_img/_common/teaser_differenzierung_ball02.jpg" /></a>'+
					'<a class="ball3" href="#"><img class="imgball3" src="'+ globalPath + "/" + globalLang + '/_img/_common/teaser_differenzierung_ball03.jpg" /></a>'+
					'<a class="ball4" href="#"><img class="imgball4" src="'+ globalPath + "/" + globalLang + '/_img/_common/teaser_differenzierung_ball04.jpg" /></a>'+
					'<a class="ball5" href="#"><img class="imgball5" src="'+ globalPath + "/" + globalLang + '/_img/_common/teaser_differenzierung_ball05.jpg" /></a>'+
				'</div>';		
				
				$('#teaser').html(html);
				
				$('#teaserDifferenzierung a').mouseover(function () {
					$('#teaserDifferenzierung a img').hide();
					$('#teaserDifferenzierung a').css('z-index', '90');
					var left = getBallLeftPosition(this, 'over');
					$(this).css({'width':'277px', 'height':'277px', 'top':'18px', 'left': left+'px', 'z-index':'100'});
					$(this).find('img').show();
				}).mouseout(function () {
					$('#teaserDifferenzierung a img').hide();
					var left = getBallLeftPosition(this, 'out');
					$(this).css({'width':'175px', 'height':'175px', 'top':'65px', 'left': left+'px'});
				});
			}			
		}
	}
}

function getBallLeftPosition(element, ev) {
	
	switch (element.className) {
		case 'ball1' : var dif = 20; break;
		case 'ball5' : var dif = 84; break;
		default : var dif = 56; break;
	}
	
	if (ev == 'over') {
		var left = parseInt($(element).css('left').replace('px', '')) - dif;
	}
	else {
		var left = parseInt($(element).css('left').replace('px', '')) + dif;
	}
	
	
	return left;
}

function slideSwitch() {
    var $active = $('#slideshow img.active');
    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    var $next =  $active.next().length ? $active.next() : $('#slideshow img:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function startSlide(a, n) {
	var ul = a.parentNode.parentNode;
	$(ul).find('a').removeClass('selected');
	$(a).addClass('selected');
	var left = n * 999;			
	$("#slider").animate({"left": "-"+ left +"px"}, "slow", "easeOutQuad");
}

function startTooltips() {
	$('.tooltip img').tooltip({
		bodyHandler: function() { 
			var text = (this.tooltipAlt || this.tooltipText);
			if (text) {
				return '<div class="tooltip-container png"><div class="tooltip-top png"><!-- --></div><div class="tooltip-content png">'+ (this.tooltipAlt || this.tooltipText) +'</div></div>';
			}
			else {
				return '';
			}
		},
		showURL: false,
		fixPNG: false,
		track: true, 
		delay: 0,
		left: -73,
		positionTop: true
	});
	
	$('.tooltip-referenzen img').tooltip({
		bodyHandler: function() { 
			var text = (this.tooltipAlt || this.tooltipText);
			if (text) {
				return '<div class="tooltip-container png"><div class="tooltip-top png"><!-- --></div><div class="tooltip-content png"><img style="margin:10px;" src="'+ globalPath +'/_img/_common/logo_'+text+'_tooltip.gif" /></div></div>';
			}
			else {
				return '';
			}
		},
		showURL: false,
		fixPNG: false,
		track: true, 
		delay: 0,
		left: -73,
		positionTop: true
	});
	
}

function startNutzenAlbum() {
	$('#nutzenAlbum a').lightBox({
		overlayBgColor: '#123354',
		imageLoading: globalPath + '/_img/_common/lightbox-ico-loading.gif',
		imageBtnClose: globalPath + '/_img/_common/bt_close.jpg',
		imageBtnPrev: globalPath + '/_img/_common/lightbox_prev.jpg',
		imageBtnNext: globalPath + '/_img/_common/lightbox_next.jpg',
		imageBlank: globalPath + '/_img/_common/lightbox-blank.gif',
		containerBorderSize: 0,
		fixedNavigation: true
	});
}

function hideMenu(id) {
	document.getElementById(id).style.left = '-9999px';
}

function showMenu(id) {
	document.getElementById(id).style.left = '0px';
}

function showRecaptcha(element, themeName) {
	Recaptcha.create(recaptchaPublicKey, element, {
		theme: themeName
	});
}

function startScrollPanels() {
	$('.scrollpane').jScrollPane({
		scrollbarWidth: 14,
		showArrows: true,
		dragMinHeight: 30,
		maintainPosition: true
	});
}

function changeReferenzenTeaser(teaserSelector) {

	switch (teaserSelector) {
		case '#referenzenMicrosoft' 		: var i = 0; break;
		case '#referenzenDatev' 			: var i = 1; break;
		case '#referenzenSwix' 				: var i = 2; break;
		case '#referenzenNovell'			: var i = 3; break;
		case '#referenzenFujitsu' 			: var i = 4; break;
		case '#referenzenEsg' 				: var i = 5; break;
		case '#referenzenIntuit' 			: var i = 6; break;
		case '#referenzenNokiaSiemens' 		: var i = 7; break;
		case '#referenzenDeuscherTelekon' 	: var i = 8; break;
		case '#referenzenKago' 				: var i = 9; break;
		case '#referenzenHP' 				: var i = 10; break;
		default 							: var i = 0; break;
	}
	
	var top = i * 316;
	$("#teaserReferenzen").css({"top": "-"+ top +"px"});
	
	window.scrollTo(0,0);
}

function changeReferenzenTeaseByAnchor(anchorName) {
	if (!anchorName) {
		anchorName = 'Microsoft';
	}
	changeReferenzenTeaser('#referenzen'+ anchorName.replace('#', ''));
}