﻿// Nifty Little Helpers
//

// Superfish Menü initialisieren
$(document).ready(function(){ 
	$("ul.sf-menu").superfish(); 
});

// Fancybox initalisieren
$(document).ready(function() {
	$("a.lightbox").fancybox({
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
});
	
/* Language Dropdown
$(document).ready(function() {
	$("#lang_toggle").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
		return false;
	});
});	
*/
																 
// External Links
var links = document.getElementsByTagName("a");

for(i=0;i<links.length;i++){
	var link = links[i];
	if(links[i].rel == "external"){
		links[i].onclick = function(e){
			var event = e || window.event;
			if(event.ctrlKey) return;
			window.open(this.href);
			return false;
		}
	}
}

// Popups
function newWin(file,name,win_width,win_height) {
	pos_x = screen.availWidth - win_width - 40;
	pos_y=40;
	resizeflag="yes";
	if(navigator.appName.substring(0,8)=="Netscape" && parseInt(navigator.appVersion)==4) resizeflag="no";
	win_options = "height=" + win_height;
	win_options += ",width=" + win_width;
	win_options += ",left=" + pos_x;
	win_options += ",top=" + pos_y;
	win_options += ",toolbar=no";       
	win_options += ",location=no";    
	win_options += ",directories=no"; 
    win_options += ",status=no";    
    win_options += ",menubar=no";     
    win_options += ",scrollbars=yes";
    win_options += ",resizable=" + resizeflag;  
    win_options += ",dependent";      
    window.open(file,name,win_options);
}

// Anwendungen: Toggle-Infolayer
$(document).ready(function() {
	$(".info_toggle").hover(function(){
		// var id = $(this).attr('href');
		// var info_id = "#info_" + id.substr(1); 
		var id = $(this).attr('id');
		var info_id = "#info_" + id; 

		// infolayer
		$("#anwendungen_infolayer div").removeClass('visible').addClass('invisible');
		$(info_id).removeClass('invisible').addClass('visible');
		$("#anwendungen_infolayer").toggleClass("visible").next().slideToggle("slow");
				
		return false;
	});
	
	$(".info_toggle").hover(function(){
		var id = $(this).attr('href');
		var info_id = "#info_" + id.substr(1); 
		
		return false;
	});	
		
});	


//Timeline function – history site 
function timeline() {
    var $anchor = $('div#timeline a');
    $('div.tab:not(.first)').removeClass('visible').addClass('invisible');
    $anchor.live('click', function (e) {
        //Prevent anchor jumping
        e.preventDefault();
        //Emphasize active tab
        $('div#timeline a').removeClass('emph');
        $(this).addClass('emph');
        //Define some variables
        var id = $(this).attr('href'),
            sector = $('div#timeline').attr('data-sector');
        this.name = id.substr(id.length - 4);
        //Only load the new image if it's not active atm
        if ($('div.timeline_descriptions div' + id + '').hasClass('invisible')) {
            $('div.timeline_descriptions div.tab').removeClass('visible').addClass('invisible');
            $(id).removeClass('invisible').addClass('visible');
            //Load new picture according to the last 4 characters of its name
            $('<img class="timeline_banner"/>').load(function () {
                var $newimg = $(this),
                    $currImage = $('#feature').children('img:first');
                $newimg.insertAfter($currImage);
                $currImage.fadeOut(100, function () {
                    $(this).remove();
                });
            }).attr('src', 'http://www.vitrulan.com/_gfx/' + sector + '/features/unternehmen/historie_' + this.name + '.jpg').fadeIn(1000);
        } else {
            return null;
        }
    });
    //Cache the images
    $.cacheImage(['http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1896.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1921.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1940.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1958.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1959.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1971.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1976.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_1992.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_2002.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_2008.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_1921.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_1958.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_1971.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_1992.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_2002.jpg', 'http://www.vitrulan.com/_gfx/vi/features/unternehmen/historie_2008.jpg', 'http://www.vitrulan.com/_gfx/vtt/features/unternehmen/historie_2011.jpg']);
}

//Initialize timeline
if (!$('div#timeline').length == 0) {
    timeline();
}

