/**
 * This file contains modifications to Highslide JS for optimizing the display on mobile user agents.
 * 
 * @author Torstein Hønsi
 */
if (/(Android|BlackBerry|iPhone|iPod|Palm|Symbian)/.test(navigator.userAgent)) {
//if (true) {
	addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
		function hideURLbar(){
		window.scrollTo(0,1);
	}

	hs.addEventListener(document, 'ready', function() {

		// Add a meta tag to have the iPhone render the page 1:1
		hs.createElement('meta', {
			name: 'viewport',
			content: 'width=device-width; initial-scale=1.0; maximum-scale=1.0;'
		}, null, document.getElementsByTagName('head')[0]);
		
		// Add CSS rules
		var stylesheet = document.getElementsByTagName('style')[0];
		stylesheet.appendChild(document.createTextNode(
			'#wrapper {'+
			'	min-height: 0 !important; '+
			'}'+
			'.gallery, .nav {'+
			'	width: auto; '+
			'}'+
			'.desc_image, .image_info_alpha, .image_info_sub, .image_info_shop, .permalink, .download, .map, .selectionCheckboxDiv, #selection_counter, #inputfields {'+
			'	display: none; '+
			'}'+
			'.mainTitle {'+
			'	font-size: 10px; font-family: Helvetica, Arial, sans-serif; text-align: center; '+
			'}'+
			'.subTitle {'+
			'	font-size: 8px; font-family: Helvetica, Arial, sans-serif; text-align: center; '+
			'}'+
			'.desc_paragraph {'+
			'	font-size: 6px; font-family: Helvetica, Arial, sans-serif; text-align: justify; '+
			'}'+
			'.thumbnail_container {'+
			'	float: left; margin: 0; padding: 0; width: auto; '+
			'}'+
			'.thumbnail_frame {'+
			'	width: 68px; height: 68px; padding: 0; margin: 5px; border-width: 1px; '+
			'}'+
			'.thumbnail_frame div {'+
			'	margin-top: 0 !important; overflow: hidden; '+
			'}'+
			'.gallerythumb {'+
			'	border-width: 0 !important; padding: 0; '+
			'}'+
			'.highslide img {'+
			'	width: 100%; '+
			'}'+
			'.highslide-wrapper div.navbutton {'+
			'	color: white;'+
			'	font-size: 64px;'+
			'}'+
			'.highslide-full-expand {'+
			'	display: none !important;'+
			'}'+
			'.highslide-wrapper {'+
			'	background: none !important;'+
			'}'+
			'.highslide-caption, .highslide-heading {'+
			'	border: none !important;'+
			'	color: white !important;'+
			'	background: none !important;'+
			'	display: none !important;'+
			'}'+
			'#footer {'+
			'	padding: 20px auto 0; border-top: 0; '+
			'}'+
			'#footer_content {'+
			'	width: auto; '+
			'}'
		));

		// add some options that make sense on a small touchscreen
		hs.outlineType = null; // outlines look distorted at normal zoom
		hs.expandDuration = 0; // animation is too slow anyway
		hs.restoreDuration = 0;
		hs.transitionDuration = 0;
		hs.wrapperClassName = 'borderless'; // take all the space available for the image
		hs.marginTop = 0;
		hs.marginRight = 0;
		hs.marginBottom = 0;
		hs.marginLeft = 0;
		hs.captionOverlay.fade = false;
		
		// Remove any slideshows with too small controls
		hs.slideshows = [];
		
		// Create custom previous and next overlays
		hs.registerOverlay({
			position: 'middle left',
			width: '20%',
			html: '<div class="navbutton"  onclick="hs.previous()"  title="'+
				hs.lang.previousTitle +'">‹</div>',
			hideOnMouseOut: false
		});
		hs.registerOverlay({
			position: 'middle right',
			width: '20%',
			html: '<div class="navbutton" style="text-align: right" onclick="hs.next()" title="'+
				hs.lang.nextTitle +'">›</div>',
			hideOnMouseOut: false
		});
	
	});

}
