

jQuery(document).ready(function() {

/*
	jQuery(".li_main").hover(function() {
		jQuery(this).children('ul').addClass('active');
		jQuery(this).children('a').addClass('active');
	}, function() {
		jQuery(this).children('ul').removeClass('active');
		jQuery(this).children('a').removeClass('active');
	});

	jQuery(".submitDiv .submit").hover(function() {
		jQuery(this).addClass('active');
	}, function() {
		jQuery(this).removeClass('active');
	});
*/


	function formatText(index, panel) {
	  return index + "";
	}


	jQuery(function () {
	
		jQuery('.anythingSlider_typ1, .anythingSlider_typ2').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 500,             // How long the slide transition takes
			hashTags: false,                // Should links change the hashtag in the URL?
			buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,            // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             	// Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});


		
		// zweite Navigation hinzufuegen
		/*
		var copynav = jQuery(".anythingSlider").find('.thumbNav').html();
		jQuery(".secondNav").html("<div class='thumbNav thumbNav_2'>"+copynav+"</div>");
		

		var i=1;
		jQuery('.anythingSlider .thumbNav_2 a').each(function() {
			jQuery(this).addClass("link_" + i);
			i++;
		});


		jQuery(".anythingSlider .thumbNav_2 a.link_1").click(function(e) {
			jQuery(".anythingSlider").anythingSlider(1);
			e.preventDefault();
		});
		jQuery(".anythingSlider .thumbNav_2 a.link_2").click(function(e) {
			jQuery(".anythingSlider").anythingSlider(2);
			e.preventDefault();
		});
		jQuery(".anythingSlider .thumbNav_2 a.link_3").click(function(e) {
			jQuery(".anythingSlider").anythingSlider(3);
			e.preventDefault();
		});
		jQuery(".anythingSlider .thumbNav_2 a.link_4").click(function(e) {
			jQuery(".anythingSlider").anythingSlider(4);
			e.preventDefault();
		});
		*/
	});
	

	jQuery('.anythingSlider .forward').html('');
	jQuery('.anythingSlider .back').html('');




	/*carousels - breite fuer ul setzen*/
	jQuery('.anythingSlider ul').each(function() {
		var li_count 	= jQuery(this).find('li').length;
		var li_width 	= parseInt( jQuery(this).find('li').width() );

		var ul_sum		= li_count*li_width;
		jQuery(this).css('width', ul_sum);
	});



	
	/* prev-link im carouselpager flexibel machen */
	/* gezählt wird die pager-link-anzahl, nicht die li's, wegen der cloned li's */
	jQuery('.workspace .anythingSlider').each(function() {
		var pL_count 	= jQuery(this).find('.thumbNav a').length;
		var pL_width 	= parseInt( jQuery(this).find('.thumbNav a').css('width') );
		var pL_margin	= parseInt( jQuery(this).find('.thumbNav a').css('margin-right') );
		var thNav_right	= parseInt( jQuery(this).find('.thumbNav').css('right') );

		var pl_sum		= pL_count*(pL_width+pL_margin)+thNav_right+pL_margin;
		jQuery(this).find('.back').css('right', (pl_sum+'px'));
	});
	


	jQuery('.login #password').click(function() {
		jQuery('.login .pwBox').html('<input type="password" id="password" class="text" >');
		jQuery('.login #password').focus();
	});


	



	// checkbox textfarbe wenn aktiv
	jQuery(".checklist .checkbox").each (
		function() {
			attr = jQuery(this).attr('checked');
			if(attr==true) jQuery(this).parent().addClass('orange');
		}
	)

	
	jQuery('.reset, .resetButton').click(function() {
		jQuery("ul.checklist").find('li').removeClass('orange');
		jQuery('ul.checklist input:checkbox').removeAttr('checked');
	});


	jQuery('.checklist .checkbox').click(function() {
		attr = jQuery(this).attr('checked');
		if(attr==true) jQuery(this).parent().addClass('orange');
		else jQuery(this).parent().removeClass('orange');
	});


	jQuery('.checklist .first .checkbox').click(function() {
		attr = jQuery(this).attr('checked');
		if(attr==true) {
			jQuery(this).parent().parent().find('li').addClass('orange');
			jQuery(this).parent().parent().find('li .checkbox').attr('checked',true);
		}
		else { 
			jQuery(this).parent().parent().find('li').removeClass('orange');
			jQuery(this).parent().parent().find('li .checkbox').attr('checked',false);
		}
	});


	
	jQuery('.menuTyp2 li').hover(
	  function () {
		jQuery(this).children().next().css("left","0px");
		jQuery(this).addClass("activeHover");
	  }, 
	  function () {
		jQuery(this).children().next().css("left","255px");
		jQuery(this).removeClass("activeHover");
	  }
	);


	thisDate = new Date().getFullYear();
	rangeMax = thisDate;
	rangeMin = rangeMax-80;
	jQuery(".datepicker").datepicker({
		dateFormat: 'dd.mm.yy',
		changeYear: true,
		yearRange: '' + rangeMin + ':' + rangeMax + ''
	});
	
	//jQuery( ".selector" ).datepicker({ changeYear: true })



	
	//Quote
	jQuery('.postQuote').click(function() {
		parentObj 	= jQuery(this).parent().parent().parent();
		postUser	= jQuery(parentObj).find('.postUser').html();
		postDate	= jQuery(parentObj).find('.postDate').html();
		postText	= jQuery(parentObj).find('.postText').html();
		
		targetObj 	= jQuery(".textareaPostList");

		targetText	= "";
		targetText+= "> " + postUser +" wrote on " + postDate + "\n";
		targetText+= "> " + postText + "\n";

		targetText = targetText.replace(/<\/?[^>]+>/gi, '');


		jQuery(targetObj).val(targetText);
		
		
		return false;

	});




	//file upload
	jQuery(".postForm input:file").change(function() {
		jQuery(this).parent().parent().find('.disp_fileinput').html(this.value);
	})

	jQuery('.postForm .lbl_fileinput').hover(function() {
		jQuery(this).addClass('browse_button_active');
		}, function() {
		jQuery(this).removeClass('browse_button_active');
	});



	//reset
	jQuery(".reset").click(function() {
		jQuery('.disp_fileinput').html('');
	});




	bottonHref = jQuery(".imgButtonNews a").attr('href');
	//jQuery(".imgButtonNews a").attr('href',bottonHref+'#comment');
	
	
	
	// Tabs for Productdescriptions
	jQuery("#descriptionTabs").tabs({

	});
	
	
	jQuery('ul#metanavi li.print a').click(function() {
		window.print();
	});
	
	
	jQuery("#ingredientsSort").change(function() {
	
		if(jQuery("#ingredientsSort").val() != 0){
			jQuery('#ingredientsSearchForm').submit();
		}
		
	});

});



