hs.showCredits = 0;
hs.padToMinWidth = true;

hs.dimmingOpacity = 0.75;
hs.fadeInOut = true;
hs.align = 'center';
hs.marginBottom = 50;
hs.marginLeft = 100;
hs.captionEval = 'this.a.title';
hs.captionOverlay.position = 'below';
hs.registerOverlay({
	html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
	position: 'top right',
	useOnHtml: true,
	fade: 2 // fading the semi-transparent overlay looks bad in IE
});

// ONLY FOR THIS EXAMPLE PAGE!
// Initialize wrapper for rounded-white. The default wrapper (drop-shadow)
// is initialized internally.
if (hs.addEventListener && hs.Outline) hs.addEventListener(window, 'load', function () {
	new hs.Outline('rounded-white');
	new hs.Outline('glossy-dark');
});
 

// focus the name field
hs.Expander.prototype.onAfterExpand = function(sender) {
	changePDF(sender.custom.url);
}

if (!hs.ie || hs.uaVersion > 6) hs.extend ( hs.Expander.prototype, {
	fix: function(on) {
		var sign = on ? -1 : 1,
			stl = this.wrapper.style;
 
		if (!on) hs.getPageSize(); // recalculate scroll positions
 
		hs.setStyles (this.wrapper, {
			position: on ? 'fixed' : 'absolute',
			zoom: 1, // IE7 hasLayout bug,
			left: (parseInt(stl.left) + sign * hs.page.scrollLeft) +'px',
			top: (parseInt(stl.top) + sign * hs.page.scrollTop) +'px'
		});
 
		if (this.outline) {
			stl = this.outline.table.style;
			hs.setStyles (this.outline.table, {
				position: on ? 'fixed' : 'absolute',
				zoom: 1, // IE7 hasLayout bug,
				left: (parseInt(stl.left) + sign * hs.page.scrollLeft) +'px',
				top: (parseInt(stl.top) + sign * hs.page.scrollTop) +'px'
			});
 
		}
		this.fixed = on; // flag for use on dragging
	},
	onAfterExpand: function(sender) {
		changePDF(sender.custom.url);
    	this.fix(true); // fix the popup to viewport coordinates
	},
 
	onBeforeClose: function() {
		this.fix(false); // unfix to get the animation right
	},
 
    onDrop: function() {
    	this.fix(true); // fix it again after dragging
	},
 
	onDrag: function(sender, args) {
		if (this.fixed) { // only unfix it on the first drag event
			this.fix(false);
		}
	}
 
});

hs.Expander.prototype.onBlur = function(sender) {
 	changePDF(sender.custom.url);
}

function doprint() {
	el = $('.highslide-image')[0];
	src = $('.highslide-image').attr('src');
	link = "about:blank";
	var pw = window.open(link, "_new");
	pw.document.open();
	pw.document.write(makepageprint(src));
	pw.document.close();
}

function noprint() {
	el = $('.highslide-image')[0];
	src = $('.highslide-image').attr('rel');
	alert(src);
	link = "about:blank";
	var pw = window.open(link, "_new");
	pw.document.open();
	pw.document.write(makepage(src));
	pw.document.close();
}

function makepageprint(src)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Dans Supermarket Ad</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

function makepage(src)
{
  // We break the closing script tag in half to prevent
  // the HTML parser from seeing it as a part of
  // the *main* page.

  return "<html>\n" +
    "<head>\n" +
    "<title>Dans Supermarket Ad</title>\n" +
    "</head>\n" +
    "<body>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

var currentPDF = ""

function changePDF(pdf) {
	currentPDF = "/data/upfiles/weeklyjpeg/"+pdf;	
  	
		$('#printer').remove();
		$('.highslide-full-expand').remove();
		
		if (currentPDF != "") {
			$('.highslide-next').after('<li id="printer"><a href="'+currentPDF+'" target="_blank"><span style="padding-left:0px; ">Print/Enlarge</span></a></li>');
		}
}
