﻿function CanvasSize() {

    this.Width = 0;
    this.Height = 0;
}


CanvasSize.prototype.isValid = function () {
	return ((this.Width != NaN) && (this.Height != NaN) && (this.Width > 0) && (this.Height > 0));
}






function CanvasSizeSelection()
{
	this.StandardSizeOptionControlId = null;
	this.CustomSizeOptionControlId = null;


    this.CustomLengthDropDownControlId = null;
    this.CustomWidthDropDownControlId = null;

    this.StandardSizeHorizontalOrientationDropDownControlId = null;
    this.StandardSizeVerticalOrientationDropDownControlId = null;

    this.StandardSizeHorizontalOrientationRadioButtonControlId = null;
    this.StandardSizeVerticalOrientationRadioButtonControlId = null;
}

CanvasSizeSelection.prototype.Debug = function(msg){
    alert(msg);
}


CanvasSizeSelection.prototype.CustomSizeSelected= function(){

    var _CustomSizeSelected = false;
    if (this.CustomSizeOptionControlId != null){
        $('#'+this.CustomSizeOptionControlId).each(function() {if ($(this).is(':checked')) {_CustomSizeSelected = true;}});
    }
    return _CustomSizeSelected;
}


CanvasSizeSelection.prototype.Orientation = function () {
       
	if ($("#" + this.HorizontalOrientationRadioButtonControlId).is(":checked") == true) {
		return "horizontal";
	}
	else if ($("#" + this.VerticalOrientationRadioButtonControlId).is(":checked") == true) {
		return "vertical";
	}
}



CanvasSizeSelection.prototype.getSize = function () {
	var selectedSize = new CanvasSize();

	if (this.CustomSizeSelected()) {
		if ((this.CustomLengthDropDownControlId != null) && (this.CustomWidthDropDownControlId != null)) {
			selectedSize.Width = parseInt($('#' + this.CustomWidthDropDownControlId).val());
			selectedSize.Height = parseInt($('#' + this.CustomLengthDropDownControlId).val());
		}
	}
	else {

		var ddlsize = null;
		var orientation = this.Orientation();       		

		if (orientation == "horizontal") {
			ddlsize = $("#" + this.StandardSizeHorizontalOrientationDropDownControlId);
		}
		else if (orientation == "vertical") {
			ddlsize = $("#" + this.StandardSizeVerticalOrientationDropDownControlId);
		}

		if (ddlsize != null) {

// parse standard size value
			var selection = ddlsize.find('option:selected');

			selectedSize.Width = parseInt(selection.attr("width"));
			selectedSize.Height = parseInt(selection.attr("length"));
		}
	}
	
	return selectedSize;
}




function CanvasSizePreview (){
    this.animate = false;
    this.scale = 0;
    this.maxX = 100;
    this.maxY = 100;
    this.x = 50;
    this.y = 50;
    this.CanvasFrame = null;
}

