var global_valfield = '';

function setFocusDelayed() {
        document.getElementById(global_valfield).select();
        document.getElementById(global_valfield).focus();
}

function setFocus(field) {
  // save valfield in global variable
  global_valfield = field;
  setTimeout( 'setFocusDelayed()', 100 );
}

var main_image_original_width = 1440;
var main_image_original_height = 900;
var pic_width = main_image_original_width;
var pic_height = main_image_original_height;
     
// emulate 'position: fixed;' for IE6
function move_box() {
	var main_image_element = document.getElementById('background_image');
    main_image_element.style.top = (document.documentElement.scrollTop + 0) + 'px';
}

function resize_image() {
	var win_width = jQuery(window).width();
//	alert(win_width);

	var win_height = jQuery(window).height();
//	alert(win_height);

	current_width = jQuery('.main-image:visible').width();
	if (current_width > 1) {
		pic_width = current_width;
	} else {
		pic_width = pic_width;
	}
	
	current_height = jQuery('.main-image:visible').height();
	if (current_height > 1) {
		pic_height = current_height;
	} else {
		pic_height = pic_height;
	}
			
	// make image fit in window height
	var new_height = win_height;
	var new_width = (win_height / pic_height) * pic_width;
	
//	alert(new_width);

	if (new_width > win_width) {
		new_width = win_width;
		new_height = (win_width / pic_width) * pic_height;		
	}
	
	if (main_image_original_width < new_width || main_image_original_height < new_height) {
		new_width= main_image_original_width;
		new_height = main_image_original_height;
	}

	jQuery('.main-image').width(new_width);
	jQuery('.main-image').height(new_height);

	
	jQuery('#background_image').css({visibility:"visible", display:"block"});
	
	
	
}

function zoom_cropping() {
	var win_width = jQuery(window).width();
	var win_zoomed = win_width - 450;
	jQuery('.MagicZoomBigImageCont').css({width: win_zoomed});
}


function resize_image_with_cropping() {
	var win_width = jQuery(window).width();
	var win_height = jQuery(window).height();
	var win_aspect_ratio = win_width / win_height;

	current_width = jQuery('.main-image').width();
	if (current_width > 1) {
		pic_width = current_width;
	}	

	current_height = jQuery('.main-image').height();
	if (current_height > 1) {
		pic_height = current_height;
	}
	
	pic_aspect_ratio = pic_width / pic_height;
	
	if (win_aspect_ratio > pic_aspect_ratio) {
		// scale pic to fit window width
		var new_height = (win_width / pic_width) * pic_height;
		var new_width = win_width;
	} else {
		// scale pic to fit window height		
		var new_height = win_height;
		var new_width = (win_height / pic_height) * pic_width;
	}
	
	// center image
	new_top = 0 - ((new_height - win_height) / 2);
	new_left =  0 - ((new_width - win_width) / 2);
//	alert('new_top: ' + new_top + 'new_left: ' + new_left);
	jQuery('.main-image').css({top: new_top, left: new_left});

	jQuery('.main-image').css({height: new_height, width: new_width});
	jQuery('#background_image').css({height: win_height, width: win_width});

	
	jQuery('#background_image').css({visibility:"visible", display:"inline"});
	
	
}


function resize_image_non_linear() {
	var win_width = jQuery(window).width();
//	alert(win_width);

	var win_height = jQuery(window).height();
//	alert(win_height);

	current_width = jQuery('.main-image').width();
	if (current_width > 1) {
		pic_width = current_width;
	} else {
		pic_width = pic_width;
	}
	
	current_height = jQuery('.main-image').height();
	if (current_height > 1) {
		pic_height = current_height;
	} else {
		pic_height = pic_height;
	}
			
	// make image fit in window height
	var new_height = win_height;
	var new_width = win_width;
	
//	alert(new_width);

	jQuery('.main-image').width(new_width);
	jQuery('.main-image').height(new_height);

	
	jQuery('#background_image').css({visibility:"visible", display:"block"});
	
	
	
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


