﻿/***** Easing plugin *****/

jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeInOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInExpo:function(e,f,a,h,g){return(f===0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f===0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInRegular:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutRegular:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutRegular:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a}});

/***** Cookie plugin *****/

jQuery.jcookie=function(d,e,b){if(arguments.length>1&&(e===null||typeof e!=="object")){b=jQuery.extend({},b);if(e===null){b.expires=-1}if(typeof b.expires==="number"){var g=b.expires,c=b.expires=new Date();c.setDate(c.getDate()+g)}return(document.cookie=[encodeURIComponent(d),"=",b.raw?String(e):encodeURIComponent(String(e)),b.expires?"; expires="+b.expires.toUTCString():"",b.path?"; path="+b.path:"",b.domain?"; domain="+b.domain:"",b.secure?"; secure":""].join(""))}b=e||{};var a,f=b.raw?function(h){return h}:decodeURIComponent;return(a=new RegExp("(?:^|; )"+encodeURIComponent(d)+"=([^;]*)").exec(document.cookie))?f(a[1]):null};


/***** WICKEDWEB LIGHTBOX v1.1 | COPYRIGHT WICKEDWEB 2010 *****/

function setCSS(css) {
	try{
		document.getElementsByTagName("head")[0].appendChild(css);
	}catch(e){
		setTimeout(function(){setCSS(css)}, 100);
	}
}
var css = document.createElement("link");
css.setAttribute("href","/lightbox/wwightbox.css");
css.setAttribute("rel","stylesheet");
css.setAttribute("type","text/css");
setCSS(css);
css = null;

String.prototype.endsWith = function (b) {
    return (this.match(b + "$") == b)
};

function querySt(value, string){
	valueArray = string.split('?').join('&').split('&');
	for(i=0; i<valueArray.length; i++) {
		result = valueArray[i].split('=');
		if(result[0] == value) {
			return result[1];
		}
	}
}

function repositionLightBox(){
	if(($('#lightBoxInner').outerHeight() + 40) > $(window).height()){
		$('#lightBoxContent').css('top', ($(window).scrollTop() + 20) + 'px').css('position', 'absolute').css('margin-top', 0);
	}
	else{
		$('#lightBoxContent').css('top', '50%').css('position', 'fixed').css('margin-top', -($('#lightBoxInner').outerHeight() / 2));
	}
}

function animateLightBox(){
	$('#lightBoxInner').prepend('<a href="close" id="closeLightBoxBtn" class="closeLightBox"><img src="/lightbox/close_btn.gif" /></a>')
	var mTop = -($('#lightBoxInner').outerHeight() / 2);
	var mLft = -($('#lightBoxInner').outerWidth() / 2);
	if(($('#lightBoxInner').outerHeight() + 40) > $(window).height()){
		$('#lightBoxContent').css('top', ($(window).scrollTop() + 20) + 'px').css('position', 'absolute').css('margin-top', 0);
		mTop = 0;
	}
	else{
		$('#lightBoxContent').css('top', '50%').css('position', 'fixed');
	}
	$('#lightBoxContent').stop().animate({ 
		width: $('#lightBoxInner').outerWidth(),
		height: $('#lightBoxInner').outerHeight(),
		marginTop: mTop,
		marginLeft: mLft,
		opacity: 1
	}, 600, "easeInOutRegular", function(){
		repositionLightBox();
		$('#lightBoxContent').css('filter', '');
		$('#lightBoxInner').css('visibility', 'visible');
		$('#lightBoxInner').stop().fadeTo(500, 1, function(){
			$('#lightBoxContent, #lightBoxInner').css('filter', '')
		});
	});
}

function detectContent(boxID){
	$('#lightBoxInner').empty();
	$('#lightBoxInner').width('auto').height('auto');
	$('#lightBoxContent').css('overflow', 'hidden').width($('#lightBoxContent').width()).height($('#lightBoxContent').height()).css('margin', (-($('#lightBoxContent').outerHeight() / 2)) + 'px 0 0 ' + (-($('#lightBoxContent').outerWidth() / 2)) + 'px');
	myTitle = querySt('title', boxID);
	myDesc = querySt('desc', boxID);
	myWidth = querySt('width', boxID);
	myHeight = querySt('height', boxID);
	if(myWidth !== undefined){
		$('#lightBoxInner').width(parseInt(myWidth));
	}
	if(myHeight !== undefined){
		$('#lightBoxInner').height(parseInt(myHeight));
	}
	if(myTitle !== undefined){
		$('#lightBoxInner').append('<h1>' + myTitle + '</h1>')
	}
	if(myDesc !== undefined){
		$('#lightBoxInner').append(myDesc);
	}
	if(boxID.indexOf('?') > -1){
		boxID = boxID.slice(0, boxID.indexOf('?'));
	}
	
	r = document.location.href.toString().replace(document.location.hash.toString(), '');
    if(boxID.indexOf('?') > -1){
        q = boxID.slice(boxID.indexOf('?'));
        boxID = boxID.slice(0, boxID.indexOf('?'))
    }
    if(boxID.indexOf(r) === 0){
        boxID = boxID.replace(r, '');
    }
    if(boxID.indexOf('#') === 0) {
		$(boxID).clone(true).appendTo('#lightBoxInner').show();
		animateLightBox();
    }
	else if(boxID.endsWith('.html') || boxID.endsWith('.htm') || boxID.endsWith('.php') || boxID.endsWith('.aspx')){
		if($('#lightBoxContent:visible').size() <= 0){
			animateLightBox();
		}
		$('#lightBoxInner').load(boxID, function(){
			animateLightBox();
		});	
	}
	else if(boxID.endsWith('.jpg') || boxID.endsWith('.gif') || boxID.endsWith('.png') || boxID.endsWith('.bmp') || boxID.endsWith('.tiff')){
		if($('#lightBoxContent:visible').size() <= 0){
			animateLightBox();
		}		
		var img = "img" + boxID.slice(boxID.lastIndexOf("/") + 1, boxID.lastIndexOf("."));
		eval[img] = new Image();
		eval[img].onload = function (evt) {
			$('#lightBoxInner').fadeTo(0, 0, function(){
				$('#lightBoxInner').append(eval[img]);
				animateLightBox();
			});
		};
		eval[img].src = boxID;
	}
}

