/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);





/*~~~ JQuery-Scripting ~~~*/

$(function(){
	$('html').addClass('js');
	$('#footer ul a').click( function( objEvent ){ showBottomSlider(this); return false; });
	$('.gallerySlider a').click( function( objEvent ){ showGalleryDetails(this); return false; });
	$('.newsContextCol a:has(img)').click( function( objEvent ){ loadBigImage(this); return false; });
	$('input[type=text]').focus( function( objEvent ){ $(this).select(); });

	//switchBackground
	//die Backgrounds werden auf den Produktuntertseiten geschaltet und unter einer auflösung von 1024 beim Start entfernt
	if($('html').width() > 1023){
		$('.epi1Please').mouseover( function( objEvent ){ $('#bgImage1').attr('src', $('#bgImage1').attr('src')).css('display', 'block'); $('body').addClass('epi');});
		$('.epi1Please').mouseout( function( objEvent ){ $('#bgImage1').css('display', 'none'); $('body').removeClass('epi');});
		$('.epi2Please').mouseover( function( objEvent ){ $('#bgImage2').attr('src', $('#bgImage2').attr('src')).css('display', 'block'); $('body').addClass('epi');});
		$('.epi2Please').mouseout( function( objEvent ){ $('#bgImage2').css('display', 'none'); $('body').removeClass('epi');});
		$('.epi3Please').mouseover( function( objEvent ){ $('#bgImage3').attr('src', $('#bgImage3').attr('src')).css('display', 'block'); $('body').addClass('epi');});
		$('.epi3Please').mouseout( function( objEvent ){ $('#bgImage3').css('display', 'none'); $('body').removeClass('epi');});
	} else {
		$('#bgImage1').remove();
		$('#bgImage2').remove();
		$('#bgImage3').remove();
	}
	
	$('.scrollTop').click( function( objEvent ){  $('body').scrollTo( $('#topNav').position().top, 500 ); });
	
	//---------------- collapse/expand
	$('.collapse').each( function(){
		$(this).attr("box_h", $(this).height());
		$(this).css({'height': 165, 'overflow': 'hidden' });
		$(this).after('<a style="padding-left: 244px;" href="#" class="antiCollapse" target="_self">[ Alle anzeigen... ]</a>');
	});
	$('.antiCollapse').click( function( objEvent ){
		//console.debug($(this).prev());
		$(this).prev().animate({ height: $(this).prev().attr('box_h')}, 'slow');
		$(this).remove();
		return false;
	});
	// end expand-----------------
	
	var resize = function(){
		//var footerHeight = ;
		$('#footer').css('min-height', $('body').height() - $('#bodyWrap').height() - parseInt($('#bodyWrap').css('padding-bottom')));
	};
	$(window).resize(resize);
	resize();
});

function showBottomSlider(which){
	if(!($(which).parent().hasClass('active'))){
		if(!$('#bottomSliderClose').attr('id')){
			$('#footer>ul:first-child').append('<li id="bottomSliderClose"><a href="#"><strong>[x]</strong> Schlie&szlig;en</a></li>');
			$('#bottomSliderClose').click( function( objEvent ){
				$('body').scrollTo( $('#topNav').position().top, 500 );
				$('#footer .bottomSlider').animate({ height: 'hide'}, 'slow');
				$('#bottomSliderClose').remove(); 
				$('#footer ul li').removeClass('active');
				return false; 
			});
			//$('html').animate({scrollTop : $('#bottomSliderClose').position().top - 150},'slow');
			setTimeout(function(){$('body').scrollTo( $('#footer').position().top - 150, 500 )}, 500);
			//console.debug( $('#bottomSliderClose').position().top);
		}
		$('#footer ul li').removeClass('active');
		$(which).parent().addClass('active');
		var targetId = $(which).attr('href');
		$('#footer .bottomSlider').animate({ height: 'hide'}, 'slow');
		$(targetId).animate({ height: 'show'}, 'slow');
	}
	//console.debug($(which).parent().hasClass('active'));
}

function showGalleryDetails(el){
	var wasAlreadyActive = false;
	
	//alle active classes entfernen, den aktuellen hinzufügen wenn nicht klick auf bereits aktiven
	if(!$(el).hasClass('active') && !$(el).hasClass('closeLink')) { 
		$('.gallerySlider .floatBlocks>a').removeClass('active');
		$('body').addClass('galleryDetailsOpen');
		$(el).addClass('active') 
	} else {
		$('body').removeClass('galleryDetailsOpen');
		$('.gallerySlider .floatBlocks>a').removeClass('active');
		wasAlreadyActive = true;
	};
	
	
	function getAndDisplayData(){
		if(!wasAlreadyActive) {
			//nur öffnen, wenn der klick nicht erneut auf das aktive element ging
			$.get('/javascript/getGalleryData.php',
				{'gallery': $(el).attr('href')},
				function(data) {
					//daten holen, laden
					$('#galleryDetail').html(data);
					//Links binden - auf CloseLink
					$('#galleryDetail a.closeLink').click( function( objEvent ){ showGalleryDetails(this); return false; });
					// - auf Thumbs
					$("#galleryDetail div.text a").colorbox({inline:true, href:"#galleryDetail div.fullText",  innerWidth:600, innerHeight:350, rel:'galleryGroup', transition:'fade', opacity: 0.7, current: "{current} von {total}"});
					$('#galleryDetail a.img').colorbox({rel:'galleryGroup', transition:'fade', opacity: 0.7, current: "{current} von {total}"});
					$('#galleryDetail a.vid').colorbox({iframe: true, innerWidth:600, innerHeight:480, rel:'galleryGroup', transition:'fade', opacity: 0.7, current: "{current} von {total}"});
					// - danach öffnen
					$('a.vid').each(function(){
						$(this).append('<img style="position: absolute; left: 0; top: 0; -moz-box-shadow: none;-webkit-box-shadow: none; box-shadow: none;" width="224" height="127" alt="Video" src="/images/chrome/galleryVideo.png">');
					});
					$('#galleryDetail').animate({height: 'show'}, 'slow');
				}
			);
		}	
	}
	
	
	if($('#galleryDetail').css('display') != 'none'){
		//schließen wenn geöffnet
		$('#galleryDetail').animate({height: 'hide'}, 'slow', function(){getAndDisplayData();});
	} else {
		getAndDisplayData();
	}
	
	
}

function loadBigImage(el){
	$('#bigNewsImage').attr('src', $(el).attr('href'));
	$('body').scrollTo( $('#wrapper'), 500 );
}

function makeNewsImageClickable(){
	$('#coda-slider-2 .col p img').each(function(){
		$(this).clone().appendTo($(this).parent().parent()).css({
			'opacity': 0,
			'z-index': 5000,
			'position': 'absolute',
			'left': 0,
			'top': 0,
			'cursor': 'pointer'
		}).click(function(event){
			document.location.href = $(this).prev().attr('href');
		});
	});
}


function poptext(URL, breite, hoehe)
{
	if (!breite){var breite=450;}
	if (!hoehe)	{var hoehe=450;}
	
	var top=(screen.availHeight-hoehe)/2;
	var left=(screen.availWidth-breite)/2;
	var args = "height="+hoehe+", width="+breite+",menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left="+left+",top="+top;
	poptextwin=window.open(URL,'poptextname',args);
	poptextwin.focus();
}     

