/* Version control Subversion $Id: extends-jquery.js 113 2011-01-15 13:21:44Z Ralf $ */
var t;
var n;
var ip44 = {
	init: function() {	
		window.clearTimeout(t)
		window.clearTimeout(n)	
		$('.halfboxleft').css({height:$('.halfboxleft').height()})
		$('.halfboxright').css({height:$('.halfboxright').height()})
		$('.halfblockboxleft').css({marginBottom:$('.halfboxleft').height()})
		$('.halfblockboxright').css({marginBottom:$('.halfboxright').height()})
		$('ul.productlist br, ul.themelist br, ul.awards br').remove()
		
		if($('.productlist').html()!=null) $('.halfboxleft, .halfboxright').hide()
		if($('.wrapper .productlist, .wrapper .productlist_hover, .leftbox').html()!=null) $('.main-navigation, .sub-navigation, .langswitch, .longbox, .halfboxleft, .halfboxright, .halfblockboxleft, .halfblockboxright, .wrapper, .facebook, .newsbox').fadeIn(200)

		if(self.location.href.indexOf('?')<0) {
			$('body').prepend('<div class="move">&nbsp;</div>')	
		}

		if($('.themelist').html()!=null) {		
			if(self.location.href.indexOf('?')<0) ip44.themefade(-1)
			else ip44.themeflip(0)
		}
		
		n=setTimeout(function(){ip44.productflip()},2000)
		
		if($('.productlist').html()!=null) $('.wrapper').show()
		$('.wrapper .productlist li').hide().eq(0).show()
		$('.wrapper .productlist').parents('.wrapper').append('<img class="productprev" src="/globalimages/arrow_left_milieu.png" alt="" />').children('.productprev').hide()
		$('.wrapper .productlist').parents('.wrapper').append('<img class="productnext" src="/globalimages/arrow_right_milieu.png" alt="" />').children('.productnext').hide()
		
		ip44.toggle()
		ip44.productfade()
		ip44.productclick()
		ip44.blocktoggle()
		ip44.expandCard()
		ip44.callMap()
		ip44.callMapWavePipe()
		ip44.expandPress()
		$('.pics a').fancybox({
			titlePosition:'inside',
			overlayColor:'#182838'
		})
		$('.themelist li:last a').fancybox({
			titlePosition:'inside',
			overlayColor:'#182838'
		})
		
		$('#loader').fadeOut(800).remove()
		ip44.ghostset()

	},
	themefade: function(next) {	
		window.clearTimeout(t)
		window.clearTimeout(n)	
		n=setTimeout(function(){
			$('.wrapper').fadeIn(899)
			$('.themelist li').eq(next+1).fadeIn(900)
			t=setTimeout(function(){
				if($('.themelist li').eq(next+1).next('li').html()!=null) ip44.themeflip(next+1)				
			},798)
			$('div.move').remove()
		},3000)	
		
		$('div.move').mousemove(function(){
			window.clearTimeout(n)	
			window.clearTimeout(t)		
			$('.wrapper').fadeIn(899)
			$('.themelist li').eq(next+1).fadeIn(900)
			t=setTimeout(function(){
				if($('.themelist li').eq(next+1).next('li').html()!=null) ip44.themeflip(next+1)
			},798)
			$('div.move').remove()
		})
	},
	themeflip: function(next){
		window.clearTimeout(t)
		window.clearTimeout(n)
		$('.themelist li').eq(next).fadeIn(800)
		if(self.location.href.indexOf('?')>-1) $('.wrapper, .main-navigation, .sub-navigation, .langswitch, .longbox, .facebook, .newsbox').fadeIn(500)
		t=setTimeout(function(){
			if($('.themelist li').eq(next).next('li').html()!=null) ip44.themeflip(next+1)
			else {
				$('.main-navigation, .sub-navigation, .langswitch, .longbox, .facebook, .newsbox').fadeIn(500)	
			}
		},500)
	},
	productflip: function(s){
		window.clearTimeout(t)
		window.clearTimeout(n)
		if(!s){
			if($('.productlist li').length>1) {
				if($('.productlist li:visible').next('li').html()!=null){
					$('.productlist li:visible').next('li').fadeIn(1200).prev('li').fadeOut(1200,function(){
						$('.awards li:visible').fadeOut(100,function(){$(this).next('li').fadeIn(100)})
					})
				}
				else {
					$('.productlist li:first').fadeIn(1200,function(){
						$('.awards li:visible').hide()
						$('.awards li:first').fadeIn(100)
					})
					$('.productlist li:last').fadeOut(1200)
				}
	
				n=setTimeout(function(){
					ip44.productflip()
				},	3000)
			}
		}
	},	
	productfade: function() {
		$('.wrapper .productlist').parents('.wrapper').hover(function(){
			if($('.productlist li').length>1) $(this).children('.productprev').fadeIn(100)
			if($('.productlist li').length>1) $(this).children('.productnext').fadeIn(100)
		},function(){
			$(this).children('.productprev').stop().fadeOut(100)
			$(this).children('.productnext').stop().fadeOut(100)
		})
	},
	productclick:function(){
		$('.awards li').hide().eq(0).show()
		$('.wrapper .productnext').click(function(){
			window.clearTimeout(t)
			window.clearTimeout(n)	
			if($('.productlist li:visible').next('li').html()!=null){
				$('.productlist li:visible').next('li').fadeIn(1200).prev('li').fadeOut(1200,function(){
					$('.awards li:visible').fadeOut(100,function(){$(this).next('li').fadeIn(100)})
				})
			}
			else {
				$('.productlist li:first').fadeIn(1200,function(){
					$('.awards li:visible').hide()
					$('.awards li:first').fadeIn(100)
				})
				$('.productlist li:last').fadeOut(1200)
			}
			ip44.productflip(stop)
		})
		$('.wrapper .productprev').click(function(){
				window.clearTimeout(t)
				if($('.productlist li:visible').prev('li').html()!=null){
					$('.productlist li:visible').fadeOut(500).prev('li').fadeIn(500,function(){
						$('.awards li:visible').fadeOut(100,function(){$(this).prev('li').fadeIn(100)})
					})
				}
				else {
					$('.productlist li:visible').fadeOut(800)
					$('.productlist li:last').fadeIn(800,function(){
						$('.awards li:visible').hide()
						$('.awards li:last').fadeIn(100)
					})
				}				
				t=setTimeout(function(){
					ip44.productflip(stop)
				},10)
		})
	},

	toggle: function() {
		var eq = document.location.href.split('#')
		$('.halfboxleft h1').append('<img class="toggle" src="/globalimages/arrow_bottom.png" alt="" />')
		$('.halfboxleft li').css({paddingBottom:'15px'})
		$('.halfboxleft li[id!='+eq[1]+']').children('h1').next().hide().next().hide()
		$('.halfboxright h1').append('<img class="toggle" src="/globalimages/arrow_bottom.png" alt="" />')
		$('.halfboxright li').css({paddingBottom:'15px'})
		$('.halfboxright li[id!='+eq[1]+']').children('h1').next().hide().next().hide()
		$('.halfboxleft h1').toggle(function(){
			$(this).next().slideDown(80,function(){
				$(this).next().slideDown(80)
				$(this).parents('li').css({paddingBottom:'22px'})
			})
			$(this).children('.toggle').attr({src:'/globalimages/arrow_top.png'})
		},function(){
			$(this).next().slideUp(80,function(){
				$(this).next().slideUp(80)
				$(this).parents('li').css({paddingBottom:'15px'})
			})
			$(this).children('.toggle').attr({src:'/globalimages/arrow_bottom.png'})
		})	
		$('.halfboxright h1').toggle(function(){
			$(this).next().slideDown(80,function(){
				$(this).next().slideDown(80)
				$(this).parents('li').css({paddingBottom:'22px'})
			})
			$(this).children('.toggle').attr({src:'/globalimages/arrow_top.png'})
		},function(){
			$(this).next().slideUp(80,function(){
				$(this).next().slideUp(80)
				$(this).parents('li').css({paddingBottom:'15px'})
			})
			$(this).children('.toggle').attr({src:'/globalimages/arrow_bottom.png'})
		})
	},
	blocktoggle: function() {
		$('.halfblockboxleft').siblings('.halfboxleft').hide()
		$('.halfblockboxright').siblings('.halfboxright').hide()
		$('.halfblockboxleft p').append('<img class="toggle" src="/globalimages/arrow_blockbottom_b.png" alt="" />')
		$('.halfblockboxright p').append('<img class="toggle" src="/globalimages/arrow_blockbottom_b.png" alt="" />')
		$('.halfblockboxleft .toggle').hover(function(){
			$(this).attr({src:'/globalimages/arrow_blockbottom_y.png'})
			$(this).parents('p').prev('h1').css({color:'#FF9900'})		
		},function(){	
			if($('.halfblockboxleft').siblings('.halfboxleft:visible').html()!=null) {} else {
				$(this).attr({src:'/globalimages/arrow_blockbottom_b.png'})	
				$(this).parents('p').prev('h1').css({color:'#182838'})
			}
		})
		$('.halfblockboxright .toggle').hover(function(){
			$(this).attr({src:'/globalimages/arrow_blockbottom_y.png'})
			$(this).parents('p').prev('h1').css({color:'#FF9900'})			
		},function(){	
			if($('.halfblockboxright').siblings('.halfboxright:visible').html()!=null) {} else {
				$(this).attr({src:'/globalimages/arrow_blockbottom_b.png'})	
				$(this).parents('p').prev('h1').css({color:'#182838'})	
			}			
		})
		
		
		$('.halfblockboxleft .toggle').toggle(function(){
			$('.halfblockboxleft').siblings('.halfboxleft').slideDown(100)
			$(this).attr({src:'/globalimages/arrow_blockbottom_y.png'})
			$(this).parents('p').prev('h1').css({color:'#FF9900'})
			$('.halfblockboxleft').css({marginBottom:0})
		},function(){
			$('.halfblockboxleft').siblings('.halfboxleft').slideUp(100)	
			$(this).attr({src:'/globalimages/arrow_blockbottom_b.png'})	
			$(this).parents('p').prev('h1').css({color:'#182838'})
			$('.halfblockboxleft').css({marginBottom:$('.halfboxleft').height()})		
		})
		$('.halfblockboxright .toggle').toggle(function(){
			$('.halfblockboxright').siblings('.halfboxright').slideDown(100)
			$(this).attr({src:'/globalimages/arrow_blockbottom_y.png'})
			$(this).parents('p').prev('h1').css({color:'#FF9900'})
			$('.halfblockboxright').css({marginBottom:0})
		},function(){
			$('.halfblockboxright').siblings('.halfboxright').slideUp(100)	
			$(this).attr({src:'/globalimages/arrow_blockbottom_b.png'})	
			$(this).parents('p').prev('h1').css({color:'#182838'})	
			$('.halfblockboxright').css({marginBottom:$('.halfboxright').height()})
		})
	},
	expandCard: function(){
		$('.blank .expanded').hide()
		
		$('#arrow').children('area').hover(function(){
			$(this).parents('map').prev('.expand').attr({src:'/images/kostenvergleich_lnk_h'+lang+'.png'})
		},function(){
			$(this).parents('map').prev('.expand').attr({src:'/images/kostenvergleich_lnk'+lang+'.png'})
		})
		
		$('#arrow').children('area').click(function(){
			$('.expand').hide()
			$('.expanded').show()
			return false;
		})
		$('#headline').children('area').click(function(){
			$('.expanded').hide()
			$('.expand').show()
			return false;
		})
	},
	callMap:function(){
		$('.wrapper map area').eq(0).hover(function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(0).show()
		},function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(2).show()
		})
		$('.wrapper map area').eq(2).hover(function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(1).show()
		},function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(2).show()
		})
		$('.wrapper map area').eq(1).hover(function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(0).show()
		},function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(2).show()
		})
		$('.wrapper map area').eq(3).hover(function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(1).show()
		},function(){
			$('.wrapper ul.productlist_hover  li').hide()
			$('.wrapper ul.productlist_hover  li').eq(2).show()
		})
	},
	callMapWavePipe: function(){
		$('map#wavepipe area').click(function(){
			$('.halfblockboxright').siblings('.halfboxright').slideDown(100)
			$('.halfblockboxright img').attr({src:'/globalimages/arrow_blockbottom_y.png'})
			$('.halfblockboxright h1').css({color:'#FF9900'})
			$('.halfblockboxright').css({marginBottom:0})
			$('.halfboxright p').hide()
			var blockid = $(this).attr('href').split('#')
			$('.halfboxright li#'+blockid[1]+' p').show()
			$('.halfblockboxleft').siblings('.halfboxleft').slideUp(100)	
			$('.halfblockboxleft img').attr({src:'/globalimages/arrow_blockbottom_b.png'})	
			$('.halfblockboxleft h1').css({color:'#182838'})
			$('.halfblockboxleft').css({marginBottom:$('.halfboxleft').height()})		
		})
	},
	expandPress:function() {
			$('.hiddenrightbox').each(function(){
				var act=$(this).find('form').attr('action')
				var hid='#'+$(this).attr('id')
				$(this).find('form').attr({action:act+hid})
			})
			var urlid=document.location.href.split('#')
			if(urlid[1]) $('#'+urlid[1]).slideDown(300)
			
			$('.showhidden, .hiddenrightbox .submit').each(function() {
				if(pressuser>0) $(this).html($(this).html().replace(' (Login)',''))
				if($(this).attr('href')) {
					if(urlid[1]&&$(this).attr('href').indexOf(urlid[1])>-1) $(this).addClass('active')
					var id=$(this).attr('href').split('#')					
					var target=(pressuser>0&&id[2])?'#'+id[2]:'#'+id[1]
					target=(pressuser>0&&id[3])?'#'+id[3]:target
					target=(pressuser>0&&id[4])?'#'+id[4]:target
					$(this).click(function(){
						$('.hiddenrightbox').hide()
						$('.showhidden').removeClass('active')
						$(target).slideDown(300)
						$(this).addClass('active')
						return false
					})
				}
			})
			$('.piclist li a').click(function(){
				$('.presslist li a').eq(3).addClass('active')
			})
		},
	callsIFR: function() {
		var gotham = { src: '/scripts/gotham_light.swf'};
		sIFR.activate(gotham);
		/*sIFR.replace(gotham, {
		  selector: 'h1',
		  css: '.sIFR-root { background-color: transparent; color: #ff9900; margin:10px 0; font-weight:normal; font-size: 56px; leading:-15; }',
		  wmode: 'transparent'
		});
		sIFR.replace(gotham, {
		  selector: 'h2',
		  css: '.sIFR-root { background-color: transparent; color: #000033; font-size: 29px; leading:-6; }',
		  wmode: 'transparent'
		});*/	
		sIFR.replace(gotham, {
		  selector: '.excerpt',
		  css: '.sIFR-root { background-color: transparent; color: #000033; font-weight: normal; font-size: 30px; letter-spacing:1.5; leading:-3; }',
		  wmode: 'transparent'
		});			
		sIFR.replace(gotham, {
		  selector: '#innercontent dl.line dt.line',
		  css: '.sIFR-root { background-color: transparent; color: #000033; font-size:30px;}' ,
		  wmode: 'transparent'
		});		
		sIFR.replace(gotham, {
		  selector: '#innercontent dt',
		  css: '.sIFR-root { background-color: transparent; color: #ff9900; font-size:30px; leading:-3px;}' ,
		  wmode: 'transparent'
		});		
	},
	callFlash: function() {
			$('div.flashreplace').flash(
		        { 
		          src: '/images/ip44_ivylight_start_flash.swf',
		          width: 944,
				  height: 249,
		          wmode: 'transparent'
		        },
		        { version: 7 }
		    );

	},
	ghostset: function() {		
		var country = $('#country').val()
		if(country > 3) $('#plz,#ort,.footnote').hide().prev().hide()
		else $('#plz,#ort,.footnote').show().prev().show()		
		$('#country').change(function(){
			country = $(this).val()
			console.log(country)
			if(country > 3) $('#plz,#ort,.footnote').hide().prev().hide()
			else $('#plz,#ort,.footnote').show().prev().show()
		})
		
	}
}
ip44.init()

