jQuery.preloadImages = function() {
		for(var i = 0; i < arguments.length; i++) {
			jQuery("<img>").attr("src", arguments[i]);
		}
}

jQuery( function($)  {

	
	
	$("#loginBox").tabs({
		cookie: { expires : 1 }
	});
	
	$("#tabs").tabs({ 
		cookie: { expires : 30 }
	});
	
	$(".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *") 
	 		.removeClass("ui-corner-all ui-corner-top") 
	  		.addClass("ui-corner-bottom");
				
			
	/* Prepare and init slideshow */
				
	window.setTimeout("initSlideshow()", 1000);
	
	/* Drop-down navigation */
	
	 $("#primaryNav li ul").hide();
	 
	 $("#primaryNav li a").hover( function() {	 
		 $(this).parent().find("ul").show();		 
		 $(this).parent().hover( function() {}, function() {
			 $(this).parent().find("ul").hide();
		 });	 
	 }); 
	 
	 $("#frontpageNav li ul").hide();
	 
	 $("#frontpageNav li a").hover( function() {	 
		 $(this).parent().find("ul").show();		 
		 $(this).parent().hover( function() {}, function() {
			 $(this).parent().find("ul").hide();
		 });	 
	 }); 
	 
	 $("#frontpageNav li").hover (	function(){
		 								$(this).children("a").addClass('active');
		 								$(this).find("a:first");
		 							}, 
		 							function(){
		 								$(this).children("a").removeClass('active');
		 								
		 							});
	
	/* Odd-even table rows */
	 
	 $("#content tbody tr:odd").addClass('odd');
	 
	 
	/* Full height for secondaryNav */
	
	$("#sidebarLeftContent .teaserBox").height($("#contentInnerWrap").outerHeight());
	
	/* Date picker */
	
	$("input#uid83, input#uid192, input#uid454").datepicker({
		'dateFormat' : 'dd.mm.yy'
	});	
	
	 $('.mover').hide();
	 $('.deleteProduct').hide();
	 
	
	$('div.parentProduct').click( function() {
		$(this).next().toggle('slow');
		$(this).children('img.deleteProduct').toggle();
		$(this).children('img.addProduct').toggle();
	});

	
	$("#content a[href$='.pdf'], #content a[href$='.zip']").addClass('download');
	$("a[href$='.pdf']").attr('target','_blank');
	
	/* Prefill login box */
	
	var paramString = document.location.search.substr(1,document.location.search.length);
	if(paramString.match(/u\=.*/)) {
		paramString = paramString.replace(/u\=/,'');
		$("#user").val(paramString);
		$("#content #user").val(paramString);
	}
	
	/* Flash user notification on top of content */
	
	$(".userNotification").css( { opacity: 0 });
	$(".userNotification").prependTo($("#content"));
	$(".userNotification").animate(
			{ opacity: 1 }, 
			1000, function() { }
	);
	
	$("#print a").click( function() { 
		window.print();
		return false;
	});
	
	/*$("input.obtrusive").each( function() {
		$(this)
			.hide()
			.after("<a href='#' class='obtrusive'>")
			.next("a").text($(this).val())
			.click( function() { 
				$(this).prev("input.obtrusive").click(); 
				return false;
			});	
	});*/
	
	
	
	/* Freikarten-Rechner */
	
	$("#freikartenrechner").html('<fieldset><div><label for="standgroesse">Standgr&ouml;&szlig;e (in m&sup2;)</label><input type="text" value="20" id="standgroesse"></div>	<div><label for="freikartenanzahl">Anzahl der kostenlosen Karten</label><input type="text" value="4" readonly="readonly" id="freikartenanzahl"></div></fieldset>');
	
	$("#standgroesse").keyup( function() {
		 var standgroesse = parseInt($("#standgroesse").val());
		 var freikartenplus = 4 + Math.ceil((standgroesse-20)/20);
		 $("#freikartenanzahl").val("" + freikartenplus);
	});

	
	// Remove obtrusive styles for MSIE 6
	
	if($.browser.msie && $.browser.version < 7) {
		$(".obtrusive").removeClass("obtrusive").css( { 'font-weight' : 'bold', 'font-size' : '1.2em' });		
	}
	
	
});

