	var uploadingNow = "false";
	var currentState = 0; // 0: Flex, 1: Upload component
	
	var upload_large = 4000;
	var upload_medium = 1800;
	var upload_small = 1100;

	var iframe_x = 0;
	var iframe_y = 0;
	var iframe_w = 0;
	var iframe_h = 0;
	
	// Set proportions of uploaded picture
	function setUploadProportions(value) {
		switch(value) {
			case "low":
				getImageUploader("ImageUploader1").setUploadThumbnail1Width(upload_small);
				getImageUploader("ImageUploader1").setUploadThumbnail1Height(upload_small);
  				break;  
			case "medium":
				getImageUploader("ImageUploader1").setUploadThumbnail1Width(upload_medium);
				getImageUploader("ImageUploader1").setUploadThumbnail1Height(upload_medium);
  				break;
			case "high":
				getImageUploader("ImageUploader1").setUploadThumbnail1Width(upload_large);
				getImageUploader("ImageUploader1").setUploadThumbnail1Height(upload_large);
				break;  
			default:
  				break;
		}
		
	}

	// Checking if environment and component are ok for running ActiveX
	function checkActiveX() {
		var callResult = PTImagine.activeXCheckCallback(activeXAvailable());
    	}

	var activeXEnabled = false;
	function activeXCheckOnLoad() {
		activeXEnabled = activeXAvailable();
	}

	function activeXAvailable() {
		var browserName=navigator.appName;

		if (browserName=="Microsoft Internet Explorer") {
			try{
				//var a=new ActiveXObject("Aurigma.UploadPaneEx.5");
				var a=new ActiveXObject("Aurigma.ImageUploaderEx.5");
				return "true";
			}
			catch(e){
				return "false";
			}
		} else {
			try {
				version = getImageUploader("ImageUploader1").getVersion();
				return "true";
			} catch(e) {
				return "false";
			}
		}
		return false;	
	}


	// Receive call from Flash element
	function setUploadURL(albumID, albumName, quality,domain) {
//		alert('upload url');
//		document.textForm.albumNameTxt.value = "Currently selected album: " + albumName;
		setUploadProportions(quality);
		document.textForm.albumNameTxt.value = albumName;
		//alert(domain);
		getImageUploader("ImageUploader1").setAction(domain + 'phototellerPHP/image_utils/save_image.php?albumID=' + albumID);
    		xOnTop();

		hideElement('nextBtn');
		showElement('prevBtn');
    	}
    
    	// Call into the Flash app
    	function callFlash() {
//    		alert('calling up Flash');
    		flashOnTop();
		var callResult = PTImagine.myFunction("something from JavaScript");
    		// Reference to the embedded Flash object
    	}
    
	var l,s;
	function changeObjectVisibility(l,s){  
//		alert("obj visi");
		var browserName=navigator.appName;
//    		document.getElementById(l).style.visibility = s;
//		document.getElementById(l).style.position = "absolute";
		
		if (browserName == "Microsoft Internet Explorer") { 
			document.getElementById(l).style.position = "absolute";
			if(s == 'visible') {
				if(l == "ax") {
					placeObj("ax");
				} else {
					placeObj("flash", "false");
					//document.getElementById(l).style.top = "0px";					
				}
				placeObj("ax");
				//showElement(l);
			} else {
				document.getElementById(l).style.top = "-3000px";				
				//hideElement(l);
			}
    		} else {
			document.getElementById(l).style.visibility = s;

			if(s == 'visible') {
				if(l == "ax") {
					placeObj("ax");
				} 
			}
		}
  	}

	// Flash element on top
  	function flashOnTop() {
                currentState = 0;
		changeObjectVisibility('flash', 'visible');
		changeObjectVisibility('ax', 'hidden');
	}
   
   	// ActiveX component on top
	function xOnTop() {
//		alert("x on top");
                currentState = 1;
		changeObjectVisibility('flash', 'hidden');
 		changeObjectVisibility('ax', 'visible');
	}
	
	
	// Sets the x and y position of the component according to the screen
	function placeObj(obj, wToo) {
		//alert('HI');
		var sWidth = 0, sHeight = 0;
  		if( typeof( window.innerWidth ) == 'number' ) {
    			//Non-IE
    			sWidth = window.innerWidth;
    			sHeight = window.innerHeight;
  		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    			//IE 6+ in 'standards compliant mode'
    			sWidth = document.documentElement.clientWidth;
    			sHeight = document.documentElement.clientHeight;
  		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   			//IE 4 compatible
    			sWidth = document.body.clientWidth;
    			sHeight = document.body.clientHeight;
  		}

		var sw; 
		var sh;
		if(sWidth-1000 > 0)
			sw = (sWidth-1000)/2;
		else
			sw = 0;

		if(sHeight-669 > 0)
			sh = (sHeight-669)/2;
		else
			sh = 0;
		
//		var sw = (sWidth-1040)/2; // incl. shadow
//		var sh = (sHeight-709)/2; // incl. shadow
//alert("places x: " + sw);
//alert("places y: " + sh);
		//if(wToo != "false")
		document.getElementById(obj).style.left = sw;
		document.getElementById(obj).style.top = sh;
	}

	
	

	function checkScreenSize() {
//		alert("screen.width: " + screen.width + ", screen.height: " + screen.height);
		if(screen.width < 1000 || screen.width < 700) {
			alert("Your screen is too small for this application to be displayed correct.\n \n You are able to continue, but we strongly suggests that you update your display setting or at least press F11.");
		}
	}

	// Hide an element based on name
	function hideElement(which) {
        	var hide = new Array();
        	hide = document.getElementsByName(which);

	        for (i=0; i<hide.length; i++) {
        		hide[i].style.display = 'none';
        	}
      	}

	// Show an element based on name
      
	function showElement(which) {
        	var hide = new Array();
        	hide = document.getElementsByName(which);

	        for (i=0; i<hide.length; i++) {
        		hide[i].style.display = 'inline';
        	}
       }


	// Notify flex that an upload is in progress
	function notifyUploadCommenced() {
		uploadingNow = "true";
		var callResult = PTImagine.uploadCommence();
	}

	// Notify flex that upload is complete
	function notifyUploadComplete() {
		uploadingNow = "false";
		var callResult = PTImagine.uploadComplete();
		// If the user haven't already navigated back to the Album Manager
		if(currentState == 1)
			callFlash();
	}

	function progressHandler(Status, Progress, ValueMax, Value, StatusText) {
		if(Status == "CANCEL")
			notifyUploadComplete(); //alert("User canceled");
		
		if(Status == "ERROR")
			notifyUploadComplete(); //alert("Error: " + value);
	}


	function initPlacement() {
		document.getElementById('flash').style.position = "absolute";
		placeObj('flash');
		placeIFrame();
	}

	// Allow the user to exit the page
	function NoPrompt() {
        	allowPrompt = false;
	}



	function getPos(direction) {
		//alert('HI');
		var sWidth = 0, sHeight = 0;
  		if( typeof( window.innerWidth ) == 'number' ) {
    			//Non-IE
    			sWidth = window.innerWidth;
    			sHeight = window.innerHeight;
  		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    			//IE 6+ in 'standards compliant mode'
    			sWidth = document.documentElement.clientWidth;
    			sHeight = document.documentElement.clientHeight;
  		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   			//IE 4 compatible
    			sWidth = document.body.clientWidth;
    			sHeight = document.body.clientHeight;
  		}

		var sw; 
		var sh;
		if(sWidth-1000 > 0)
			sw = (sWidth-1000)/2;
		else
			sw = 0;

		if(sHeight-669 > 0)
			sh = (sHeight-669)/2;
		else
			sh = 0;
		
//		var sw = (sWidth-1040)/2; // incl. shadow
//		var sh = (sHeight-709)/2; // incl. shadow
//alert("places x: " + sw);
//alert("places y: " + sh);
		//if(wToo != "false")
//		document.getElementById(obj).style.left = sw;
//		document.getElementById(obj).style.top = sh;
		
		if(direction == "top") 
			return sh;
		else
			return sw;
	}

	// Iframe	
	function moveIFrame(x,y,w,h) {	
	    iframe_x = x-getPos();
	    iframe_y = y-getPos("top");
	    iframe_w = w;
	    iframe_h = h;
            var frameRef=document.getElementById("content");
	    frameRef.style.left=x;
	    frameRef.style.top=y;
	    frameRef.width=w;
	    frameRef.height=h;
	}

