// Copyright ELMA GmbH & Co. KG, Jan Kiesewetter
//hide  elements and fade them in
jQuery('img#bg-img,div#home,div#container').hide();
	

jQuery.fn.slideLeftHide = function( speed, callback ) { this.animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, speed, callback ); }
jQuery.fn.slideLeftShow = function( speed, callback ) { this.animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, speed, callback ); }

jQuery(document).ready(function () {
	//hide  elements and fade them in
	jQuery('img#bg-img,div#home,div#container').hide();
	
	//##############################################################################################
	// functions start
	function resizeBg(){
		var windowHeight = jQuery(window).height();
		var windowWidth = jQuery(window).width();
		
		jQuery('div#bg').css('height', windowHeight);
        jQuery('div#bg').css('width', windowWidth);
		
		if (windowWidth / windowHeight < 4/3) {
    		jQuery('img#bg-img').removeAttr('width');
    		jQuery('img#bg-img').attr('height', windowHeight);
	    } else {
    		jQuery('img#bg-img').removeAttr('height');
    		jQuery('img#bg-img').attr('width', windowWidth);
    	}
	}

	// functions end
	
	resizeBg();
	//jQuery('img#bg-img').load(function(){
	$(window).load(function(){
		jQuery('img#bg-img').fadeIn(800, function(){
			jQuery('div#home,div#container,div#logo').fadeIn(800);
		});
	});
	jQuery('img#bg-img').error(function(){
		jQuery('img#bg-img').fadeIn(800, function(){
			jQuery('div#home,div#container,div#logo').fadeIn(800);
		});
	});
	
	jQuery(window).resize(function () {
		resizeBg();
	});
	
	jQuery('div#content').children('div.csc-default:not(:first-child)').children(':not(div.csc-header)').hide();
	//jQuery('div#content').children('div.csc-default:first-child div.csc-header h2').addClass('open');
	jQuery('div.csc-header').click( function() {
		jQuery(this).nextAll().slideToggle('slow');
		//jQuery(this).children('h1,h2').toggleClass('open');
		jQuery(this).parent('div.csc-default').nextAll('div.csc-default').children(':not(div.csc-header)').slideUp('slow');
		jQuery(this).parent('div.csc-default').prevAll('div.csc-default').children(':not(div.csc-header)').slideUp('slow');
	});
	jQuery.getScript('/fileadmin/templates/em/js/fb/jquery.fancybox-1.3.4.pack.js', function(){
		jQuery('a.fb-group').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	400, 
			'speedOut'		:	400, 
			'overlayShow'	:	true,
			'overlayOpacity':	0.9,
			'overlayColor'  :   '#3C3C3C',
			'titlePosition' :	'over'
		});
	});
	
	var pkBaseURL = (('https:' == document.location.protocol) ? 'https://piwik.elma-ultrasonic.com/' : 'http://piwik.elma-ultrasonic.com/');
	jQuery.getScript(pkBaseURL + 'piwik.js', function(){
		var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 2);
		piwikTracker.trackPageView();
		piwikTracker.enableLinkTracking();
	});
});

