// on page load
jQuery(document).ready(function() {
	
	// tab navigation
	$('#appstore_selection li').click(function() {
		$('#appstore_selection li').removeClass('act');
		$(this).addClass('act');
	})
	
	// Clients Slideshow
	$('#clients').cycle({
		fx: 'fade', // fade
		timeout: 5000, // milliseconds between slides
		speed: 2000, // animation speed
		height: '140px', // height
		containerResize: 0 // no container resize
	});
	
	// News Carousel
	$('#news').jcarousel({
		auto: 5,
		wrap: 'circular',
		scroll: 1,
		timeout: 200, // milliseconds between slides
		speed: 2000, // animation speed
		dynamic: 60,
		initCallback: mycarousel_initCallback
	});
	
	/* Menu */
	$('.menu').hide();
	$('.showmenu').click(function() {
		$('.menu').slideToggle('slow');
	})
	
	/* Tooltips */
	$('.tooltip').tooltip();	
	
	/* Toggle */
	$('.toggleNow').click(function() {
		$('.toggle').slideToggle('slow', function() {		
			if($('.toggle_alttext').is(':hidden')) {
				$('.toggle_alttext').fadeIn();
			} else {
				$('.toggle_alttext').fadeOut();
			}
		});
	})
	
	// No redirect after click
	$('ul.appstore_selection li a').click(function(e) {
		e.preventDefault();
	});
	
	// Startcontact
	$('.startcontact_icon_mail').click(function() {
		$('.startcontact_iframe_div').fadeTo('fast', 0.95);
		$(this).fadeTo('fast', 0.01);
	});
	$('.startcontact_close').click(function() {
		$('.startcontact_icon_mail').fadeTo('fast', 1.00);
		$(this).parent().fadeOut();
		var iframeUrl = $('#startcontact_container_iframe_url').val();
		$('iframe.startcontact_iframe').attr('src', iframeUrl);
	});
});

// hide some products
function hideProducts(hideClasses) {
	if (hideClasses != '') {
		$('.appstore_product').stop(true, true); // stop all still running processes
		$('.appstore_product').fadeTo('fast', 1); // first of all - show all
		var classes = hideClasses.split(',');
		for (i=0; i < classes.length; i++) { // one loop for every product
			$('.' + classes[i]).fadeTo('slow', 0.10); // hide each product
		}
	}
}

// show all products
function showAllProducts() {
	$('.appstore_product').stop(true, true); // stop all still running processes
	$('.appstore_product').fadeTo('slow', 1); // show all
}

// Callback function for Carousel
function mycarousel_initCallback(carousel) {
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};
