 function mySbOpen(){
	var c = Shadowbox.getCurrent();
	//var pageLink = c.link.baseURI;
	var pageLink = c.link.ownerDocument.URL;
	if(pageLink.indexOf('?')>1){
		pageLink = pageLink.split('?')[0]
	}
	var link2image = pageLink+"?the_item="+c.link.shadowboxCacheKey;
	var newDiv = $('<div id="sb-mylink" style="height: 50px; width: 200px;">'+
				   '<a id="printMe" href="#" title="Print me"><img src="/sites/all/themes/jg_layout/shadowbox/icon-print.png" border="0"><span id="sb-link">Print</span></a></div>');
	if($('div#sb-mylink')!=null){
		$('div#sb-mylink').remove();
	}
	newDiv.insertAfter($('div#sb-counter'));
	$('a#printMe').click(function(){
		    
			var image = document.getElementById("sb-player");
			var imagesrc = image.src;
			var theWork =  window.open('','PrintWindow');
    		
			var html = "<html><head><title>Print Image</title></head>";
			
			var imagewidth = image.naturalWidth;
			var imageheight = image.naturalHeight;
			
			if (imageheight > 950 && imagewidth > 500) {
				var imageheightratio = imageheight / 950;
				var imagewidthratio = imagewidth / 500; 

				if (imageheightratio > imagewidthratio) {
					html = html + '<body><div><img src="'+imagesrc+'" height="950" /></div></body></html>';
				}
				else {
					html = html + '<body><div><img src="'+imagesrc+'" width="500" /></div></body></html>';
				}
			}
			else if (imageheight > 950 && imagewidth < 500) {
				html = html + '<body><div><img src="'+imagesrc+'" height="950 /></div></body></html>';
			}
			else if (imageheight < 950 && imagewidth > 500) {
				html = html + '<body><div><img src="'+imagesrc+'" width="500" /></div></body></html>';
			}
			else {
				html = html + '<body><div><img src="'+imagesrc+'" height="'+imageheight+'" /></div></body></html>';
			}

			theWork.document.open();
			theWork.document.write(html);
			theWork.document.close();
			theWork.print();
			theWork.close()
      return false;
								  
	});
}