/* 
 * Simulated accordion but with seperate panels 
 */
jQuery(function($) {	
	
	var accordionActive = false;
	
	$("#accordionToggle a").click( function() {
		
		var textToggle = '';
		
		if( $(this).html() == 'Expand all' || $(this).html() == 'Fold all') {
			var textToggle = ( $(this).html() == 'Expand all' ) ? 'Fold all' : 'Expand all';
		}
		else {
			var textToggle = ( $(this).html() == 'Alle ausklappen' ) ? 'Alle einklappen' : 'Alle ausklappen';
		}
		
		$(this).html(textToggle);
		$(this).toggleClass('toggle_active');
		
		if(accordionActive) {
			$("#accordion h3.ui-state-active").each(function() { showSinglePanel(this); });
			accordionActive = false;
		}
		else {			
			$("#accordion h3").not(".ui-state-active").each(function() { showSinglePanel(this); });
			accordionActive = true;
		}
		
		return false;
		
	});
	
	$("#accordion").addClass("ui-accordion ui-widget ui-helper-reset ui-accordion-icons")
	  .find("h3")
	    .addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all")
	    .hover(function() { $(this).toggleClass("ui-state-hover"); })
	    .prepend('<span class="ui-icon ui-icon-triangle-1-e"></span>')
	    .click(function() {
	    	
	    	if(!$(this).hasClass('ui-state-active') ) {
	    		hideActivePanels();	    	
	    		showSinglePanel(this);	    
	    	}
	    	return false;
	      
	    })
	    .next()
	      .addClass("text ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom")
	      .hide();	
	
});

function hideActivePanels() {
		jQuery("#accordion").find("h3.ui-state-active")
		.toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
        .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
        .next().toggleClass("ui-accordion-content-active").slideToggle();
}

function showSinglePanel(panel) {
	jQuery(panel)
	.toggleClass("ui-accordion-header-active ui-state-active ui-state-default ui-corner-bottom")
    .find("> .ui-icon").toggleClass("ui-icon-triangle-1-e ui-icon-triangle-1-s").end()
    .next().toggleClass("ui-accordion-content-active").slideToggle();    
	
}
/* Accordion end */

function initSlideshow()
{	

	jQuery(".featureItem").each(function() { jQuery(this).css('display','block'); });
	jQuery(".featureItem").each(function() { jQuery(this).css('visibility','visible'); });
	Cufon.refresh('.featureTextTitle');
	jQuery("#featureWrap").css('background-image','none');	

	jQuery("#featureWrap").before('<div id="slideshowPaging"></div>');
	jQuery("#slideshowControls a").eq(0).click(function() { jQuery('#featureWrap').cycle('prev'); return false; });
	jQuery("#slideshowControls a").eq(1).click(function() { jQuery('#featureWrap').cycle('next'); return false; });
	
	jQuery('#featureWrap').cycle({ 
	    fx:      'fade', 
	    easing: 'easeInOutQuad',
	    speed:    1000, 
	    timeout:  5000,
	    pager: '#slideshowPaging',
	    pagerEvent: 'mouseover',
	    pauseOnPagerHover: 1,
	    fastOnEvent: 500,
	    pagerAnchorBuilder: function(idx, slide) {	     
	     return '<img class="slideshowPagingButton" src="/fileadmin/templates/main/images/icons/blank_10x10.gif" alt="" />';
	    } 
	});
}
/* Trimming of Username and Password */

jQuery(function($) {	
	$("form").submit(function () {
		var user = $("#user").val();
		var pass = $("#pass").val();
		user = jQuery.trim(user);
		pass = jQuery.trim(pass);
		$("#user").val(user);
		$("#pass").val(pass);
	});
});

jQuery.noConflict();
