jQuery(document).ready(function(){
	//wk
	if(jQuery('div.block-cart a#wk_toggle').length>0){
		//init slider
		jQuery('#cart-sidebar').jcarousel({
	        scroll: 3
	    });
		
		
		//init toggle button
		var toggle=jQuery('div.block-cart a#wk_toggle');
		var list=jQuery('div.block-cart div.cart-items');
		var cartIsIn=true;
		toggle.click(function(){
			if(cartIsIn){
				list.animate({top:"0px"},function(){cartIsIn=false;});
				toggle.css("background-position","0px 0px");
			}else{
				list.animate({top:"-181px"},function(){cartIsIn=true;});
				toggle.css("background-position","0px -20px");
			}
			return false;
		});
	}
	
	//youtube winzer detail
	if(jQuery('.winzer_details div.youtube_block').length>0){
		jQuery('a.youtube_link').click(function(){
			jQuery('div.youtube_player').slideToggle();
			jQuery('a.youtube_link').toggleClass("open");
			return false;
		});
	}
	//youtube wine detail
	if(jQuery('.product-view div.youtube_block').length>0){
		jQuery('a.youtube_link').click(function(){
			jQuery('div.youtube_player').slideToggle();
			jQuery('a.youtube_link').toggleClass("open");
			return false;
		});
	}
	//Product more images
	if(jQuery('.product-view .more-views').length>0){
		jQuery(".product-view .more-views ul li a").fancybox({
			'hideOnContentClick': true
		});
	}
	//gallery winzer detail
	if(jQuery('.winzer_details div.gallery_block').length>0){
		/*jQuery('a.gallery_link').click(function(){
			jQuery('div.gallery_list').slideToggle();
			jQuery('a.gallery_link').toggleClass("open");
			return false;
		});*/
		
		jQuery("a[rel=test]").fancybox({
			'hideOnContentClick': true
		});
	}
	//winzer more link
	if(jQuery('.winzer_details').length>0){

		jQuery('.winzer_details .winzer_more').css("display","inline");
		jQuery('.winzer_details .additional-description').css("display","none");
		jQuery('.winzer_details .youtube_block').css("display","none");
		jQuery('.winzer_details .gallery_block').css("display","none");
		
		jQuery('.winzer_details .winzer_more').click(function(){
			jQuery('.winzer_details .winzer_more').css("display","none");
			jQuery('.winzer_details .shortDescr').css("display","none");
			jQuery('.winzer_details .additional-description').fadeIn("slow");
			jQuery('.winzer_details .youtube_block').fadeIn("slow");
			jQuery('.winzer_details .gallery_block').fadeIn("slow");
		});
	}
	//category more link
	if(jQuery('.category_details').length>0){

		jQuery('.category_details .category_more').css("display","inline");
		jQuery('.category_details .additional-description').css("display","none");
		
		jQuery('.category_details .category_more').click(function(){
			jQuery('.category_details .category_more').css("display","none");
			jQuery('.category_details .shortDescr').css("display","none");
			jQuery('.category_details .additional-description').fadeIn("slow");
		});
	}
	
	//CHECKOUT
	//pre select land/bundesland and hide it
	/*if(jQuery('.checkout-onepage-index #opc-billing select#billing\\:region_id').length>0){
		jQuery('.checkout-onepage-index #opc-billing select#billing\\:region_id').val(320);
		jQuery('.checkout-onepage-index #opc-billing select#billing\\:region_id').parents("div.field:first").css("display","none");
	}
	if(jQuery('.checkout-onepage-index #opc-shipping select#shipping\\:region_id').length>0){
		jQuery('.checkout-onepage-index #opc-shipping select#shipping\\:region_id').val(320);
		jQuery('.checkout-onepage-index #opc-shipping select#shipping\\:region_id').parents("div.field:first").css("display","none");
	}*/
	
	if(jQuery('.subscription_note').length>0){
		jQuery('.subscription_note').click(function(){
			var bubble=jQuery(this).parents(".item").find('.subscriptionBubble');
			
			bubble.css({top:"20px",
						opacity:"0",
						display:"block",
						left:"40px"});
			
			bubble.stop().animate({opacity:"1",top:"5px"},300);
		})
		
		jQuery('.subscriptionBubble').click(function(e){
			jQuery(this).stop().animate({opacity:"0",display:"none",top:parseInt(jQuery(this).css("top"))-30},300);
			e.stopPropagation();
		});
	}
	
	if(jQuery('#initial_password_form').length>0){
		var p=gup("m");
		var field=jQuery("#initial_password_form #email_address");
		if(p){
			field.attr("value",p);
		}
	}
	
	if(jQuery('a.list-detail-more').length>0){
		jQuery('a.list-detail-more').click(function(){
			jQuery(this).parent().css("display","none");
			jQuery(this).parents('.shortdescr').find('span.remain').fadeIn("slow");
			return false;
		});
	}
	
	jQuery('.wib').click(function(){
		jQuery.fancybox.showActivity();
		var tmp=jQuery('<div/>').load(jQuery(this).attr("href")+" #col3_content",function(one,two,three){
			if(two=="success"){
				var headline=tmp.find("div.category-title");
				var content=tmp.find("div.winzer_details");
				content.find('p.shortDescr').remove();
				content.find('a.winzer_more').remove();
				content.find('p.image').css({float:"left",margin:"0 10px 10px 0"});
				tmp=headline.html()+content.html();
				jQuery.fancybox({
					content: tmp,
					width:600,
					height:400,
					autoDimensions:false,
					onComplete:function(){
						jQuery('#fancybox-content .gallery_list a').attr("rel","test").fancybox();	
					}
				});
			}
		});
		return false;
	});	
	
});

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