function showLightBox(boxID){
	$('#lightBoxInner').css('visibility', 'hidden');
	if($('#lightBoxContent:visible').size() > 0){
		detectContent(boxID);
	}
	else{
		$('#lightBox').stop().show().fadeTo(0, 0).fadeTo(500, 1, function(){
			$('#lightBoxContent').stop().show().fadeTo(0, 0, function(){
				detectContent(boxID);
			});
		});
	}
}

function openLightBox(boxID){
	if($('#lightBoxContent:visible').size() > 0){
		$('#lightBoxInner').stop().fadeTo(500, 0, function(){
			showLightBox(boxID);
		});
	}
	else{
		$('#lightBoxInner').fadeTo(0, 0, function(){
			showLightBox(boxID);
		});
	}
}

function closeLightBox(){
	$('#lightBoxContent').stop().fadeTo(500, 0, function(){
		$('#lightBox').stop().fadeTo(500, 0, function(){
			$('#lightBoxContent').hide().width('100px').height('100px');
			$('#lightBox').hide();
			$('#lightBoxInner').empty();
		});
	});
}

function initWWightBox(){
	$('body').append('<div id="lightBox" class="closeLightBox"></div><div id="lightBoxContent"><div id="lightBoxMid"><div id="lightBoxInner"></div></div></div>');
	$(document).bind('mouseup', function(e){
		$('.zoomBox img').unbind('mousemove');
		$('.zoomBox img').css('cursor', 'pointer');
	});
	$(window).resize(function(){
		repositionLightBox();
	});
	//if(document.location.href.indexOf('?tester') > -1){
	if($.jcookie('welcome') === null){
		$.jcookie('welcome', 'seen');
		$('body').append('<div id="welcomeText" style="display:none;"><img height="105" width="170" alt="Vega Logo" src="/images/vega_logo.gif"><h1>Welcome to the old website of VEGA in Germany</h1><p>On 1 December 2010, VEGA Deutschland GmbH split into two separate companies - VEGA Space GmbH (Darmstadt) focusing on our civil and military aerospace business, and VEGA Deutschland GmbH (Cologne) focusing on our IT/SAP services business.<br /><br />To visit the VEGA Space GmbH website, click <a href="http://www.vegaspace.de/default.aspx?lang=en">here</a><br />To visit the VEGA Deutschland website, click <a href="http://www.vega-deutschland.de">here</a></p><br /><h1>Willkommen auf der alten Website von VEGA in Deutschland</h1><p>Am 1. Dezember 2010 wurde VEGA Deutschland in zwei separate Firmen geteilt - VEGA Space GmbH in Darmstadt mit dem Schwerpunkt auf unserem Geschäft in der zivilen und militärischen Luft- und Raumfahrt und VEGA Deutschland GmbH in Köln mit Fokus auf IT- und SAP-Consulting.<br /><br />Um auf die Website der VEGA Space GmbH zu gelangen, klicken Sie <a href="http://www.vegaspace.de/default.aspx?lang=de">hier</a>.<br />Um auf die Website der VEGA Deutschland GmbH zu gelangen, klicken Sie <a href="http://www.vega-deutschland.de">hier</a>.</p>')
		openLightBox('#welcomeText?width=500');
	//}
	}
}

$('.lightBox').live('click', function(e){
	openLightBox($(this).attr('href'));
	return false;
});

$('.closeLightBox').live('click', function(){
	closeLightBox()
	return false;
});

$(document).keypress(function(event){
	if($('#lightBoxContent:visible').size() > 0 && event.keyCode == '27'){
		event.preventDefault();
		closeLightBox();
	}
});


/***** ON READY FUNCTIONS *****/

$(document).ready(function(){
	//if(document.location.href.indexOf('?tester') > -1){
		initWWightBox();
	//}
});
