var width;
var height;
var stylesheet;
var stylesheetSlideshow;
var sideHeight;
var resizePics = false;
var jsonArray;

function checkResolution(url){
	var height = getBrowserHeight();
	var width = getBrowserWidth();

	if (height < 720 || width < 1280) {
		stylesheet = url + 'style_resize.css';
		stylesheetSlideshow = url + 'js/jon1012-smoothgallery/css/jd.gallery_resize.css';
		sideHeight = '300px';
		resizePics = true;
	} else {
		stylesheet = url + 'style.css';
		stylesheetSlideshow = url + 'js/jon1012-smoothgallery/css/jd.gallery.css';
		sideHeight = '450px';
	}
	
	
	var headID = document.getElementsByTagName("head")[0];
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = stylesheet;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
	
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = stylesheetSlideshow;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
	
}

function loadImages(singleImage, isWork){
	
	if (singleImage == true) {
		
		var parent = document.getElementById('singleImage');
		var imgInfo = jsonArray;
		
		var imgFull = document.createElement('img');
		imgFull.src = resizePics == true ? imgInfo.img_resized_content : imgInfo.img_content;
		parent.appendChild(imgFull);
		
		if (isWork == true) {
			var imageContainer = document.getElementById('singleText');
			imageContainer.innerHTML = imgInfo.p_content;
		}

	} else {
		
		var parent = document.getElementById('myGallery');
	
		for (var index = 0; index != jsonArray.length; index++) {
			
			var imgInfo = jsonArray[index];
			
			var imageElement = document.createElement('div');
			imageElement.className = 'imageElement';
			
			var h3 = document.createElement('h3');
			h3.innerHTML = imgInfo.h3_content;
			
			var p = document.createElement('p');
			p.innerHTML = imgInfo.p_content;
			
			var h = document.createElement('a');
			h.href = imgInfo.a_content;;
			h.title = imgInfo.p_content;
			h.target = "_blank";
			h.className = 'open';
			
			var imgFull = document.createElement('img');
			imgFull.src = resizePics == true ? imgInfo.img_resized_content : imgInfo.img_content;
			imgFull.className = 'full';
			
			var imgThumb = document.createElement('img');
			imgThumb.src = resizePics == true ? imgInfo.img_resized_content : imgInfo.img_content;
			imgThumb.className = 'thumbnail';
			
			
			imageElement.appendChild(h3);
			imageElement.appendChild(p);
			imageElement.appendChild(h);
			imageElement.appendChild(imgFull);
			imageElement.appendChild(imgThumb);
			parent.appendChild(imageElement);
				
		}
		
	}
	/*
	
*/	
}

function resizeLateral(){
	if (resizePics == true) {
		try {
			document.getElementById('sideResize').style.height = '330px';
		} catch (e) {
		}
	} else {
		try {
			document.getElementById('sideResize').style.height = '480px';
		} catch (e) {
		}
	}
}

function getBrowserHeight(){
    var height = 0;
    if (window.innerHeight) {
        height = window.innerHeight;
    }
    else
        if (window.document.documentElement && window.document.documentElement.clientHeight) {
            height = window.document.documentElement.clientHeight;
        }
        else
            if (window.document.body) {
                height = document.body.clientHeight;
            }

    return height;
}

function getBrowserWidth(){
    var height = 0;
    if (window.innerWidth) {
        height = window.innerWidth;
    }
    else
        if (window.document.documentElement && window.document.documentElement.clientWidth) {
            height = window.document.documentElement.clientWidth;
        }
        else
            if (window.document.body) {
                height = document.body.clientWidth;
            }
    return height;
}


function whichButton() {
	var key = null;
	document.onkeyup=function (event) {
		if(!event) {
			event=window.event;
			key = (window.event.keyCode);
		} else {
			key = (event.which);
		}
		
		if (key == 37) {
			// left
			
			goPrevious();
			
		} else if (key == 39) {
			//right
			goNext();
		}
	}
}

function checkImageIndex(){
	try {
		var urlIndex = location.href.split("#")[1];
		if (urlIndex != undefined) {
			indexToShow = urlIndex - 1;
			return indexToShow;
		} else {
			return 0;
		}
	} catch (error) {
		return 0;
	}	
}

function pauseGallery() {
	myGallery.clearTimer();
	isPaused = 1;
}

function goPrevious() {
	myGallery.prevItem();
	pauseGallery();
}

function goNext(){
	myGallery.nextItem(); 
	pauseGallery();
}

function resumeGallery() {
	myGallery.options.timed = true;
	myGallery.prepareTimer();
	myGallery.doSlideShow();
}


function PausePlayGallery() {
	
	if (isPaused == 0) {
		pauseGallery();
	    isPaused = 1;
	} else {
		resumeGallery();
		isPaused = 0;
    }
}
