﻿if(typeof(IK) == 'undefined')
	var IK = Class.create({});
	
var CDisplayImage = Class.create({
onload: function()
{
	if($('dpPageSize') == null) return;
	var size = $('dpPageSize')
	var url = window.location.href;

	if(/size=\d{2}/.test(url))
	{
		 var selectedSize = url.substring(url.indexOf('size=') + 5, url.indexOf('size=') + 7)
		for(x = 0; x < size.length; x++)
		{
			if(size[x].innerHTML == selectedSize)
			{
				size[x].selected = true;
			}
		}
	}

Event.observe('dpPageSize', 'change',IK.DisplayImage.getSize, false);
}
,getSize: function(that)
{	
	var url = window.location.href;

	//has the word size a 2 digits
	if(/size=\d{2}/.test(url))
	{
		url= url.replace(/size=\d{2}/g,'size='+$F('dpPageSize'))
	}
	else
	{
		var newURL =  /\?/.test(url) ? '&': '?' ;
		url  =   url + newURL + 'size='+$F('dpPageSize');
	}
	 window.location.href = url;
}
,delHover: function(imageDiv)
{
	var icon = $(imageDiv)
	var hover = icon.down().next();
	try
	{
		hover.hide();
	}
	catch(x)
	{
		Util.log('Hover Error ' + x)
	}
}
, buyOptions: function(div,id, type)
{
	div= $(div)
	var menu = div.next(1);

	new Ajax.Request('/services/showpurchaseoptions.ashx'
	,   {	 method:'get'
	, parameters: {IMID: id, num: escape(Date()),MembershipType: 'Member'} 
	, onSuccess: function(transport)
	{
		menu.innerHTML = transport.responseText;   
		menu.toggle();
	}
	, onFailure:  Util.LogAjaxError
	}); 
}
,ImageShadow:function(that, IE6)
{
	var that = $(that)
	
	var wrap1 = that.up(4)
	
	wrap1.addClassName('ImageShadow');
			/*var wrap1 = that.up(3)
			var wrap2 = that.up(2)
			var wrap3 = that.up(1)
			wrap1.setStyle({backgroundImage:'url(/images/shadow/Oshadow.gif)'})
			wrap2.setStyle({backgroundImage:'url(/images/shadow/corner_bl.gif)'})
			wrap3.setStyle({backgroundImage:'url(/images/shadow/corner_tr.gif)'})
	*/
	that.show();
	
	
		var scwidth = 177;
	if(/showartwork/i.test(window.location.href))
	scwidth = 158;
	
	
	var wrap1 = that.up(4)
	var mTop = ((157 - that.getHeight()) / 2  ) + 'px';
	var mLeft = ((scwidth - that.getWidth()) / 2) + 'px';
	var ICHeight = (165 - (((150 - that.getHeight()) / 2  ) )) +'px'
	wrap1.setStyle({marginLeft:mLeft, marginTop:mTop, paddingTop:'10px', height:ICHeight});
	var ImageContainer = that.up(5)
	ImageContainer.setStyle({backgroundImage:'url(/images/blank.gif)'})
	ImageContainer.observe('mouseover', function(event)
	{ 
	try
	{
		var el = Event.element(event)
		var wrap1 = that.up(4)

		/*
		var wrap1 = that.up(3)
		var wrap2 = that.up(2)
		var wrap3 = that.up(1)
		wrap1.setStyle({backgroundImage:'url(/images/blank.gif)'})
		wrap2.setStyle({backgroundImage:'url(/images/blank.gif)'})
		wrap3.setStyle({backgroundImage:'url(/images/blank.gif)'})
		*/
			wrap1.removeClassName('ImageShadow');

		}
		catch(ex){Util.log(ex)}
	});
	
	ImageContainer.observe('mouseout', function(event)
	{
		try
		{
		
		var wrap1 = that.up(4)
	
	wrap1.addClassName('ImageShadow');
		/*
			var el = Event.element(event)
			var wrap1 = that.up(3)
			var wrap2 = that.up(2)
			var wrap3 = that.up(1)
			wrap1.setStyle({backgroundImage:'url(/images/shadow/Oshadow.gif)'})
			wrap2.setStyle({backgroundImage:'url(/images/shadow/corner_bl.gif)'})
			wrap3.setStyle({backgroundImage:'url(/images/shadow/corner_tr.gif)'})
		*/			
		}
		catch(ex){Util.log(ex)}
	});
	if(IE6)	
	{
		if(that.width > 150)
		{
			that.width = that.width - (that.width - 150)
		}
		if(that.height > 150)
		{
			that.height = that.height - (that.height - 150)
		}
	}
	
		
}
,ShowFramed: function(param)
 {
 	var clientsize =  document.viewport.getDimensions() 
	var loca = $(param.parentid).cumulativeOffset()
	var win = new Window({className:  "alphacube",
               width:  300 , 
               height: 300,
               minimizable:false,
               maximizable:false
              });
    win.setHTMLContent('<img src="/images/icons/wait_big.gif" alt="" />')
	win.setZIndex(2)
	win.showCenter();
	
	imgPreloader = new Image();

	// once image is preloaded, resize image container
	imgPreloader.onload=function(){

	var width = imgPreloader.width   +   80 ;
	var height = imgPreloader.height +  90 ; 
	var imagescale = 0;

	if(height > clientsize.height - 50 || width > clientsize.width - 50)
	{
		imagescale =140;
		width = imgPreloader.width - imagescale + 80;
		height = imgPreloader.height - imagescale + 80; 
	}

 var imagewidth = imgPreloader.width - imagescale;
 var imageheight = imgPreloader.height - imagescale;

 var shadow = '';  

 var shadowwidth = imagewidth + 10;
 var shadowheight = imageheight - 24;

	 if(param.typeId == "0")
	{
	 var htm  = '<div style="float:left; margin-left:40px; "><table id="table'+ param.id +'" style="text-align:left; "><tr><td style="text-align:left; white-space:nowrap;  " id="c1'+ param.id +'" class="Text4">' + param.title + '</td></tr>'
	htm += '<tr><td class="Text9" style="white-space:nowrap;"><a id="gallery'+ param.id +'"  href="' + param.primaryHost + '/galleryprofile.aspx?gid='+ param.galleryid +'"> </td></tr>'
	htm += '<tr><td  class="Text4"><a href="' + param.primaryHost + '/Memberprofile.aspx?MID='+ param.memberid +'" >' + IK.Translate.SearchBy + ' ' + param.artistName + '</a></td></tr></table></div>'
	
	if (param.isNotForSale == "False")
	{
	    htm += '<div style="float:right; clear:right;  width:195px;"><table style="width:195px; white-space:nowrap;"><tr><td class="Text4 cost" id="cost'+ param.id +'"></td></tr>'
	    htm += '<tr><td class="Text5"><a href="' + param.primaryHost + '/frameshop.aspx?IMID='+param.id+'&byartist=1">' + IK.Translate.SearchByShown + '<a></td></tr>'
	    htm += '<tr><td class="Text5"><a href="' + param.primaryHost + '/' + param.title.replace(' ' ,'-') + '_art?imid='+param.id+'">' + IK.Translate.SearchPurchaseOptions + '</a></td></tr></table></div>'
    }
	var innerWidth = width - 40;
	if(Prototype.Browser.IE)
	{
		htm += '<div style="text-align:left; margin-top:5px; margin-left:40px; margin-bottom:5px; width:' +innerWidth  + 'px;  float:left; clear:none;">'
	}
else if(Prototype.Browser.Gecko)
{
 htm += '<div style="text-align:center; margin-top:5px;  float:none; ">'
}
else
{
 htm += '<div style="text-align:left; margin-top:5px; margin-left:40px; margin-bottom:5px; width:' +innerWidth  + 'px;  float:left; clear:none;">'
}
 htm +=  '<img width="' + imagewidth  +'" height="' + imageheight + '"  id="img' + param.id + '" src="http://www.imagekind.com/services/frame_engine_default.ashx?IMID=' + param.id + '&typeId=' + 1 +   '&maxWidth=650&maxHeight=650'+ '" />'
 htm += shadow + '</div>'
 }
else
{
 var htm  = '<div style="float:left; margin-left:40px; width:150px;"><table id="table'+ param.id +'" style="text-align:left; white-space:nowrap;overflow:visible; width:150px"><tr><td id="c1'+ param.id +'" class="Text3" style="white-space:nowrap;overflow:visible;">' + param.title + '</td></tr>'
 htm += '<tr><td class="Text9" style="white-space:nowrap;overflow:visible;"><a href="/'+param.artistName.replace(" ", "-")+'_artwork?category=artist&id=' + param.artistid + '">'+ IK.Translate.SearchBy + ' ' + param.artistName + '</a> </td></tr>'
htm += '<tr><td  class="Text4" style="white-space:nowrap;overflow:visible;"><a href="/'+param.title.replace(' ' ,'-')+'_art?imid='+param.id+'">' + IK.Translate.SearchPurchaseOptions + '</a></td></tr></table></div>'
htm += '<div style="clear:right;float:right;margin-right:40px;"><table style="width:150px;"><tr><td class="Text4" id="cost'+ param.id + '"> '+IK.Translate.SearchAsShown + '"></td></tr>'
 htm += '<tr><td class="Text5"><a href="/frameshop.aspx?IMID='+param.id+'&byartist=1">' + IK.Translate.SearchByShown + '<a></td></tr>'
htm += '<tr><td class="Text5"></td></tr></table></div>'

if(Prototype.Browser.IE)
{
 htm += '<div style="text-align:left; margin-top:5px; margin-left:40px; width:' +innerWidth  + 'px;  float:left; clear:both;">' 
 }
else if(Prototype.Browser.Gecko)
{
 htm += '<div style="text-align:center; margin-top:5px;  float:none; clear:both;">'
}
else
{
  htm += '<div style="text-align:left; margin-top:5px; margin-left:40px; width:' +innerWidth  + 'px;  float:left; clear:none;">'
}
 htm += '<img width="' + imagewidth +'" height="' + imageheight + '" id="img' + param.id + '" src="http://www.imagekind.com/services/frame_engine.ashx?IMID=' + param.id + '&sizeId=1&cropLeft=0&cropTop=0&cropRight=0&cropBottom=0&frameId=602&topMatId=1324&topMatSpacingTop=3&topMatSpacingLeft=3&topMatSpacingRight=3&topMatSpacingBottom=3&glazingId=4&materialId=1&maxWidth=650&maxHeight=650"  />'
 htm += shadow + '</div>'
}

if(Prototype.Browser.IEVersion == 6)
{
width = width + 75;
height = height + 20;
}

if(width < 400)
width = 400;
    
    win.setHTMLContent(htm)
	win.setSize(width,height);
	win.showCenter();


	
if(Prototype.Browser.IEVersion == 6)
imagescale = imagescale + 150;


 if(param.typeId == "0")
 { 
	new Ajax.Request('/services/search.ashx'
	,   {	 method:'get'
	, asynchronous:false
	, parameters: {IMID: param.id, num: escape(Date()),GID: param.galleryid} 
	, onSuccess: function(transport)
	{
		var response = (transport.responseText).evalJSON();  
		if (param.isNotForSale == "False") 
    		$('cost'+ param.id).innerHTML = response.price;
		$('gallery'+ param.id).innerHTML = response.galleryName.substring(0,22);
	}
	, onFailure:  Util.LogAjaxError
}); 
}else
{

	new Ajax.Request('/services/PricingDetails.aspx?br=imagekind&IMID=' + param.id +'&sizeId=1&cropLeft=0&cropTop=0&cropRight=0&cropBottom=0&frameId=602&topMatId=1324&topMatSpacingTop=3&topMatSpacingLeft=3&topMatSpacingRight=3&topMatSpacingBottom=3&glazingId=4&materialId=1&command=total' 
	,   {	 method:'get'
	, asynchronous:false
	, onSuccess: function(transport)
	{
		$('cost'+ param.id).innerHTML = transport.responseText;
	}
	, onFailure:  Util.LogAjaxError
}); 
}
}
if(param.typeId == "0")
{
		imgPreloader.src = 'http://www.imagekind.com/services/frame_engine_default.ashx?IMID=' + param.id + '&typeId=' + 1 + '&maxWidth=650&maxHeight=650' ;
}
else
{
		imgPreloader.src ='http://www.imagekind.com/services/frame_engine.ashx?IMID=' + param.id + '&sizeId=1&cropLeft=0&cropTop=0&cropRight=0&cropBottom=0&frameId=602&topMatId=1324&topMatSpacingTop=3&topMatSpacingLeft=3&topMatSpacingRight=3&topMatSpacingBottom=3&glazingId=4&materialId=1' + '&maxWidth=650&maxHeight=650'
}
 }
 
 ,getImageGuid:function(el)
 {
	var url = el.src.split("/");
	return url[url.length].replace('.js','');
 }
 
 , Advanced: function()
 {
	var keywords = $('KeyWord').value;
	var title = $F('Title');
	var firstName = $F('FName');
	var lastName = $F('LName');
	var screenName = $F('ScreenName');
	var ID = $F('Id');
	var typeid = $('image');
	var isAdult = $('Adult').checked == true? 'True':'False';
	var IMID =  $('imageID').checked  ? ID :"";
	var GID = $('galleryID').checked  ? ID :"";
	var MID = $('memberID').checked  ? ID :"";
	var searchString = 'searchresult.aspx?Keyword=' + keywords + '&title=' + title + '&FirstName=' + firstName + '&LastName=' + lastName
	searchString += '&ScreenName=' + screenName + '&Adult=' + isAdult;
	searchString += '&imageId=' + IMID + '&galleryId=' + GID + '&memberId=' + MID;
	Util.Nav(searchString);
 }
 
});




FastInit.addOnLoad(IK.DisplayImage = new CDisplayImage());
Event.observe(window, 'load', IK.DisplayImage.onload, false);

	
	
