function openModalDialog(contentID) {
	$('#'+contentID).dialog({ draggable: false, 
							  modal: true, 
							  resizable: false, 
							  dialogClass: 'customizedDialog', 
							  width: 774,
							  height: viewportHeight * 0.7,
							  show: 'fade',
							  hide: 'fade',
							  open: function(){
								  $('.ui-widget-overlay').click(function(){ $('#'+contentID).dialog('close'); });
							  }});
}

var viewportWidth;
var viewportHeight;

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

if (typeof window.innerWidth != 'undefined')
{
     viewportWidth = window.innerWidth,
     viewportHeight = window.innerHeight
}

//IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

else if (typeof document.documentElement != 'undefined'
    && typeof document.documentElement.clientWidth !=
    'undefined' && document.documentElement.clientWidth != 0)
{
      viewportWidth = document.documentElement.clientWidth,
      viewportHeight = document.documentElement.clientHeight
}

// older versions of IE

else
{
      viewportWidth = document.getElementsByTagName('body')[0].clientWidth,
      viewportHeight = document.getElementsByTagName('body')[0].clientHeight
}

$(document).ready(function(){	
	
    if (!$.browser.opera) {

        $('select.styledSmall').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
                .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
                .after('<span class="selectSmall">' + title + '</span>')
                .change(function(){
                    val = $('option:selected',this).text();
                    $(this).next().text(val);
                    })
        });
		
		
		$('select.styled').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
                .css({'z-index':10,'opacity':0,'-khtml-appearance':'none'})
                .after('<span class="select">' + title + '</span>')
                .change(function(){
                    val = $('option:selected',this).text();
                    $(this).next().text(val);
                    })
        });

    };
	
	//$('#price').html(parseInt($('#unit').val()).toFixed(2));
	//$('#unit').change(function(){ $('#price').html(parseInt($(this).val()).toFixed(2)); });
	//$('#quantity').change(function(){ $('#amount').html(parseInt($('#unit').val()*$(this).val()).toFixed(2)); });

	$("a.fancybox").fancybox({
		'hideOnContentClick':false,
		'transitionIn':'elastic',
		'transitionOut':'elastic',
		'durationIn':50,
		'durationOut':50,
		'autoScale':true,
		'padding':0,
		'onComplete':function(){
			$("#fancybox-content").fadeIn(50);
		},
		'onCleanup':function(){
			$("#fancybox-content").hide(50);
		}
	});
	
	// Funktionen werden initial ausgeführt
	//updateBenefits();
	startSlideShow();
})


var slideVisibleTime = 5000;
var showsPosition = new Array();


function getElementsByName_iefix(tag, name) {
	var elem = document.getElementsByTagName(tag);
    var arr = new Array();
    for(i = 0,iarr = 0; i < elem.length; i++) {
   		att = elem[i].getAttribute("name");
        if(att == name) {
  			arr[iarr] = elem[i];
  			iarr++;
 	    }
  	}
    return arr;
}


function fade(step) {		
	var slideShows = document.getElementsByName("SLIDE-SHOW");
	if (slideShows.length == 0)
		slideShows = getElementsByName_iefix("div", "SLIDE-SHOW");
	var slideShow = null;
	
	step = step || 0;
	invStep = 100 - step;
	
	for (var showCount = 0; showCount < slideShows.length; showCount++) {
		slideShow = slideShows[showCount];
		var images = slideShow.getElementsByTagName("img");
		var imageCount = images.length;
		var position = showsPosition[showCount]; 
		var lastPosition = position - 1;
		if (lastPosition < 0)
			lastPosition = imageCount - 1;
   
		if (!isNaN(lastPosition)) {
			images[lastPosition].style.opacity = invStep/100;
			images[lastPosition].style.filter = "alpha(opacity=" + invStep + ")"; 
		}
		images[position].style.opacity = step/100;
		images[position].style.filter = "alpha(opacity=" + step + ")"; 
	}
    step = step + 2;

    if (step <= 100) {
        window.setTimeout(function () { fade(step); }, 1);
    } else {
        window.setTimeout(nextSlide, slideVisibleTime);
        lastPostiion = position;        
    }
}


function nextSlide() {
	var slideShows = document.getElementsByName("SLIDE-SHOW");
	if (slideShows.length == 0)
		slideShows = getElementsByName_iefix("div", "SLIDE-SHOW");	
	var slideShow = null;

	for (var showCount = 0; showCount < slideShows.length; showCount++) {
		slideShow = slideShows[showCount];
		var images = slideShow.getElementsByTagName("img");
		var imageCount = images.length;

		if (imageCount <= 0)
			continue;
	    
		if (isNaN(showsPosition[showCount])) {
			showsPosition[showCount] = 1;
		} else {
			if(++showsPosition[showCount] >= imageCount)
				showsPosition[showCount] = 0;
        }
    }
            
	fade();		
}


function startSlideShow() {
    window.setTimeout(nextSlide, slideVisibleTime);
}