function test()
{
   
}

	function placeIFrame()
	{
	   if(document.getElementById("content").style.visibility=="visible")
	   {
	       var xpos = getPos()+iframe_x;
  	       var ypos = getPos("top")+iframe_y;
	       
               moveIFrame(xpos,ypos, iframe_w, iframe_h);
	   }
	}
	
	function setIFrameContent( contentSource )
	{
		document.getElementById("content").src = contentSource;
	}
	
	function hideIFrame()
	{
	    document.getElementById("content").style.visibility="hidden";
	}
	
	function showIFrame()
	{
		document.getElementById("content").style.visibility="visible";
	}	

	var frameX=0;
	var frameY=0;
	var frameW=0;
	var frameH=0;
	var onloadShow=false;

	function setIFrameContentAutoShow( contentSource,x,y,w,h )
	{
		hideIFrame();
		frameX=x;
		frameY=y;
		frameW=w;
		frameH=h;
		onloadShow=true;
		document.getElementById("content").src = contentSource;
	}

	function iframeOnload()
	{
		if(onloadShow == true)
		{
			onloadShow = false;
			showIFrame();
			moveIFrame(frameX,frameY,frameW,frameH)
		}
		
	}
	

	function showAurigmaPopup(){
		var winW = 500;
		var winH = 500;
		var winX = (screen.availWidth - winW) / 2;
		var winY = (screen.availHeight - winH) / 2;

		var features = 'left='+winX+',top='+winY+',width='+winW+',height='+winH+',toolbar=0,location=0,status=0,scrollbars=0,resizable=0';
		window.open ("AurigmaInstaller.html","aurigma",features);							
	}
	
	var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
