/**
 * This file contains some functions for resizeing the image to the correct size.
 *
 */
 
 var browserWidth;
 var browserHeight;

//Capture keyBoard
document.onkeyup = keyPressed;

// Capture resize events
window.onresize = WindowResize;
 
 function WindowResize() {
 	setTimeout("WindowResized()", 1000);
 }
 
 function WindowResized() {
 	if(IsWindowResized()) {
 		// The window has been resized, so now let's send the Ajax-call
 		UpdateSizeImage();
 	}
 }
 
 function UpdateSizeImage() {
 	//Ajax call to update the size of the image
 	qc.pA('kbrImage', 'pxyResize', 'QClickEvent', browserWidth+'i'+browserHeight, 'c1');
 }
 
 /**
  * This fnction returns true if the width or height of the window is changed
  */
 function IsWindowResized() {
 	if( typeof( window.innerWidth ) == 'number' ) {
    		//Non-IE
		newBrowserWidth = window.innerWidth;
    		newBrowserHeight = window.innerHeight;
  	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    		//IE 6+ in 'standards compliant mode'
    		newBrowserWidth = document.documentElement.clientWidth;
    		newBrowserHeight = document.documentElement.clientHeight - 55;
  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    		//IE 4 compatible
    		newBrowserWidth = document.body.clientWidth;
    		newBrowserHeight = document.body.clientHeight;
  	}
 	
 	if(!(browserWidth == newBrowserWidth)) {
 		browserWidth = newBrowserWidth;
 		browserHeight = newBrowserHeight;
 		return true;
 	} else if(!(browserHeight == newBrowserHeight)) {
 		browserWidth = newBrowserWidth;
 		browserHeight = newBrowserHeight;
 		return true;
 	} else {
 		return false;
 	}
 }
 
 /**
  * Method called when a key is pressed
  *
  */
 function keyPressed(e) {
 	var evt = e || window.event;

	// Left
	if(evt.keyCode == 37) {
		qc.pA('kbrImage', 'btnLeft', 'QClickEvent', 'left', 'c1');
	// Right
	} else if(evt.keyCode == 39) {
		qc.pA('kbrImage', 'btnRight', 'QClickEvent', 'right', 'c1');
	// Up
	} else if(evt.keyCode == 38) {
		qc.pA('kbrImage', 'btnUp', 'QClickEvent', 'up', 'c1');
	// Down
	} else if(evt.keyCode == 40) {
		qc.pA('kbrImage', 'btnDown', 'QClickEvent', 'down', 'c1');
	}
	
	return false;
 }