/*
* SEELE
* standard.js
*
* Author: Holger M. Stangl
* Company: Limeflavour | http://www.limeflavour.com
* Date: Februar 2009
*/


function popitup(destination,win_name,width,height, withScrollbar, toolBar) {
	if (popitup.arguments.length < 5) withScrollbar = true;			// default ist mit scrollbars
	if (width==0 ||  height == 0)
	{
		fs = window.open (destination,win_name);
	} else {
		fs = window.open (destination,win_name,'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=' + withScrollbar + ',toolbar=no,status=no,directories=no,menubar=' +toolBar + ',location=no');
		fs.resizeTo(width,height);
	}
	fs.focus();
}


function doIt(url){
	opener.document.location = url;
	self.window.close();
}


/*
jQuery.fn.keyVisualSlide = function(opts, plan) {
	var self = this,
			self_width = this.width(),
			self_height = this.height();

	// generic utilities
	function format(str) {
		for (var i = 1; i < arguments.length; i++)
			str = str.replace(new RegExp('\\{' + (i-1) + '}', 'g'), arguments[i]);
		return str;
	}

	function abort() {
		arguments[0] = 'crossSlide: ' + arguments[0];
		throw format.apply(null, arguments);
	}

	// first preload all the images, while getting their actual width and height
	(function(proceed) {

		var n_loaded = 0;
		function loop(i, img) {
			// for (i = 0; i < plan.length; i++) but with independent var i, img (for the closures)
			img.onload = function(e) {
				n_loaded++;
				plan[i].width = img.width;
				plan[i].height = img.height;
				if (n_loaded == plan.length)
					proceed();
			}
			img.src = plan[i].src;
			if (i + 1 < plan.length)
				loop(i + 1, new Image());
		}
		loop(0, new Image());

	})(function() {  // then proceed
		if (! opts.fade)
			abort('missing fade parameter.');
		if (! opts.sleep)
			abort('missing sleep.')
			
		var fade_ms = Math.round(opts.fade * 1000);
		var sleep = Math.round(opts.sleep * 1000);
	
			
		// set container css
		self.empty().css({
			overflow: 'hidden',
			padding: 0
		});
		if (! self.css('position').match(/absolute|relative|fixed/))
			self.css({ position: 'relative' });
		if (! self.width() || ! self.height())
			abort('container element does not have its own width and height');
		// random sorting
		if (opts.shuffle)
			plan.sort(function() {
				return Math.random() - 0.5;
			});
		
		// prepare each image
		for (var i = 0; i < plan.length; ++i) {

			var p = plan[i];
			if (! p.src)
				abort('missing src parameter in picture {0}.', i + 1);

			var elm;
			elm = jQuery(format('<img src="{0}"/>', p.src));
			elm.appendTo(self);
		}
		var imgs = self.find('img').css({
			position: 'absolute',
			visibility: 'hidden',
			top: 0,
			left: 0,
			border: 0
		});
		imgs.eq(0).css({ visibility: 'visible' });
		
		function create_chain(i, chainf) {
			// building the chain backwards, or inside out
			if (i % 2 == 0) {
				if (sleep) {

					// still image sleep

					var i_sleep = i / 2,
							i_hide = (i_sleep - 1 + plan.length) % plan.length,
							img_sleep = imgs.eq(i_sleep),
							img_hide = imgs.eq(i_hide);

					var newf = function() {
						img_hide.css('visibility', 'hidden');
						setTimeout(chainf, sleep);
					};
				}
			} else {
				if (sleep) {

					// still image cross-fade

					var i_from = Math.floor(i / 2),
							i_to = Math.ceil(i / 2) % plan.length,
							img_from = imgs.eq(i_from),
							img_to = imgs.eq(i_to),
							from_anim = {},
							to_init = { visibility: 'visible' },
							to_anim = {};

					if (i_to > i_from) {
						to_init.opacity = 0;
						to_anim.opacity = 1;
					} else {
						from_anim.opacity = 0;
					}

					var newf = function() {
						img_to.css(to_init);
						if (from_anim.opacity != undefined)
							img_from.animate(from_anim, fade_ms, 'linear', chainf);
						else
							img_to.animate(to_anim, fade_ms, 'linear', chainf);
					};

				}
			}

			if (i > 0)
				return create_chain(i - 1, newf);
			else
				return newf;
		}
		var animation = create_chain(plan.length * 2 - 1, function() { return animation(); });

		// start animation
		animation();
		
	});
	
	return self;		
};
*/

