// JavaScript Document
var imgFrame = null; // object
var winH = 0;
var winW = 0;
var imHeightCoeff = 0;
var imWidhtCoeff = 0;
var topCoordCoeff = 0;
var leftCoordCoeff = 0;
var i = 0;
var imHeight = 0;
var imWidht = 0;
var topCoord = 0;
var leftCoord = 0;
var cursorScrX = 0;
var cursorScrY = 0;
var cursorWinY = 0;
var clickState = false;
var closebutHeigth = 0;


function getcursorScrXY(event) {
	cursorScrX = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	cursorScrY = event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	cursorWinY = event.clientY;
	
	if (cursorScrX < 0){cursorScrX = 0;}
	if (cursorScrY < 0){cursorScrY = 0;}
	/*document.getElementById('ValueCursorScrX').value = cursorScrX;
	document.getElementById('ValueCursorScrY').value = cursorScrY;*/
}


/*---DATA INITIALIZATION FOR OPEN IMAGE FUNCTION---*/
function openImage(imageUrl) {
	getWindowSize();
	showShadeLayer();
	imgFrame = document.getElementById('imageFrame'); // get the "imageFrame" object
	document.getElementById('curentImage').style.backgroundImage = imageUrl;// getind image URL from an icon
	imHeightCoeff = 500/100;
	imWidhtCoeff = 600/100;
	topCoordCoeff = ( ((cursorScrY - cursorWinY) + winH/2 - 500/2) - cursorScrY ) / 100;//geting coefficient for the top patametr
    //stopCoordCoeff = ((winH/2 - 500/2)-cursorScrY)  / 100;//geting coefficient for the top patametr
	leftCoordCoeff = ((winW/2 - 600/2)-cursorScrX) / 100;//geting coefficient for the left patametr
	topCoord = cursorScrY;
	leftCoord = cursorScrX;
	doMove();//running of fuction with muves the inmage
}

/*---FUNCTION WICH OPENS THE IMAGE---*/
function doMove() {
  imgFrame.style.height = imHeight + 'px';
  imgFrame.style.width = imWidht + 'px';
  imgFrame.style.top = topCoord + 'px';
  imgFrame.style.left = leftCoord + 'px';
  if(i < 100){
    imHeight = imHeight + imHeightCoeff;
  	imWidht = imWidht + imWidhtCoeff;
	topCoord = topCoord + topCoordCoeff;
	leftCoord = leftCoord + leftCoordCoeff;	
	i = i+1;
  	setTimeout(doMove,1); // call doMove in 1msec
  }else showCloseBut();
}


/*---FUNCTION WICH CLOSES THE IMAGE---*/
function hideImage() {
  imgFrame.style.height = imHeight + 'px';
  imgFrame.style.width = imWidht + 'px';
  imgFrame.style.top = topCoord + 'px';
  imgFrame.style.left = leftCoord + 'px';
  if(i > 0){
    imHeight = imHeight - imHeightCoeff*2;
  	imWidht = imWidht - imWidhtCoeff*2;
	topCoord = topCoord - topCoordCoeff*2;
	leftCoord = leftCoord - leftCoordCoeff*2;	
	i = i-2;
  	setTimeout(hideImage,1); // call doMove in 20msec
  } else hideShadeLayer();
  		
}


/*---SHOWING OF THE CLOSEBUTTON---*/
function showCloseBut(){
	closeBut = document.getElementById('closeButton');
	closeBut.style.height = closebutHeigth + 'px';
	if(closebutHeigth < 30){
		closebutHeigth = closebutHeigth +1;
  		setTimeout(showCloseBut,1); // call doMove in 1msec
	}
}


/*---HIDING OF THE CLOSEBUTTON---*/
function hideCloseBut(){
	closeBut = document.getElementById('closeButton');
	closeBut.style.height = closebutHeigth + 'px';
	if(closebutHeigth > 0){
		closebutHeigth = closebutHeigth -1;
  		setTimeout(hideCloseBut,1); // call hideCloseBut in 1msec
  	}else hideImage();//after closebuton is hided it runs function wich closes the image
}


function getWindowSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    winW = window.innerWidth;
    winH = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    winW = document.documentElement.clientWidth;
    winH = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    winW = document.body.clientWidth;
    winH = document.body.clientHeight;
  }
}


function showShadeLayer(){
	var shadeLay = document.getElementById('shadeLayer');
	shadeLay.style.width = winW - 20 + 'px';
	//shadeLay.style.height = winH + 'px';
	shadeLay.style.height = document.body.scrollHeight + 'px';//gets boby height
}


function hideShadeLayer(){
	var shadeLay = document.getElementById('shadeLayer');
	shadeLay.style.height = '0px';
	shadeLay.style.width = '0px';
}

///////////////////////////////*---FEEDBACK FUNCTIONS---*/////////////////////////////////////////////////
var feedbackFormsCode = "<h3>Your feedback is very importent for us!</h3><form action='http://applet3d.com/js/mail.php' method='POST'><b>Your name: </b> <input type='text' name='name'> is not required<br /><br />		<b>Your e-mail: </b> <input type='text' name='email'> is not required<br/><br /> <b>Message:</b><br><textarea name='message' cols='38' rows='6'></textarea>	<br /> <br /> <input type='submit' onclick='getCurrentUrl()' value='Send'>&nbsp;&nbsp;&nbsp;<input name='Button' type='button' value='Close' onclick = 'hideFeedBackForm()'> <input type='hidden' id = 'urlcontainer' value='url text' name='curentURL'/></form>";

function showFeedBackForm(){
	var feedFrame = document.getElementById("feedbackFrame");
	getWindowSize();
	feedFrame.style.left = winW/2 + 36 + 'px';
	feedFrame.innerHTML = feedbackFormsCode;
	feedFrame.style.visibility = "visible";
}

function hideFeedBackForm(){
	document.getElementById("feedbackFrame").style.visibility = "hidden";
}

function getCurrentUrl(){
	document.getElementById('urlcontainer').value = document.location;
}

