
	//select img directory based on screen size
	function getDeviceImgPath(zoom)
	{
		var imgPath;
		var imgRoot
		
		if(zoom == "background"){
			imgRoot = "/downloads/Image/background/";
		}else{
			imgRoot = "/downloads/Image/gallery/";
		}
		
		if(zoom == "zoom"){
			imgRoot = imgRoot+"zoom_";
		}
		
		// over 1600 wide is considered Hi Res (2500w)
		// over 1440 wide is considered Hi Res (1600w)
		// between 1280 and 1440 is considered Widescreen (1440w)
		// between 800 and 1024 is considered Low Res (1024w)
		// less than 500 is considered mobile(500w)
		
		if (screen.width > 2500){
			imgPath = imgRoot+"2500/";
		}else if (screen.width > 1440){
			imgPath = imgRoot+"1600/";
		}else if (screen.width >= 1280){
			imgPath = imgRoot+"1440/";
		}else if (screen.width == 1024){
			imgPath = imgRoot+"1024/";
		}else if (screen.width < 500){
			imgPath = imgRoot+"500/";
		}
		
		// Iphone Stupidity
		if (screen.width == 320){ //iphone
			imgPath = imgRoot+"500/";
			$(".containerZoomControls").hide();
		}else if (screen.width == 768){ //ipad
			$(".containerZoomControls").hide();
			if(window.orientation == 0 || window.orientation == 180){
				imgPath = imgRoot+"1024/";
			}else{
				imgPath = imgRoot+"1024/";
			}
		}
		
		return imgPath;
	}
	
	// load the appropriate sized background for the users screen
	function loadDeviceBgImg(imgSrc)
	{
		var imgSrc;
		var imgSrcFrags;
		var imgSrcFragsCount;
		var imgFileName;
		var imgPath;
		var finalImage;		
		
		//get img src attribute into a var
		if (!imgSrc) {
			imgSrc = $('#bgImg').attr("src");
			//split imgSrc into array()
			imgSrcFrags = imgSrc.split("/")
			
			//set imgFilename = last record in array
			imgSrcFragsCount = imgSrcFrags.length;
			imgFileName = imgSrcFrags[imgSrcFragsCount-1];
		
			//select img directory based on screen size

			imgPath = getDeviceImgPath();
		
			//replace img with correct size
			finalImage = imgPath+imgFileName;
			$('#bgImg').attr('src', finalImage);
		}
		else{
			var imgSrcFrags = imgSrc.split("/");
			var imgSrcFragsCount = imgSrcFrags.length;
			var imgFileName = imgSrcFrags[imgSrcFragsCount-1];
			var imgArea = imgSrcFrags[imgSrcFragsCount-3];
			var imgRoot = getDeviceImgPath(imgArea);
						
			imgSrc = imgRoot+imgFileName;			
			$('#bgImg').attr('src', imgSrc);
		}
	}
	
	function getUrlStructure()
	{
		var pageurl;
		var pageurlFrags;
		var finalurl;
		
		pageurl = window.location+""; //forces string
		pageurl = pageurl.replace("http://", "");
		pageurl = pageurl.replace("https://", "");
		
		pageurlFrags = pageurl.split("/");
		pageurlFragsTemp = pageurlFrags.splice(0,1);
	
		finalurl = "/"+pageurlFrags.join("/");
		
		return finalurl;
	}
	
	function checkImageExists(img)
	{
		var data = getDeviceImgPath();
			data = data + img;
	
		var reply = $.ajax({
			type: "POST",
			url: "/includes/checkImages.php",
			data: "urlstring="+data,
			async: false,
			success: function(msg)
			{
				var message = msg+"";
			}
		}).responseText;
		
		return reply;
	}

	// Transform img element with class="bgmaximage" into div bg
	$(function()
	{
		var follows = "both";
			
		$('img.bgmaximage').maxImage({
			horizontalOffset: 250,
			maxFollows: follows,
			verticalAlign: 'top',
			horizontalAlign: 'right'
		});
	});		





	
