﻿function toggleVisibility() {
    var e = document.getElementById('divPartProperties');
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

var imgpopup_data = null;


function variantform_show(partno) {
    flexpan_show_modal(510, 400, sitedata.variantformurl + '?partno=' + partno);
}


function imgpopup_show(partno, imgname) {
/*	var content = '<div style="height: 600px; 
	<img src="' + img_url + '" />'*/

	flexpan_show_modal(470, 570, sitedata.imgpopupurl + '?partno=' + partno + '&imgname=' + imgname);
	
/*    var img = document.getElementById('enlarge_image');
    var img_close = document.getElementById('img_close');
    var img_holder = document.getElementById('enlarge_image_holder');

    img.src = img_url;
    img_holder.visible = true;
    img.style.visibility = 'visible';

    img_holder.style.width = img.style.width;

    img_close.visible = true;
    img_close.style.visibility = 'visible';
    img_close.style.height = '15px';*/
}

function imgpopup_prev() {
	// hitta nuv bild
	var nuv = -1;
	for (var i = 0; i < imgpopup_data.bilder.length; i++) {
		if (imgpopup_data.selected == imgpopup_data.bilder[i]) {
			nuv = i;
		}
	}

	nuv = (nuv + imgpopup_data.bilder.length - 1) % imgpopup_data.bilder.length;

	var src = $('#detaljbild_enlarged_image').attr('src');
	$('#detaljbild_enlarged_image').attr('src', src.replace(imgpopup_data.selected, imgpopup_data.bilder[nuv]));
	imgpopup_data.selected = imgpopup_data.bilder[nuv];
}

function imgpopup_next() {
	// hitta nuv bild
	var nuv = -1;
	for (var i = 0; i < imgpopup_data.bilder.length; i++) {
		if (imgpopup_data.selected == imgpopup_data.bilder[i]) {
			nuv = i;
		}
	}

	nuv = (nuv + 1) % imgpopup_data.bilder.length;

	var src = $('#detaljbild_enlarged_image').attr('src');
	$('#detaljbild_enlarged_image').attr('src', src.replace(imgpopup_data.selected, imgpopup_data.bilder[nuv]));
	imgpopup_data.selected = imgpopup_data.bilder[nuv];
}

function imgpopup_hide() {
	flexpan_hide_modal();
}


/*function clear_image() {
    var img = document.getElementById('enlarge_image');
    var img_close = document.getElementById('img_close');
    var img_holder = document.getElementById('enlarge_image_holder');

    img_holder.visible = false;
    img.visible = false;
    img.style.visibility = 'hidden';
    img.style.textAlign = 'center';
    img_close.visible = false;
    img_close.style.visibility = 'hidden';
}*/


function flexpan_show_modal(xz, yz, content) {
	var contenttype = null;
	if ((typeof (content) == 'string' && content == '') || content == null) {
		contenttype = 'none';
	} else if (typeof (content) == 'string' && content.substr(0, 1) == '<') {
		contenttype = 'html';
	} else if (typeof (content) == 'string') {
		contenttype = 'url';
	}

	$('#modalbackground').css('display', '');
	$('#modalframe').css('width', xz + 'px').css('height', '0px').css('top', '40px');
	$('#modalholder').css('display', '');

	if (contenttype == 'url') {
		if (typeof (sedata) != 'undefined') {
			$('#modalframe').html('<img src="' + sedata.processinggif + '" alt="processing" />');
		}
		jQuery.post(content, function (data) {
			$('#modalframe').html(data);
		});
	} else if (contenttype == 'html') {
		$('#modalframe').html(content);
	}

	$('#modalbackground').animate({ opacity: 0.4 }, 200);
	$('#modalframe').animate({ height: yz + 'px' }, 200);
	$('#modalholder').animate({ top: (($(window).height() - yz) / 2) + 'px' }, 200);
}


function flexpan_hide_modal() {
	$('#modalbackground').animate({ opacity: 0.0 }, 200);
	$('#modalframe').animate({ height: '0px' }, 200);
	$('#modalholder').animate({ top: '0px' }, 200, function () {
		$('#modalframe').html('');
		$('#modalbackground').css('display', 'none');
		$('#modalholder').css('display', 'none');
	});
}

