$(function() {
	$('#kundenlogin_expand_link').click(function(event){
		$('#kundenlogin_expand_container').slideToggle() ;
		return false ;
	}) ;
	
	$.fn.fancybox.defaults.overlayOpacity = 0.4 ;
	//$.fn.fancybox.defaults.overlayColor = '#ccc' ;
	//$.fn.fancybox.defaults.padding = 0 ;
	
	// Urlaubshinweis
	//if(location.search.indexOf('test') != -1) {
		var urlaub = $('#urlaubshinweis') ;
		var cook = jQuery.cookie('urlaubshinweis') ? parseInt(jQuery.cookie('urlaubshinweis')) : 0 ;
		if (urlaub.length > 0) {
			cook++ ;
			if (cook == 2) {
				$.fancybox(urlaub.html()) ;
			}
			jQuery.cookie('urlaubshinweis', cook, {path:'/'}) ;
		}
		else if (cook) {
			jQuery.cookie('urlaubshinweis', 0, {path:'/'}) ;
		}
	//}
	
	// Galerie auf Detailseite
	$('*[rel^="lightbox"]').fancybox({hideOnContentClick:true,padding:10}) ;
	$('*[rel^="lightbox_detail"]').click(function(){
		var firstGalPic = $('*[rel^="lightbox_gallery"]:first') ;
		//if (firstGalPic.length > 0 && this.href.replace(/^.*\/([^\/]+)$/, '$1') == firstGalPic.get(0).href.replace(/^.*\/([^\/]+)$/, '$1')) {
		if (firstGalPic.length > 0 && this.href == firstGalPic.get(0).href) {
			firstGalPic.click() ;
			return false ;
		}
	}) ;
	
	// Alternativ-Artikel
	$('a[href*="alt_articles="]').attr('onclick', '').fancybox({
		type:'iframe',
		width:655,
		height:425		
	}) ;
	
	// Futtterkonfigurator
	$('a[href*="futterkonfigurator"]').attr('onclick', '').fancybox({
		type:'iframe',
		width:855,
		height:835,
		margin:0
	}) ;
	
	// Last seen
	if ($.fn.carouFredSel) {
		$('.lastseen').each(function(){
			if ($('.lastseen-items > *', this).length > 3) {
				$('.lastseen-items', this).carouFredSel({
					direction: 'up',
					items: 3,
					scroll: 1,
					circular: false,
					infinite: false,
					auto: false,
					prev: $('.lastseen-up', this),
					next: $('.lastseen-down', this)	
				}) ;
			}
			else {
				$('.lastseen-up, .lastseen-down', this).hide() ;
			}
		}) ;
	}
	
	//// Detailseite
	
	// Tabs
	$('.tabcontainer').each(function(){
		var container = $(this) ;
		$('.tabinfo_content', container).each(function(num){
			if (num > 0) {
				$(this).hide() ;
			}
			var tab_id = this.id ;
			$('a[href*="#'+tab_id+'"]').click(function(event){
				event.preventDefault() ;
				if ($(this).closest(container).length < 1) {
					$('li:has(a[href*="#'+tab_id+'"])', container).click() ;
					$.fancybox.close() ;
					window.scrollTo(0, container.offset().top) ;
				}
			}) ;
		}) ;
		$('.tabmenu li', container).click(function(event){
			event.preventDefault() ;
			var li = $(this) ;
			$('.tabinfo_content', container).hide() ;
			$('.tabmenu li', container).removeClass('active') ;
			$($('a', this).attr('href')).show() ;
			li.addClass('active') ;
		}) ;
	}) ;
	// Tab-Teaser-Trenner
	$('.tabinfo_content .trenner').each(function(){
		var divider = $(this) ;
		
		Array.prototype.reverse.call(divider.prevAll()).wrapAll('<div class="tabteaser" />') ;
		divider.prev('.tabteaser').append(
			$('<a href="#" class="more">weiterlesen &raquo;</a>').click(function(){
				var elem = $(this) ;
				elem.parent().next('.tabcontent').slideDown() ;
				elem.remove() ;
				return false ;
			})
		) ;
		divider.nextAll().wrapAll('<div class="tabcontent" />') ;
		divider.next('.tabcontent').hide() ;
		divider.remove() ;
	}) ;
	
	// lightbox_recommend
	$('a[href*=lightbox_recommend]').fancybox({padding:0}) ;
	
	// link_staffelpreise
	$('a.link_staffelpreise').bind('mouseenter mouseleave', function(){
		$(this).next('.staffelpreise').fadeToggle('fast') ;
		return false ;
	}).click(function(){return false;}) ;
	
	// Slider Startseite
	if ($.fn.carouFredSel) {
		$('.slider').carouFredSel({
			scroll: {
				fx: 'crossfade',
				pauseOnHover: 'resume',
				duration: sliderSettings.fade * 1000
			},
			auto: {
				pauseDuration: sliderSettings.pause * 1000
			},
			pagination: {
				container: '.slider_pagination',
				anchorBuilder: function(nr, item){
					return '<a href="#'+nr+'"><img src="/shop/images/leer.gif" border="0" alt="" width="9" height="9" /><span>'+nr+'</span></a>' ;
				}
			}
		}) ;
	}
}) ;

function wopen(link,wi,he) {

	var width=wi; var height=he;
	var l=(screen.availWidth-width)/2;
	var t=(screen.availHeight-height)/2;
    wincom=window.open(link ,"oswin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+wi+",height="+he+",screenX="+l+",screenY="+t+",left="+l+",top="+t);

    if (wincom) {
    	wincom.focus() ;
	} else {
		alert(statustext) ;
	}
}


function dellink(link,btext) {

	Check = confirm(btext);

	if(Check == false) {
		return ;
	} else {
		window.open(link,'_self') ;
	}
}


function changebutton(s) {

    window.Bestellung.obutton.value = "Bitte warten ... und diesen Button nur 1x klicken !!!!";

    if (SEND==1) {

    	alert("Sie haben die Bestellung bereits abgeschickt, bitte warten Sie auf Antwort des Shop-Servers !") ;
    	return false ;

    } else {

    	SEND=1 ;
    	return true ;
    }
}


function fielddel(f) {

	if (f.value == f.defaultValue) {

		f.value = "" ;
	}
}


function fieldset(f) {

	if (f.value == "") {

		f.value = f.defaultValue ;
	}
}


function fieldemp(f) {

	if (f.sbeg.value == f.sbeg.defaultValue) {

		f.sbeg.value = "" ;
	}
}


function tabbgcolor(hrefid,col2){

	hrefid.className='navi_top_active';
}

