﻿var retryAttempt = 0;
var CImageDetail = Class.create({
menu: function(name)
{

$$('.Tab').each(function(el){


	if(el.id.endsWith(name))
	{
		el.removeClassName(name)
		el.addClassName( name + 'On' )
		$(name + "Detail").show();
	}
	else
	{
		el.className = el.className.replace(/On/i,'');
		$(el.id + "Detail").hide()
	}

	})

}

, 
ShowComments:function()
{
$$('.imageComment').each(function(el)
{
el.show();
})

$$('.ViewAllComments')[0].hide();
}

,
GetFramedThumb:function(that, galleryid, imid, maxWidth, maxHeight, materialID)
{
    if ($(that.id).src == "http://ikfiles.imagekind.com/theme/Defaulttheme/loading_solid.gif")
    {
        return;
    }

    new Ajax.Request('/store/services/frame_engine_save.ashx', {method:'get', parameters: {IMID: imid, maxWidth: 150, maxHeight: 150, materialID: materialID,ShowDropShadows:'false' }}); 

    var tryURL = that.src;
    if(tryURL.indexOf('?') == -1)
        tryURL += '?1'
    else
        tryURL += '&1'

    if(typeof(that.style.maxHeight) != 'undefined')
    {
        that.style.maxHeight = maxHeight;
        that.style.maxWidth = maxWidth;
    }
    that.src = "http://ikfiles.imagekind.com/theme/Defaulttheme/loading_solid.gif";
    if (retryAttempt <= 3)
        window.setTimeout(function(){if(/loading/.test(that.src)) { that.src = tryURL; retryAttempt += 1;} },retryAttempt * 1000)
    else
    {
        if (imid.indexOf('_' == -1))
            that.src = "http://thumbs.imagekind.com/member/" + galleryid + "/uploadedartwork/150X150/" + imid + ".jpg";
        else
            that.src = "http://thumbs.imagekind.com/museum/150X150/" + galleryid + "/JPGS/" + imid + ".jpg";
    }
 }
,ShowLarge:function(box)
{
light = $(box)
fade = $('fade');
light.style.display='block';
fade.style.display='block';
var img = light.down(8);


var style = {top:0, left:0};
var width = img.getWidth()
var height = img.getHeight()

style.top      = (((10 + (document.documentElement.scrollTop || document.body.scrollTop))) ) + 'px';
style.left      = ((pageWidth() - width ) / 2) + 'px';
//style.height = (img.getHeight() + 23) + 'px'
//style.width = (img.getWidth() + 18) + 'px'
//alert(style.height)

fade.setStyle({height: getDocHeight() + 'px'});

light.setStyle(style)
}
, 
HideLarge:function()
{
light.style.display='none';
fade.style.display='none';
}
});
ImageDetail = new CImageDetail();


function UpdatePrintPrice()
{
    if ($E('select', 'lstPrintSizes') != null)
    {
        var size = $F($E('select', 'lstPrintSizes'));
        $E('input', 'hdnPrintSizeID').value = size;
        var material = $F('materialID');
        if (material >= 5 && material <= 12)
            material = 1;
	    new Ajax.Request('/store/services/PricingDetails.aspx',
        {
            parameters: {imid: $F('IMID'), sizeId: size, materialId: material, command: 'total'},
            onSuccess: function(response) {
                            $E('span', 'lblPrintUnframedPrice').innerHTML = response.responseText;
                       },
            onFailure: function(response) {
                            alert(response.responseText + 'd' + material);
                        }
        })
    }
}

function lstCanvasFinishChanged()
{
    if ($E('select', 'lstCanvasFinish') != null)
    {
        var finish = $F($E('select', 'lstCanvasFinish'));
        
        if (finish == "17" || finish == "19")
        {
            $E('div', 'trCanvasWrapColor').style.display = 'block';
            $E('div', 'trCanvasFrameColor').style.display = 'none';
        } 
        else if (finish == "22")
        {
            $E('div', 'trCanvasWrapColor').style.display = 'none';
            $E('div', 'trCanvasFrameColor').style.display = 'block';
        }
        else
        {
            $E('div', 'trCanvasWrapColor').style.display = 'none';
            $E('div', 'trCanvasFrameColor').style.display = 'none';
        }
        UpdateCanvasPrice();
    }  
}

function UpdateCanvasMaterialType()
{
    var finish = $F($E('select', 'lstCanvasFinish'));
    var wrapColor = $F($E('select', 'lstCanvasWrapColor'));
    var frameColor = $F($E('select', 'lstCanvasFrameColor'));
    
    if (finish == "17" || finish == "18")
    {
        if (wrapColor == "White")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "17";
        }
        else if (wrapColor == "Black")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "18";
        }
        else if (wrapColor == "ImageWrap")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "26";
        }
    } 
    else if (finish == "19" || finish == "20")
    {
        if (wrapColor == "White")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "19";
        }
        else if (wrapColor == "Black")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "20";
        }
        else if (wrapColor == "ImageWrap")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "27";
        }
    }
    else if (finish == "22")
    {
        if (frameColor == "Black")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "22";
        }
        else if (frameColor == "Gold")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "23";
        }
        if (frameColor == "White")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "24";
        }
        if (frameColor == "Brown")
        {
            getElementByEndingId("input", "hdnMaterialID").value = "25";
        }
    }
    else
    {
        getElementByEndingId("input", "hdnMaterialID").value = finish;
    }
}

function UpdateCanvasPrice()
{
    if ($E('select', 'lstCanvasSizes') != null)
    {
        var size = $F($E('select', 'lstCanvasSizes'));
        $E('input', 'hdnCanvasSizeID').value = size;
            
        var finish = $F($E('select', 'lstCanvasFinish'));

        new Ajax.Request('/store/services/PricingDetails.aspx',
        {
            parameters: { imid: $F('IMID'), sizeId: size, materialId: finish, command: 'total'},
            onSuccess: function(response) {
                            $E('span', 'lblCanvasUnframedPrice').innerHTML = response.responseText;
                       },
            onFailure: function(response) {
                            alert(response.responseText);
                        }
        })
    }        
}


function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function FramePopup(frameID) {
    var popup = window.open('http://www.imagekind.com/FrameDetail.aspx?FID=' + frameID, 'FrameDetail', 'scrollbars,resizable,width=515,height=750');
    popup.focus();
}
function FramePopupCurrent() {
    var current = $("frameID").value;
    FramePopup(current);
}

function getElementByEndingId(tagName, id) {
    var elements = document.getElementsByTagName(tagName);
    for (var i=0; i < elements.length; i++) {
        if (elements[i].id.lastIndexOf(id) == (elements[i].id.length - id.length) && elements[i].id.lastIndexOf(id) >= 0) {
            return elements[i];
        }
    }
}
