// JavaScript Document

var leftHS = new Array();
var topHS = new Array();
var ratioH = 0;  // Used for aspect ratio
var ratioW = 0;  // Used for aspect ratio

function readHotspots() {
    var z = 0;
    $('.hotspot').each(function() {
        leftHS[z] = parseInt($(this).css("left"));
        topHS[z] = parseInt($(this).css("top"));
        z++;
    });
}

function changeHotspots(dw, dh) {
    var z = 0;
    $('.hotspot').each(function() {
        var newleft = leftHS[z] * (dw / 1300);
        var newtop = topHS[z] * (dh / 867);
        $(this).css("left", newleft);
        $(this).css("top", newtop);
        z++;
    });
}

function resizeBG() {

    var newHeight = 0;
    var newWidth = 0;
    var minWidth = 760; // Min width for the image
    var maxWidth = $('body').width()-240; // Max width for the image
    var maxHeight = $('body').height();    // Max height for the image	
    if (minWidth > maxWidth) { maxWidth = minWidth; }
    
    if (maxHeight < 550) {
        $('#aussenrahmen').css("height", 550);
        maxHeight = 550;
    } else {
        $('#aussenrahmen').css({'height' : '100%'});
        maxHeight = $('body').height(); 
    }
    
    $('.Startanimation .resizeable').css("display", 'block');
    $('.resizeable img').each(function() {
    	$('.ajax-container img').click(function() {
  		resizeBG();
	});
            var width = 1300;    // Current image width
      	  	var height =867;  // Current image height 

        ratioH = maxHeight / height; // get ratio for scaling image
        ratioW = maxWidth / width;   // get ratio for scaling image
        
        // Check if the current width is larger than the max
        newWidth = width * ratioW;
        newHeight = height * ratioW;
        
        // Check if current height is smaller than max
        if(height * ratioW < maxHeight) {
            newWidth = width * ratioH;
            newHeight = height * ratioH;
        }
        
        $(this).css("height", newHeight);   // Set new height
        $(this).css("width", newWidth);    // Scale width based on ratio
        $('img.zoom_out').css({'width': newWidth, 'height': newHeight});
        $('#rahmen_links').css("width", maxWidth);
        $('#rahmen_links').css("height", maxHeight);
    
    });
    $('.zoom_pic img').each(function() {
    	$('.ajax-container img').click(function() {
  		resizeBG();
	});


            var width = 1300;    // Current image width
            var height = 1174;
 
        ratioH = maxHeight / height; // get ratio for scaling image
        ratioW = maxWidth / width;   // get ratio for scaling image
        
        // Check if the current width is larger than the max
        newWidth = width * ratioW;
        newHeight = height * ratioW;
        
        // Check if current height is smaller than max
        if(height * ratioW < maxHeight) {
            newWidth = width * ratioH;
            newHeight = height * ratioH;
        }
        
        $(this).css("height", newHeight);   // Set new height
        $(this).css("width", newWidth);    // Scale width based on ratio
        $('img.zoom_out').css({'width': newWidth, 'height': newHeight});
        $('#rahmen_links').css("width", maxWidth);
        $('#rahmen_links').css("height", maxHeight);
    
    });
    changeHotspots(newWidth, newHeight);
    
    //$('.resizeable').css("display", 'none');
    $('.resizeable').eq(aktBild).css("display", 'block');
    

    // Die Weiter- und Zurück-Buttons zentrieren
    var wz_top = ($(window).height()/2) - 49;
if ( $(".p_weiter_bild").length > 0 ) {
   $('.p_weiter_bild').css('top', wz_top);
   }
   if ( $(".p_zurueck_bild").length > 0 ) {
    $('.p_zurueck_bild').css('top', wz_top);
}
}
