var ajaxprepared = false;
var cachecount = 1;

var leftbar = 170; 
var mainbar = 870;



//onKey Events
var Netscape = new Boolean();
if (navigator.appName == "Netscape")  Netscape = true;

function processKey(key)
{
	if (key == 37)
	{
		linkprev();		
	}
	/*
	else if (key == 38)
	{
		linkup();		
	}
	*/
	else if (key == 39)
	{		
		linknext();		
	}

}

function keyPressed(keyEvent)
{
	if (Netscape) { processKey(keyEvent.which); return true; }
}

function linkprev(){	
		if(ajaxprepared) goleft();
		else if(document.getElementById('prevlink'))
			location.href = document.getElementById('prevlink').href;
}
function linknext(){	
		if(ajaxprepared) goright();
		else if(document.getElementById('nextlink'))
			location.href = document.getElementById('nextlink').href;
}
function linkup(templink){	
	if(document.getElementById('overviewlink')){
		var pagelink = "";
		if(galleryInfo.galleryIndex){
			var page = Math.floor((galleryInfo.galleryIndex)/itemsperpage)+1;
			pagelink = "&page="+page;
		}
	location.href = "gallery.jsp?"+galleryParamString+pagelink;
	}
}

document.onkeydown = keyPressed;
//onKey Events end
			
			
			
			
			
			
			
			
//ajax
function getLucky()
	{ 
	refreshInclude("index_lucky_shots.jsp?include_temp_id="+cachecount, 'luckyshots'); 
	cachecount ++;
} 


// The following function submits the data from the 'input' form
//
// NOTE: As with xhrGet, you can also use handleAs to accept
// JSON objects in your load() function.
function submitForm() {
	dojo.xhrPost ({
        // The page that parses the POST request
        url: '/Scoreboard/json/',
        // Name of the Form we want to submit
		form: 'input',		
      	handleAs: 'json', // IMPORTANT: tells Dojo to automatically parse the HTTP response into a JSON object

        // Loads this function if everything went ok
        load: function (data) {
                // Put the data into the appropriate <div>
                //dojo.byId('response').innerHTML = data;
    			console.debug('Success: Formular gesendet - positives Feedback!');
				processData(data);
        },
        // Call this function if an error happened
        error: function (error) {
                console.error ('Error: ', error);
				processData('false');
        }
	});
}
// Function that retrieves a JSON object and puts the information
// into the <div> with an id of 'json-content'. Notice how we're defining
// 'handleAs' to be of type 'json' now. That lets Dojo know that the data being
// retrieved from the URL should be eval()-ed and converted to a javascript object.
function refreshInclude (geturl, datadiv){
    dojo.xhrGet ({
        url: geturl,
        handleAs: 'text', 
        load: function (data) {
			if(data!=undefined && data.length>0 && dojo.byId(datadiv)) dojo.byId(datadiv).innerHTML = data;
            console.debug('Success: Include refreshed.');
        },
        error: function (error) {
            console.error('Error: ', error);
        }
    });
}







// onload, on resize Div rezising
function getClientWidth() {
  	 if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	 }
	}
	return winW;
}

//width px

function resizeDivs(){	
	windowwidth = getClientWidth();	
	newleftbarwidth = Math.round((windowwidth*1-leftbar*1-mainbar*1)/2+leftbar*1);
	
	console.debug('newleftbarwidth='+newleftbarwidth);
	if(newleftbarwidth<170) newleftbarwidth = 170;
	
	document.getElementById('leftbar').style.width = newleftbarwidth + "px";
	document.getElementById('mainbar').style.left = newleftbarwidth + "px";
}

