/*
 *
 */

/*
 *
 */
jQuery.fx.step.syncWidth = function(fx){
    if (!fx.state) {
        var o = fx.options;
        fx.start = jQuery(fx.elem).width();
        fx.syncStart = [];
        fx.fullWidth = o.fullWidth;
 
        fx.syncElements = jQuery(o.syncElements)
            .map(function(i, elem){
                if(elem !== fx.elem){
                    return elem;
                }
            })
            .each(function(i){
                fx.syncStart.push(jQuery(this).width());
            });
 
        fx.syncEnd = (fx.fullWidth - fx.end) / fx.syncElements.length;
    }
    var syncedWidth = 0;
    fx.syncElements
        .each(function(i){
            var width = Math.round(fx.pos * (fx.syncEnd - fx.syncStart[i]) + fx.syncStart[i]);
            syncedWidth += width;
            this.style.width = width + fx.unit;
        });
 
    fx.elem.style.width = fx.fullWidth - syncedWidth + fx.unit;
};

/*
 *
 */
cyclicFade = function(target) {
	var el = jQuery(target);
	el.fadeTo(600, 0.25, function(){
		el.fadeTo(600, 1.0, function(){cyclicFade(target);});
	});
};

/*
 *
 */
initIntro = function() {
	var easing_in 	= "easeOutCubic";
	var speed_in 	= "slow";
	var easing_out 	= "easeOutCubic";
	var speed_out 	= "slow";
	var full_width	= 960;
	var max_width	= 576;
	var min_width	= 192;
	
	// initialize grid animation
	jQuery("#z35intro .grid-cell").hover(
		function(){
			jQuery(this)
				.stop(true)
				.animate({syncWidth: max_width}, {syncElements: jQuery('.grid-cell',jQuery(this).parent()), fullWidth: full_width, easing: easing_in, duration: speed_in});
		},
		function(){
			jQuery(this)
				.stop(true)
				.animate({syncWidth: min_width}, {syncElements: jQuery('.grid-cell',jQuery(this).parent()), fullWidth: full_width, easing: easing_out, duration: speed_out});
		}
	);	
	
	// initialize scrollable and return the programming API 
	var api = jQuery("#z35intro").scrollable({ 
		items: '#z35intro .slides', 
		size: 1, 
		clickable: false 
	 
	// use the navigator plugin 
	}).navigator({
		api: true,
		navi: "#z35navi", 
        naviItem: 'a.naviitem', 
        activeClass: 'active' 
	});
    
	// setup click handler in grid
	jQuery("#z35intro .grid .vertrauen div a").click(function(){ api.seekTo(1); });
	jQuery("#z35intro .grid .flexibilitaet div a").click(function(){ api.seekTo(2); });
	jQuery("#z35intro .grid .bedingungen div a").click(function(){ api.seekTo(3); });
	jQuery("#z35intro .grid .haende div a").click(function(){ api.seekTo(4); });

	// and setup click handler on page logo
	jQuery("#header h1 a").click(function(){ api.seekTo(0); return false; });
	
	// start blinking button
	cyclicFade("#z35intro-blinker");
	
	// hide blinking button once the mouse is over grid area
	jQuery("#z35intro").one('mouseover', function(){
		jQuery("#z35intro-blinker").stop().fadeOut();
  	});

};

/*
 *
 */
initVideo = function(){
	jQuery("a.fancytrigger").fancybox({'hideOnContentClick': true});
					
	var flashvars = {
		'file':'http://www.zu-hause-gepflegt.de/fileadmin/gute_pflege_braucht/layout/video/trailer.flv',
		//'image':'video/trailer.jpg',
		'controlbar':'over',
		'autostart':'true',
		'stretching':'fill'
	};
	var params = {
		'allowfullscreen': 'true',
		'allowscriptaccess': 'always',
		'wmode':'opaque'
	};
	var attributes = {};
	swfobject.embedSWF("fileadmin/gute_pflege_braucht/layout/video/player.swf", "mediaspace", "640", "360", "9.0.0","fileadmin/gute_pflege_braucht/layout/js/swfobject/expressInstall.swf", flashvars, params, attributes);
};


