/*<![CDATA[*/
/**
 * functions.js - Bibliothek mit uebergreifenden JavaScript Funktionen
 *
 * Copyright (c) 2010    die.interaktiven GmbH u. Co. KG
 *                       www.die-interaktiven.de
 *
 * Alle Rechte vorbehalten. Unberechtigte Kopie und Weiter-
 * verwendung nicht gestattet.
 *
 */

var DOCUMENT_ROOT = '/';

function doStart()
{
	setStatus('B&M Leuchten');

}
window.onload = doStart;

function setCycleButtons(value) {
	jQuery('#prev').css('display', value);
	jQuery('#next').css('display', value);
}


/*
function setButtonActive(element) {
	jQuery('#' + element).animate({opacity: '0.6'}, '100');
}
*/

$(document).ready(function() {
   	//jquery cycle plugin
	setCycleButtons('block');

	$('.image-list').cycle({
	        fx:      'fade',
			speed:   3000,
	        timeout:  1,
			pause:   1,
	        prev:    '#prev',
	        next:    '#next'
	});

	$('#next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#prev').bind('click', function() {
        carousel.prev();
        return false;
    });

	
	/* Anpassen der Seitenhöhe */
	
	var element = document.getElementById('page');
	
	var elementClientHeight	= element.clientHeight;
	
	var screenHeight		= screen.height;
	var screenWidth			= screen.width;
	
	//auf diese Hoehe muss verlaengert werden
	var innerHeight			= window.innerHeight;
	
	if(elementClientHeight < innerHeight) {
		newHeight = (innerHeight - elementClientHeight); 
		$('#space').css('height', (newHeight + 15));
	}
	
	/**********************************/
	
	//alert($('#image-gallery').html());

	$('#related-carousel').jcarousel({
    	auto: 8, //Sekunden
		
		scroll: 1,
		animation: 2000, //Millisekunden
		itemFallbackDimension: 300,
    });
	
	$('#scroll').jcarousel({
    	auto: 8, //Sekunden
		wrap: 'first',
		scroll: 1,
		animation: 2000, //Millisekunden
		itemFallbackDimension: 447,
    });
	
	
	//###Fancybox_!_START###########################	
	
			
			$("a.fancybox_productdetail").fancybox();
			
			
	//###Fancybox_!_ENDE###########################	

});



$(window).load(function() {
	positionContent();
	minOpacity = 0.6;
	maxOpacity = 1.0;
	minOpacityB = 0.4; /*Für Infobox-Start*/
	maxOpacityB = 1.0; /*Für Infobox-Start*/
	
	$("#prev").css({ opacity: minOpacity });
	$("#next").css({ opacity: minOpacity });
	$("#colspan-footer-col-left #image-start").css({ opacity: minOpacityB });
	$("#colspan-footer-col-center #image-start").css({ opacity: minOpacityB });
	$("#colspan-footer-col-right #image-start").css({ opacity: minOpacityB });
	
	$('#prev').hover(function(){
		$(this).stop().animate({ opacity: maxOpacity } , '100');
	} , function(){
		$(this).stop().animate({ opacity: minOpacity} , '100');
	});
	$('#next').hover(function(){
		$(this).stop().animate({ opacity: maxOpacity } , '100');
	} , function(){
		$(this).stop().animate({ opacity: minOpacity} , '100');
	});
	/*########START_Infobox-Start########*/
	$('#colspan-footer-col-left div.element.infobox-start').hover(function(){
		$("#colspan-footer-col-left #image-start").stop().animate({ opacity: maxOpacityB } , '100');
	} , function(){
	$("#colspan-footer-col-left #image-start").stop().animate({ opacity: minOpacityB } , '100');
	}); 
	$('#colspan-footer-col-center div.element.infobox-start').hover(function(){
		$("#colspan-footer-col-center #image-start").stop().animate({ opacity: maxOpacityB } , '100');
	} , function(){
		$("#colspan-footer-col-center #image-start").stop().animate({ opacity: minOpacityB } , '100');
	});
	$('#colspan-footer-col-right div.element.infobox-start').hover(function(){
		$("#colspan-footer-col-right #image-start").stop().animate({ opacity: maxOpacityB } , '100');
	} , function(){
		$("#colspan-footer-col-right #image-start").stop().animate({ opacity: minOpacityB } , '100');
	});	
	/*########ENDE_Infobox-Start########*/
});

$(window).resize(function() {
  positionContent();
});


/**
Schiebt den Content der Seite unter das Bild im Kopf der Seite.
Dies wurde benoetigt, da das entsprechende Bild mit einer relativen Breite von 100% eine vom Browser berechnete Hoehe bekommt.
Dadurch war ein haendisches Setzen der Element-Hoehe nicht moeglich.

Diese Funktion wird beim Laden der Seite (DOM und Assets fully loaded) als auch vom Resize-Event des Seitenfensters getriggert
**/
function positionContent() {
	var imgNaturalHeight 	= jQuery('.item > img:first').attr('naturalHeight');
	var imgNaturalWidth		= jQuery('.item > img:first').attr('naturalWidth');

	var ratio				= imgNaturalHeight / imgNaturalWidth;
	
	var windowWidth			= jQuery(window).width();
	var imgHeight			= Math.ceil(ratio * windowWidth);
	$('#colspan-header').css('height', imgHeight);	
	$('#startbild').css('height', imgHeight);
	
	var images = jQuery('.item img');
	jQuery(images).each(function(){
		jQuery(this).width(windowWidth);
	});
}


//window.innerHeight


/*]]>*/