$(document).ready(function() {


	// Key Navigation SubMenu
	$('.navigationKey').each(function() {
		
		// Alle verstecken
		$(this).find('.navigationKeyB').hide();
		var naviEntry = $(this);
		
		// Hover Effekt
		$(this).children('li').mouseover( function() {
			
			var thisHoverImage = $(this).find('img:first').attr('rel');
			var thisImage = $(this).find('img:first').attr('src');
			$(this).find('img:first').attr('rel', thisImage );
			$(this).find('img:first').attr('src', thisHoverImage );
			
			
			// so könnte es auch gehen ( in der art .. kanns nicht testen)
			/*
			var activeImage = $(this).find('img:first')
			var thisHoverImage = activeImage.attr('rel');
			var thisImage = activeImage.attr('src');
			$('<img src="'+thisHoverImage+'" rel="'+thisImage+'">').hide().prependTo(naviEntry).fadeIn(500, function(){ activeImage.remove(); })
			*/
			$(this).find('.navigationKeyB').show();
			//$(this).find('.navigationKeyB').fadeIn(600);
			
		});
			
		$(this).children('li').mouseout( function() {
				
			var thisHoverImage = $(this).find('img:first').attr('rel');
			var thisImage = $(this).find('img:first').attr('src');
			$(this).find('img:first').attr('rel', thisImage );
			$(this).find('img:first').attr('src', thisHoverImage );
			
			
			$(this).find('.navigationKeyB').hide();
				
		});
		
	});
	
	// Key Navigation SubMenu
	$('.navigationKeyB li img').each(function() {
		
		$(this).mouseover( function() {
			
			var thisHoverImage = $(this).attr('rel');
			var thisImage = $(this).attr('src');
			$(this).attr('rel', thisImage );
			$(this).attr('src', thisHoverImage );
			
		});
			
		$(this).mouseout( function() {
				
			var thisHoverImage = $(this).attr('rel');
			var thisImage = $(this).attr('src');
			$(this).attr('rel', thisImage );
			$(this).attr('src', thisHoverImage );
				
		});
	});
	
	
	jQuery.each(jQuery.browser, function(i, val) {
		
		if( i!="msie" && jQuery.browser.version.substr(0,3)!="6.0" )
		{
		
		// Project Detail Thumbs
		$('.containerListB .thumbBox').each(function() {
													 
			$( this ).css('position','relative');
			
			$( this ).mouseover( function() {
				$(this).css("z-index",1002);
				$(this).find('.overImg').show();
			});
			
			$( this ).mouseout( function() {
				$(this).css("z-index",1000);
				$(this).find('.overImg').hide();
			});
		});
		
		// Project List Thumbs
		$('.containerThumb .thumbBox').each(function() {
			
			$( this ).css('position','relative');
			
			$( this ).mouseover( function() {
				$(this).css("z-index",1002);
				$(this).find('.overImg').show();
			});
			
			$( this ).mouseout( function() {
				$(this).css("z-index",1000);
				$(this).find('.overImg').hide();
			});
		});
		
		}
		
	});
	
	$("a.iframe").fancybox( {
		'hideOnContentClick': false,
		'zoomOpacity' : true,
		'overlayShow' : true,
		'overlayOpacity' : 0.6,
		'padding' : 10,
		'frameWidth' : 800,
		'frameHeight' : 600
	});
	
	
	$("a.lightbox").fancybox( {
		'zoomOpacity' : true,
		'overlayShow' : true,
		'overlayOpacity' : 0.6,
		'padding' : 3,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500
	});
/*
	// jQuery LightBox
	$(function(){
		$.Lightbox.construct({
			text: {
				close: '',	
				image: '',
				of: '',
				closeInfo: '',
				download: '',
				help: {
					close: '',
					interact: ''
				}
			},
			opacity: 0.6,
			speed: 300,
			padding: 0,
			auto_resize: true,
			show_linkback: false,
			download_link: false,
			show_info: false,
			show_extended_info: false
		});
	
	});
*/	
		
	
	
	$('.selectBox').each(function() {
		
		
		// Define Click Function on div.selected
		$(this).find('.selected').click( function() {
			$(this).addClass('selectedHover');
			$(this).next().show();
		});
		$(this).find('.selected').mouseout( function() {
			$(this).removeClass('selectedHover');
			//$(this).parent().find('.optionBox').hide();
			$(this).next().hide();
		});
		
		
		// Define MouseOver Function on div.optionBox
		$(this).find('.optionBox').mouseover( function() {
			$(this).prev().addClass('selectedHover');
			$(this).show();
		});
		$(this).find('.optionBox').mouseout( function() {
			$(this).prev().removeClass('selectedHover');
			$(this).hide();
		});
		
		
		
		$('.selectBox .optionBox').each(function() {
			
			// Define MouseOver Function on div.option
			$(this).find('.option').mouseover( function() {
				$(this).addClass('optionHover');
			});
			$(this).find('.option').mouseout( function() {
				$(this).removeClass('optionHover');
			});
			
			
			$(this).find('.option').click( function() {
				$(this).parent().hide();
			});
			
		});
		
	});
	
	
	
	/* Register */
	$('#company').change( function(){

		// STANDORT DATEN HOLEN
		$.getJSON(
			"index.php", { modid: $('#company').attr('value') ,modaction: 'getCompanyDataAX', page: $('#pageId').attr('value') },
			function(data){
				
				if ( data['Id'] ) {
					
					// STANDROT DATEN EINTRAGEN
					$('#phonePre').attr('value', data['PhonePre'] );
					$('#faxPre').attr('value', data['FaxPre'] );
					
				}
			}
		)
	
	});
	
	
	
	/* Glossary */
	$('.toogleBox').each(function() {
		var $container = $(this);
		if ( $(this).attr('class') == "toogleBox toogleBoxOpen" )
		{
			$(this).find('h2 a').click().toggle( 
				function() {
					$('.thumbBox',this).slideUp('fast');
					$container.removeClass('toogleBoxOpen');
					return false;
				},
				function() {
					$('.thumbBox',this).slideDown('fast');
					$container.addClass('toogleBoxOpen');
					return false;
				}
			);
		}
		else
		{
			$(this).find('h2 a').click().toggle( 
				function() {
					$container.addClass('toogleBoxOpen');
					$('.thumbBox',this).slideDown('fast');
					return false;
				},
				function() {
					$container.removeClass('toogleBoxOpen');
					return false;
				}
			);
		}
	});
	
	
	// Blur Links
	$('a').click(function() {
		this.blur();
	});
	
	
	// Beispiel Werte im Glossar
	$('#exampleterm').hover(
		function()
		{	
			var tempterm = $('#term').val();
			$('#tempterm').val(tempterm);
			$('#term').val('structure');
			
			var tempdescription = $('#description').val();
			$('#tempdescription').val(tempdescription);
			$('#description').val('Architektur ist filigran. seele schafft eine Minimierung von Stahl- und Aluminiumtragwerken in der Gebäudehülle durch Materialbeherrschung gerade auch im lastabtragenden Einsatz von Glas. Diese Materialkunst reizt seele bis zum Maximum aus.');
		},
		function()
		{
			var term = $('#tempterm').val();
			$('#term').val(term);
			
			var description = $('#tempdescription').val();
			$('#description').val(description);
		}
	);
	
	$('#exampledescription').hover(
		function()
		{	
			var tempterm = $('#term').val();
			$('#tempterm').val(tempterm);
			$('#term').val('structure');
			
			var tempdescription = $('#description').val();
			$('#tempdescription').val(tempdescription);
			$('#description').val('Architektur ist filigran. seele schafft eine Minimierung von Stahl- und Aluminiumtragwerken in der Gebäudehülle durch Materialbeherrschung gerade auch im lastabtragenden Einsatz von Glas. Diese Materialkunst reizt seele bis zum Maximum aus.');
		},
		function()
		{
			var term = $('#tempterm').val();
			$('#term').val(term);
			
			var description = $('#tempdescription').val();
			$('#description').val(description);
		}
	);

});


function showCnt( areaID, imgID ) {

	// Hide all text containers
	$('.containerDetail').each(function() {
		if ( $(this).not('display:none;') ) {
			$(this).hide();
		}
	});
	// Set all navigation points to inactive
	$('.navigationFunctions li').each(function() {
		$(this).removeClass('active');
	});
	// Set all thumbnails to full opacity
	$('.thumbImg').each(function() {
		$(this).css('opacity','1');
	});
	// Hide detail images 
	$('#projectImage').hide();
	$('.imageBox').hide();
	// Hide pagination
	$('.paginationBox').hide();
	$('.paginationBox a').each(function() {
		$(this).removeClass('active');
	});
	
	
	
	if ( imgID != 0 ) 
	{
		
		$('.containerCenterBottom').css('width','728px');
		$('.paginationBox').show();
		
		
		$('.projectImageThumb'+imgID).css('opacity','0.3');
		$('.projectImageLink'+imgID).addClass('active');
		
		$('#projectImage').show();
		$('.projectImageDetail'+imgID).fadeIn(300);
	}
	else
	{
		$('.containerCenterBottom').css('width','651px');
	}
	
	$('.'+areaID+'Link').addClass('active');
	
	$('#'+areaID).fadeIn(600);
	
}