function ResizeInlinePreviewCanvasFrame(newSize, maxSize) {
    if (!newSize.isValid()) {
        return;
    }
   
    x = newSize.Width;
    y = newSize.Height;

	var width = maxSize;
	var height = maxSize;	
	
	var excesswidth = 0;
	var excessheight = 0;

	var widthlabel = $("#ProductSizeModifierPreviewInlineContents .ProductSizeModifierPreview_LabelWidth");
	var heightlabel = $("#ProductSizeModifierPreviewInlineContents .ProductSizeModifierPreview_LabelHeight");
	
	if (x >= y)
	{
		height = y / x * maxSize;
		excessheight = (maxSize / 2) - (height / 2)
		
	}
	else
	{
		width = x / y * maxSize;
		excesswidth = (maxSize / 2) - (width / 2);		
	}
	
	//Single
	var single1 = $("#canvassizeinlinepreview-single-1");
	
	single1.width(width);
	single1.height(height);
	
	single1.css("margin-top", excessheight);
	single1.css("margin-left", excesswidth);


	//Diptych
	var diptych = $("#canvassizeinlinepreview-diptych .PreviewPanel");
	var diptych1 = $("#canvassizeinlinepreview-diptych-1");
	var diptych2 = $("#canvassizeinlinepreview-diptych-2");

	diptych.height(height);
	
	var dwidth = width / 2 - 5; 
	diptych.width(dwidth);	

	diptych.css("margin-top", excessheight);	
	diptych1.css("margin-left", excesswidth);


	heightlabel.css("margin-left", excesswidth * -1)
	widthlabel.css("margin-top", excessheight * -1)

	
	//Triptych
	var triptych = $("#canvassizeinlinepreview-triptych .PreviewPanel");
	var triptych1 = $("#canvassizeinlinepreview-triptych-1");
	var triptych2 = $("#canvassizeinlinepreview-triptych-2");
	var triptych3 = $("#canvassizeinlinepreview-triptych-3");

	triptych.height(height);	

	var twidth = width / 3 - 7; 
	triptych.width(twidth);
	
	triptych.css("margin-top", excessheight);	
	triptych1.css("margin-left", excesswidth);


	heightlabel.css("margin-left", excesswidth * -1)
	widthlabel.css("margin-top", excessheight * -1)

	//Quad
	var quad = $("#canvassizeinlinepreview-quad .PreviewPanel");
	var quad1 = $("#canvassizeinlinepreview-quad-1");
	var quad2 = $("#canvassizeinlinepreview-quad-2");
	var quad3 = $("#canvassizeinlinepreview-quad-3");
	var quad4 = $("#canvassizeinlinepreview-quad-4");

	var qheight = height / 2 - 5;
	quad.height(qheight);	

	var qwidth = width / 2 - 5; 
	quad.width(qwidth);
	
	quad1.css("margin-top", excessheight);	
	quad2.css("margin-top", excessheight);	
	
	quad1.css("margin-left", excesswidth);
	quad3.css("margin-left", excesswidth);


	heightlabel.css("margin-left", excesswidth * -1)
	widthlabel.css("margin-top", excessheight * -1)

	

		
}

function ResizeWallPreviewCanvasFrame(newSize)
{
	var scale = 2.6;
	var size = 200;

	var width = newSize.Width * scale;
	var height = newSize.Height * scale;

	var excesswidth = (size / 2) - (width / 2);
	var excessheight = (size / 2) - (height / 2);
	
	//Single
	var single = $("#canvassizewallpreview-single .PreviewPanel");
	
	single.width(width);
	single.height(height);

	single.css("margin-left", excesswidth);
	single.css("margin-top", excessheight);	


	//Diptych
	var diptich = $("#canvassizewallpreview-diptych .PreviewPanel");
	var diptich1 = $("#canvassizewallpreview-diptych-1");
	var diptich2 = $("#canvassizewallpreview-diptych-2");
	
	diptich.width(width / 2);
	diptich.height(height);	
	

	diptich1.css("margin-left", excesswidth);
	diptich.css("margin-top", excessheight);


	//Triptych
	var triptich = $("#canvassizewallpreview-triptych .PreviewPanel");
	var triptich1 = $("#canvassizewallpreview-triptych-1");
	var triptich2 = $("#canvassizewallpreview-triptych-2");
	var triptich3 = $("#canvassizewallpreview-triptych-3");
	
	triptich.width(width / 3);
	triptich.height(height);	
	

	triptich1.css("margin-left", excesswidth);
	triptich.css("margin-top", excessheight);


	//Quad
	var quad = $("#canvassizewallpreview-quad .PreviewPanel");
	var quad1 = $("#canvassizewallpreview-quad-1");
	var quad2 = $("#canvassizewallpreview-quad-2");
	var quad3 = $("#canvassizewallpreview-quad-3");
	var quad4 = $("#canvassizewallpreview-quad-4");
	
	quad.width(width / 2);
	quad.height(height / 2);	
	

	quad1.css("margin-left", excesswidth);
	quad3.css("margin-left", excesswidth);
	quad1.css("margin-top", excessheight);
	quad2.css("margin-top", excessheight);


}
	
