// Conflict Mode on, means, the Class can be called bei 'jQuery' instead of $

jQuery(document).ready(function(){

	// default 'dedication' disabled, only enabled when click on not zero euro card
	jQuery('#bundle-option-43-132').attr('disabled', 'disabled');
	jQuery('#product_input_list_132 span').css({'color' : '#999'});
	jQuery('#options-list-43 li *').css({'color':'#999'});

	// function for making telephone not empty
	jQuery.makeTelefonNotEmpty = function(target,teltext){
		if(jQuery(target).val() == '')
			//alert('wasuuuupp');
			jQuery(target).val(teltext);
		jQuery(target).click(function(){
			if(jQuery(target).val() == teltext)
				jQuery(target).val('');
		});
		jQuery(target).blur(function(){
			if(jQuery(target).val() == '')
				jQuery(target).val(teltext);
		});
	}

	// function winfo hide on start
	jQuery.winfoHide = function(id){
		jQuery(id).css('opacity',0.0);
	}

	// function winfo fade out
	jQuery.winfoFadeOut = function(id){
		jQuery(id).fadeTo('slow',0.0);
	}

	// function winfo fade in
	jQuery.winfoFadeIn = function(id){
		jQuery(id).fadeTo('slow',1.0);
	}

	// function to disable dedication
	jQuery.disbleDedication = function(){
		jQuery('#options_24_text').val('');
		jQuery('#bundle-option-43-132').attr('checked', false);
		jQuery('.widmung_container').slideUp();
		bundle.changeSelection(document.getElementById('bundle-option-43-132'));
		jQuery('#bundle-option-43-132').attr('disabled', 'disabled');
		jQuery('#product_input_list_132 span').css({'color':'#999'});
		jQuery('#options-list-43 li *').css({'color':'#999'});
		jQuery.winfoFadeIn('#winfo-43');
	}
	// function to enable dedication
	jQuery.enableDedication = function(){
		jQuery('#bundle-option-43-132').removeAttr('disabled');
		jQuery('#product_input_list_132 span').css({'color':null});
		jQuery('#options-list-43 li *').css({'color':'#0C395F'});
		jQuery('.bundle-option-43-132 .price-notice').css({'color':'#999999'});
		jQuery('.bundle-option-43-132 .price-notice .price').css({'color':'#2F2F2F'});
		jQuery.winfoFadeOut('#winfo-43');
	}

	// function to check textarea for allowed string length

	jQuery.CheckLen = function(target,max){
		if (target.value.length > max){
			target.value = target.value.substring(0,max);
		}
		jQuery('p.no-margin strong').html(max-target.value.length);
	}

	jQuery.winfoHide('#winfo-43');

	// make everything on dedication to the beginnng when click on zero price card
	// zero
	jQuery('#bundle-option-51-164').click(function(){jQuery.disbleDedication();});
	jQuery('#bundle-option-51-163').click(function(){jQuery.disbleDedication();});
	jQuery('#bundle-option-51-162').click(function(){jQuery.disbleDedication();});
	jQuery('#bundle-option-51-161').click(function(){jQuery.disbleDedication();});

	// enable checkbox when click on not zero price card
	// not zero checkbox
	jQuery('#bundle-option-51-170').click(function(){jQuery.enableDedication();});
	jQuery('#bundle-option-51-169').click(function(){jQuery.enableDedication();});
	jQuery('#bundle-option-51-168').click(function(){jQuery.enableDedication();});
	jQuery('#bundle-option-51-167').click(function(){jQuery.enableDedication();});
	jQuery('#bundle-option-51-166').click(function(){jQuery.enableDedication();});
	jQuery('#bundle-option-51-165').click(function(){jQuery.enableDedication();});

	// option texts and 'widmung-textarea' hide and make them trigger for clicking
	jQuery('.bundle_the_desc').hide();
	jQuery('.widmung_container').hide();
	jQuery('#bundle-option-43-132').click(function(){jQuery('.widmung_container').slideToggle('slow');jQuery('#options_24_text').val('');});
	jQuery('h2.mehr').click(function(){
		jQuery(this).next('.bundle_the_desc').slideToggle('slow');
	});
	
	// textarea onKeyUp check for 200 chars
	jQuery('#options_24_text').keyup(function(){jQuery.CheckLen(document.getElementById('options_24_text'),200);});

	// start the Cart summary follow scroller
	jQuery('#sidebar').scrollFollow({
		speed:1000,
		offset:0,
		killSwitch:'exampleLink',
		onText:'Disable Follow',
		offText:'Enable Follow'
	});

	// addtocart-button validation: red css border on #options-list-51
	jQuery('#addtocart-button').click(function(){
	    if (jQuery('#options-list-51').hasClass('validation-failed')){
	          jQuery('#options-list-container-51').addClass('validation-failed');
	    }else if(jQuery('#options-list-51').hasClass('validation-passed')){
	          jQuery('#options-list-container-51').removeClass('validation-failed');
	    }else{
	    	// do nothing
	    }
	});
	
	
	// Gutscheinkarte/PDF-Karte
	
	if (jQuery.browser.msie) {
       
	   jQuery('#pdf-gutschein').click(function(){
		jQuery.winfoFadeOut('.cards');
		jQuery('#options-list-container-51').animate({
			height: '285px'
		  }, 550, function() {
			// Animation complete.
			jQuery('.cards').css({'display':'none'});
			jQuery('.cards_338').css({'display':'block'});
			jQuery('#bundle-option-51-338').attr('checked', true);
			jQuery.disbleDedication();
			jQuery.winfoFadeIn('.cards_338');
		});
	});
	
	jQuery('#gutscheinkarte').click(function(){
		jQuery.winfoFadeOut('.cards');
		jQuery('#options-list-container-51').animate({
			height: '430px'
		  }, 550, function() {
			// Animation complete.
			jQuery('.cards').css({'display':'block'});
			jQuery.winfoFadeIn('.cards');
			jQuery('.cards_338').css({'display':'none'});
			jQuery('#bundle-option-51-164').attr('checked', true);
		});
	});
	   
    } else {
		
		jQuery('#pdf-gutschein').change(function(){
		jQuery.winfoFadeOut('.cards');
		jQuery('#options-list-container-51').animate({
			height: '285px'
		  }, 550, function() {
			// Animation complete.
			jQuery('.cards').css({'display':'none'});
			jQuery('.cards_338').css({'display':'block'});
			jQuery('#bundle-option-51-338').attr('checked', true);
			jQuery.disbleDedication();
			jQuery.winfoFadeIn('.cards_338');
		});
	});
	
	jQuery('#gutscheinkarte').change(function(){
		jQuery.winfoFadeOut('.cards');
		jQuery('#options-list-container-51').animate({
			height: '430px'
		  }, 550, function() {
			// Animation complete.
			jQuery('.cards').css({'display':'block'});
			jQuery.winfoFadeIn('.cards');
			jQuery('.cards_338').css({'display':'none'});
			jQuery('#bundle-option-51-164').attr('checked', true);
		});
	});		
	
	}
	
	
	
	
	
	
	// select the thumbnails and make them trigger our overlay all a.single_image in #options-list-51
	if(document.getElementById('options-list-51')){
		jQuery('#options-list-51 a.single_image').overlay({
			target: '#gallery',
			expose: {
					color: '#133E65',
					opacity: 0.3
					},
            closeOnClick: true
		}).gallery({
			opacity: 1.0,
			speed: 800
		});
	}
	
	// select the thumbnails and make them trigger our overlay all a.single_image in #options-list-51
	if(document.getElementById('options-list-51')){
		jQuery('#options-list-51 a.single_image2').overlay({
			target: '#gallery',
			expose: {
					color: '#133E65',
					opacity: 0.3
					},
            closeOnClick: true
		}).gallery({
			opacity: 1.0,
			speed: 800
		});
	}

	
	teltext = 'Rückrufnummer';
	if(document.getElementById('shipping:telephone')){jQuery.makeTelefonNotEmpty('[title^="Telefon"]',teltext);}
	if(document.getElementById('billing:telephone')){jQuery.makeTelefonNotEmpty('[title^="Telefon"]',teltext);}
	if(document.getElementById('telephone')){jQuery.makeTelefonNotEmpty('[title^="Telefon"]',teltext);}
	
	jQuery("label[for='billing:telephone'] span").css('display','none');
	jQuery("label[for='shipping:telephone'] span").css('display','none');
								
 
<!---- Rückrufnummer ---->
		
	/*var $inputfield = jQuery('*[title^="Telefon"]');
	
	$inputfield.val() = "Rückrufnummer";
	inputvalue = $inputfield.val();
	
	$inputfield.focus(function(){
		alert('wasuuuupp');
	if (jQuery(this).val() === inputvalue) jQuery(this).val("");
		}).blur(function(){
			if (jQuery(this).val() === "") jQuery(this).val(inputvalue);
		});*/
});
// get all images in the header fade div
	function getAllSlideImages(wrapper,tag){
		var slide_elements = document.getElementById(wrapper).getElementsByTagName(tag);
		var slide_src = new Array();
		for (var i = 0; i < slide_elements.length; i++) {
			slide_src[i] = slide_elements[i].src;
		}
		return slide_src;
	}

	// header image fader : preload and fade in
	jQuery(function( jQuery ){
		jQuery('.slide').css('opacity', 0.0);
		var urls = getAllSlideImages('header-images','img');
		jQuery.preload( urls, {
			base:'',
			ext:'',
			onFinish:function(){
				jQuery('.slide').fadeTo('slow', 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
			}
		});
	});