/* Bookmarks SAVE */ 

function saveBookmark(type, uid){

	//alert(type + ' - ' + uid);
    
    //jQuery('html, body').animate({scrollTop:0}, 'slow');

    jQuery.ajax({
        url: 'index.php?type=1309',
        type: "GET",
        data: 'tx_ffnatrue_pi1[type]=' + type + '&tx_ffnatrue_pi1[parentId]=' + uid,
        
        success: function(result){
        
        	//jQuery(result).each(function() {
			//	$val = jQuery("#discussion").html();
			//	alert($val);
    		//});

	
			div = jQuery("#bookmarkValues",result).html();
			jQuery("#bookmarkValues").html(div);
        	
        	
        },
        error: function(xml){
        
        	//alert('Fehler');
            
        }
        
    });
	
        
}

/* Bookmarks DELETE */ 

jQuery(document).ready(function() {

	jQuery("#bookmarks").submit(function() {
		  
	
		var discussions = []; 
		jQuery("#bookmarks input[type='checkbox'].discussions:checked").each(function(i, selected){ 
			discussions[i] = jQuery(selected).val(); 
		});
	
	
		var posts = []; 
		jQuery("#bookmarks input[type='checkbox'].posts:checked").each(function(i, selected){ 
			posts[i] = jQuery(selected).val(); 
		});
		
	
		jQuery.ajax({
			url: 'index.php?type=1310',
			type: "GET",
			data: 'tx_ffnatrue_pi1[discussions]=' + discussions + '&tx_ffnatrue_pi1[posts]=' + posts,
			
			success: function(result){
			
				//jQuery(result).each(function() {
				//	$val = jQuery("#discussion").html();
				//	alert($val);
				//});
	
				div = jQuery("#bookmarkValues",result).html();
				jQuery("#bookmarkValues").html(div);
							
			},
			error: function(xml){
			
				//alert('Fehler');
				
			}
			
		});
		  
		return false;
		  
	});

});


