/*****************
/*****************
**
** Projekt: wvgkainz
**
/*****************
******************/


/** Config **********************************************************************************************/

var overSpeed = 400;
var outSpeed = 400;

var overSpeedLinks = 200;
var outSpeedLinks = 400;

var colors = {"default":"#525252","over":"#DD4D16","background-over":"#FFFFFF","background-default":"#DCDDDD","background-alt":"#E3E3E3"};

/********************************************************************************************************/



var ie6 = false;
if (jQuery.browser.version == 6.0) {
	if (jQuery.browser.msie) {
		ie6 = true;
	}
}




/**
	*
	* jQuery adaption of swfObject 
	*
	*/

function swfObject() {
	var obj = $('.flash');
	if (obj.length > 0) {
		obj.each(function() {
			var imgFile = $(this).find("img").attr("src");
			if (!imgFile) return;
			var flashFile = imgFile.slice(0,-4) + ".swf";
			var flashHeight = $(this).css("height");
			$(this).flash({	
				'src':flashFile,
				'width':'654',
				'height': flashHeight,
				'wmode' : 'transparent',
				'allowfullscreen':'false',
				'allowscriptaccess':'always',
				'version':'9.0.24'
			});
		});
	}
}






/**
	*
	* IE 6 PNG Transparency Hack
	*
	*/


function replacePNG() {

	if (ie6 && $("#presenter").length > 0) {
		var img = $("#presenter img").attr("src");
			if (!img) return;
		var imgName = img.slice(0,-4);
		$("#presenter img").attr("src", imgName + ".gif");
	}
}



//animate Bulletbox

function animateBulletbox() {
	var obj = $("#header-col-2 ul li");
	var vAlign = 6;
	var distance = 70 + vAlign;
	var current = -distance;
	var currentObj =  $("#header-col-2 ul li a.current").not("ul li ul li a.current");
	if (currentObj.length > 0) current = Math.floor($(currentObj).parent().position().top);
	$("#header-col-1 img").css("margin-top",(distance + current) + "px");
	$(obj).not("ul li ul li").bind("mouseenter",function() {
		var pos = Math.floor($(this).position().top);
		$("#header-col-1 img").stop().animate({marginTop: (distance + pos) + "px"}, 600);
	});	
	$("#header-col-2").bind("mouseleave",function() {
		$("#header-col-1 img").stop().animate({marginTop: (distance + current) + "px"}, 600);
	});	
	$()
	
}


// Menu

function menu(obj){

	$(obj).find("ul").css({display: "none"}); // Opera Fix


	$(obj).find("li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).stop().delay(200).fadeIn(overSpeed);
	},function(){
		$(this).find('ul:first').css({visibility: "hidden",display: "none"});
//		$(this).find('ul:first').css({visibility: "visible",display: "block"}).delay(700).fadeOut(1);
	});

}
 
 
function changeLinkColor(obj,over,out) {
	$(obj).bind("mouseenter",function() {
		$(this).stop().animate(over, overSpeedLinks);
	});
	$(obj).bind("mouseleave",function() {
		$(this).stop().animate(out, outSpeedLinks);
	});
}


//Startseite

function scaleStartImages(obj,resizeFactor) {
		if (!obj.length) return;
		
		obj.each(function() {
			var thisItem = $(this);								
			var img = thisItem.find("img");
			var resize = {
						obj: img,
						top:thisItem.css("top"),
						left:thisItem.css("left"),
						newLeft: (img.width() *  resizeFactor - img.width()) / 2,	
						newTop:  (img.height() * resizeFactor - img.height()) / 2,
						width: img.width(),
						height: img.height(),
						newWidth: img.width() *  resizeFactor,
						newHeight: img.height() *  resizeFactor,
						zindex: thisItem.css("z-index"),
						parent: thisItem
					};
			thisItem.mouseenter(function() {
				animation(resize,true);										 
			}).mouseleave(function() {
				animation(resize,false);
			}).click(function(e) {
				animation(resize,false);
			});	
		});
			
		function animation(resize,up) {
			var properties = {};
			(up) ?	properties = {str:"-=",zindex:100,width:resize.newWidth,height:resize.newHeight,top:resize.newTop,left:resize.newLeft} 
			     : 	properties = {str:"",zindex:resize.zindex,width:resize.width,height:resize.height,top:resize.top,left:resize.left};
			resize.obj.stop().animate({"width":properties.width,"height":properties.height});
			resize.parent.stop().animate({
				"top": properties.str + properties.top,
				"left": properties.str + properties.left
			}).css("z-index",properties.zindex);
		}
}
 
 
 
			/*
			*   FAncybox
			*/

	function fancy(obj) {
	
		if (!obj.length) return;
		
		obj.each(function() {
		
//				$("a[rel=img_group]")	
		
			var imgGroup = $(this).find("a");
		
			imgGroup.css("opacity",0.8);
			imgGroup.hover(function() {
				$(this).fadeTo(100,1);
			},
			function() {
				$(this).fadeTo(100,0.8);
			});

			imgGroup.fancybox({
				'padding' : 0,
//				'transitionIn'	:	'elastic',
//				'transitionOut'	:	'elastic',
				'speedIn'		:	600, 
				'speedOut'		:	200, 
				'overlayShow'	:	true,
				'overlayOpacity' : 0.8,
				'titlePosition' 	: 'over',	
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		});
	}
 
 
 $(document).ready(function(){	

	replacePNG();	

	var mainOver = {color:colors["over"],backgroundColor:colors["background-over"]};
	var mainOut = {color:colors["default"],backgroundColor:colors["background-default"]};
	changeLinkColor($("div#header-col-2 ul li a").not(".current"),mainOver,mainOut);


	var langOver = {color:colors["over"],backgroundColor:colors["background-over"]};
	var langOut = {color:colors["default"],backgroundColor:colors["background-alt"]};
	changeLinkColor($("div#languages ul ul li a").not(".current,.label"),langOver,langOut);

	swfObject();

	animateBulletbox();
	menu($("#header-col-2 ul"));
	menu($("div#languages ul"));
	
	scaleStartImages($("div.img-container"),3);

	fancy($("div.galerie"));


});
