/* $Revision: 17816 $ $Date: 2010-11-08 18:18:22 +0100 (Mon, 08 Nov 2010) $ */

function openGallerySelectCardWindow(cardDefinitionId, ratio, orientation,hasDesignedBackside, singleProductId, doubleProductId,singleProductLogedInPrice,singleProductNotLogedInPrice,doubleProductLogedInPrice,doubleProductNotLogedInPrice,issoundcard,soundid,soundartist,soundtitle) {
	
	// Displaying popup	
	showGallerySelectCardWindow();	
	// Setting card definition info to popup
 	changeCardDefinition(cardDefinitionId, ratio, orientation,hasDesignedBackside, singleProductId, doubleProductId,singleProductLogedInPrice,singleProductNotLogedInPrice,doubleProductLogedInPrice,doubleProductNotLogedInPrice,issoundcard,soundid,soundartist,soundtitle);	
	 
}

function showGallerySelectCardWindow() {
	try {
		var windowInit = document.galleryAddCardPanelInit;
		// Make sure the width and height of the body are set
		if (isIE6()) {
			// If Internet Explorer 6
			$('body', 'html').css( {
				height : '100%',
				width : '100%'
			});
			if (document.getElementById('hideSelectsIframe') === null) {
				// Add an iframe to hide select elements
				$('body')
						.append(
								'<iframe id="hideSelectsIframe" frameborder="0"></iframe>');
			}
		}
		if(document.getElementById('gallerycardpreviewarea') === null) {
			$('body').append('<div id="gallerycardpreviewarea"></div>');
			// Moving preview popup to this area
			$('#gallerycardpreviewarea').append($('#' + windowInit.panelComponentId));
		}
		// Add the overlay and div for the dialog window
		if (document.getElementById('overlay') === null) {
			$('#gallerycardpreviewarea').before('<div id="overlay"></div>');
			$('#overlay').click(function() {
				closeGallerySelectCardWindow();
			});
		}

		// Use background and opacity
		$('#overlay').addClass('overlaybg');

		// Adding class to window
		$('#' + windowInit.panelComponentId).addClass('dialogWindow');
		// Display the window content

		positionGallerySelectCardWindow(windowInit);
		
		$('#' + windowInit.panelComponentId).css( {
			'display' : 'block'
		});
		
	} catch (ex) {
		window.console.error('An exception occurred: ' + ex);
	}
}
function positionGallerySelectCardWindow(windowInit) {
	if (isIE6()) {
		// In case of ie6 using absolute positioning
		var windowElem = $(window);
		var windowWidth = windowElem.width(), windowHeight = windowElem
				.height();
		$("#" + windowInit.panelComponentId + ",#hideSelectsIframe").css( {
			'top' : ((windowHeight - windowInit.height) / 2) + 'px',
			'left' : ((windowWidth - windowInit.width) / 2) + 'px',
			'position' : 'absolute',
			'width' : windowInit.width + 'px',
			'height' : windowInit.height + "px"
		});
	} else {
		$("#"+windowInit.panelComponentId).css( {
			'marginTop' : '-' + (windowInit.height / 2) + 'px',
			'marginLeft' : '-' + (windowInit.width / 2) + 'px',
			'width' : +windowInit.width + 'px',
			'height' : +windowInit.height + 'px'
		});
	}
}

function closeGallerySelectCardWindow() {
	try {
		// Move the content back to the source div
		$('#overlay,#hideSelectsIframe').remove();		
		$('#' + document.galleryAddCardPanelInit.panelComponentId).css( {
			'display' : 'none'
		});
		if (isIE6()) {
			$('body', 'html').css( {
				'height' : 'auto',
				'width' : 'auto'
			});
		}
	} catch (ex) {
		window.console.error("An error occurred closing the modal window", ex);
	}
}

function isIE6() {
	return jQuery.browser.msie && jQuery.browser.version < 7;
}
