$(document).ready(function(){


	//target blank
	$("a[@href^='http://'],a.extern").attr('target','_blank');
	$("a[@href^='http://']").addClass('extern');
	
	$("a[@href$=.pdf]").addClass('pdf');
	$("a[@href$=.doc]").addClass('doc');
	$("a[@href$=.xls]").addClass('xls');
	$("a[@href$=.docx]").addClass('docx');
	$("a[@href^=mailto]").addClass('mailto');
	
	//IE PNG FIX
	$.ifixpng('_js/jquery.ifixpng.pixel.gif');
	$('#navigation li span').ifixpng();
	
	//Fix IE PNGs that have links. I hate IE.
	if (document.attachEvent) {
		$('div#branding').append('<div id="IEFIX-navoverlay"><ul></ul></div>');
		$('#navigation a').each(function(i){
			$('#IEFIX-navoverlay ul').append('<li><a href="'+$(this).attr('href')+'"><img src="files/_js/jquery.ifixpng.pixel.gif" style="width:100%;height:100%;" /></a></li>');
		});
		
	}
	
	$('#navigation li a').css('cursor','pointer');

	
	
	
	//###------------------------------------------------- branding-pager
	var banners = $('div#branding-banners .banner');
	if (banners.length>1) {
		$('div#container').append('<div id="branding-pager"><ul><li><a class="back" href="#b">&nbsp;</a></li><li><a class="next" href="#n">&nbsp;</a></li></ul></div>');
	}
	$('div#branding-banners .banner').each(function(i) {
		if (i>0) {
			$(this).css({opacity:"0"});
		}
	});
	$('div#branding-pager a.next').click(function(){

		$('div#branding-banners .banner:nth-child(2)').animate({opacity:"1"},1000,function(){
			$('div#branding-banners').append($('div#branding-banners .banner:nth-child(1)'));
			$('div#branding-banners .banner:last-child').css({opacity:"0"});
			//reset, just in case someone is clicking too much.
			$('div#branding-banners .banner:first-child').css({opacity:"1"});
			$('div#branding-banners .banner').each(function(i) {
				if (i>0) { $(this).css({opacity:"0"}); }
			});
		});
		$(this).blur();		
		
		return false;
	});
	
	
	$('div#branding-pager a.back').click(function(){

		$('div#branding-banners').prepend($('div#branding-banners .banner:last-child'));
		$('div#branding-banners .banner:first-child').css({opacity:"1"});
		$('div#branding-banners .banner:nth-child(2)').animate({opacity:"0"},1000,function(){
			//reset, just in case someone is clicking too much.
			$('div#branding-banners .banner:first-child').css({opacity:"1"});
			$('div#branding-banners .banner').each(function(i) {
				if (i>0) { $(this).css({opacity:"0"}); }
			});
		});


		$(this).blur();
		return false;
	});
	//###----------------------------------------------------------------------------------------------
	
	
	
	

	
	
	
	//### minigallery-pager--------------------------------------------------
	
	$('div.galerie-container').each(function(i){
		var imgs = $(this).children('img');
		if (imgs.length>1) {
			$(this).parent().append('<div class="minigal-pager"><ul><li><a class="back" href="#b">&nbsp;</a></li><li><a class="next" href="#n">&nbsp;</a></li></ul></div>');
		}
	});
	
	$('div.galerie-container img').each(function(i) {
		if (i>0) {
			$(this).css({opacity:"0"});
		}
	});
	
	$('div.minigal-pager a.next').click(function(){
		var x = $(this).parent().parent().parent().parent().children('div.galerie-container');
		
		x.children('img:nth-child(2)').animate({opacity:"1"},1000,function(){
			x.append(x.children('img:nth-child(1)'));
			x.children('img:last-child').css({opacity:"0"});
			
			//reset, just in case someone is clicking too much.
			x.children('img:first-child').css({opacity:"1"});
			x.children('img').each(function(i) {
				if (i>0) { $(this).css({opacity:"0"}); }
			});
		});
		
		$(this).blur();		
		return false;
	});
	$('div.minigal-pager a.back').click(function(){
		var x = $(this).parent().parent().parent().parent().children('div.galerie-container');
		
		x.prepend(x.children('img:last-child'));
		x.children('img:first-child').css({opacity:"1"});
		x.children('img:nth-child(2)').animate({opacity:"0"},1000,function(){
			//reset, just in case someone is clicking too much.
			x.children('img:first-child').css({opacity:"1"});
			x.children('img').each(function(i) {
				if (i>0) { $(this).css({opacity:"0"}); }
			});
		});
		
		$(this).blur();		
		return false;
	});	
	//###----------------------------------------------------------------------------------------------
	
	
	
	
	
	
	
	
	
	//### moebel modul --------------------------------------------------------

	
	
	
	$('div.item').css('cursor','pointer');
	
	$('div.item img.moebel-over').each(function(i){
		$(this).parent().css('background-image','url('+$(this).attr('src')+')');
	});
	
	//mouseover
	$('div.item img.moebel-normal').mouseover(function(){
		$(this).animate({opacity:"0"},300);
	});	

	//mouseout
	$('div.item img.moebel-normal').mouseout(function(){
		$(this).animate({opacity:"1"},300);
	});	
	
	//click
	var moebelsrc='';
	$('div.item img.moebel-normal').click(function(){
		
		
		
		moebelsrc = $(this).parent().children('img.moebel-large').attr('src');
		moebelname = $(this).parent().children('h4.moebel-name').html();
		moebeldesc = $(this).parent().children('div.moebel-desc').html();
		
		
		
		$.scrollTo(0,800,{
			onAfter: function() {
				// remove any existing banners
				$('div#branding-banners .banner').each(function(i) {
					if (i>0) { $(this).remove(); }
				});
				
				$('div#branding-banners').append('<img src="'+moebelsrc+'" style="display:none;" class="banner" alt="" />');
				$('div#branding-banners .banner:last-child').css({opacity:"0",display:'block'});
				$('div#branding-banners img.banner:nth-child(2)').animate({opacity:1},1000,function(){
					$('div#branding-banners img.banner:first-child').remove();
					
					//swap out the text if a dynamic textfield exists.					
					x = $('.dynamictext');
					if (x.length>0) {
						text = '';
						if (moebelname!="") {
							text += '<h2 class="moebel-replacedtext">'+moebelname+'</h2>';
						}
						if (moebeldesc!="") {
							text += moebeldesc;
						}
						
						$('.dynamictext').slideUp('slow',function(){
							$('.dynamictext .sectiontext').html(text);
							setTimeout(function(){
							$('.dynamictext').slideDown('slow');
							},100);
							
						});						
					}
				});
								
			}
		});
		
		
		
	});
	//###----------------------------------------------------------------------------------------------
	
	

	//### vita modul ------------------------------------------
	$('div.vitatext a').click(function(){
		
		if ($('div#vitalayer').css('display')=="block") {
			$('div#vitalayer').animate({opacity:"0"},1000,function() {
				$('div#vitalayer').remove();
			});
		}
		else {
			$('div#container').append('<div id="vitalayer">'+$(this).parent().parent().children('div.sectiontext').html()+'</div>');
			$('div#vitalayer').css({opacity:"0",display:"block"});
			$('div#vitalayer').animate({opacity:"1"},1000,function(){
				$.scrollTo(244,800);
			});
		}
		$(this).blur();
		return false;
	});
	//###----------------------------------------------------------------------------------------------
	
	
	
});
