current_visible = "";
function hideDiv() {
	if ( current_visible.length >= 0) {
		var div = document.getElementById( current_visible);
		if ( div) {
			div.style.display = "none";
		}
	}
}

function closeDiv() {
	var timeOut = window.setTimeout( "hideDiv()", 350);
}

function showDiv( current_name, event) {
	hideDiv();
	var div = document.getElementById( current_name);

	if ( div && div.style.display == "none") {
		current_visible = current_name;
		div.style.display = "block";
	}
	var wwidth = (window.innerWidth)?window.innerWidth: ((document.all)?document.body.offsetWidth:null);
	if (!event) event=window.event;
	x = (event.clientX) ?  event.clientX : ((event.pageX) ? event.pageX : event.screenX);
	y = (event.clientY) ? (event.clientY + 15) : (event.pageY + 15);
	if ( document.documentElement.scrollTop == 0) {
		y += document.body.scrollTop;
	} else {
		y += document.documentElement.scrollTop;
	}

	if ( x + 300 >= wwidth) {
		x -= 280;
	}
	div.style.top = y+"px";
	div.style.left = x+"px";
}

move = 0;
delta = 0;
timeOutVar = null;
function moveDiv( direct ) {
	allWidth = (document.body.scrollWidth) ? document.body.scrollWidth : document.documentElement.scrollWidth;
	if ( direct == "left") {
		if ( Math.abs( parseInt( $( "#big_top").style.left)) < ($( "#big_top").clientWidth - allWidth)) {
			newX = parseInt( $( "#big_top").style.left) - delta;
			$( "#big_top").style.left = newX + "px";
             current_position_array = $( "#big_top_abs").style.backgroundPosition.split( " ");
             $( "#big_top_abs").style.backgroundPosition = (parseInt( current_position_array[0]) + delta) + "px 0px";
			move = 1;
			timeOutVar = window.setTimeout( "moveDiv( \"" + direct + "\")", 50);
		} else {
			clearTimeout( timeOutVar);
			move = 0;
		}
	} else if ( direct == "right") {
		if ( parseInt( $( "#big_top").style.left) < 0) {
			newX = parseInt( $( "#big_top").style.left) + delta;
			$( "#big_top").style.left = newX + "px";
			timeOutVar = window.setTimeout( "moveDiv( \"" + direct + "\")", 50);
             current_position_array = $( "#big_top_abs").style.backgroundPosition.split( " ");
             $( "#big_top_abs").style.backgroundPosition = (parseInt( current_position_array[0]) - delta) + "px 0px";
			move = 1;
		} else {
			clearTimeout( timeOutVar);
			move = 0;
		}
	}
}

function testFunc( event) {
//     alert( "here!");
}

function getMouse( event) {
	if ( !event) {
		event = window.event;
	}
	windowWidth = (window.innerWidth) ? window.innerWidth : ((document.all)? document.body.offsetWidth : null);
	x_coord = (event.clientX) ?  event.clientX : ((event.pageX) ? event.pageX : event.screenX);
    y_coord = (event.clientY) ?  event.clientY : ((event.pageY) ? event.pageY : event.screenY);
    if ( y_coord > 160 && y_coord < 420) {
		showElementInCursor( $( "#descr_popup_" + getPopupNum( x_coord)), event);
		window.status = g_href_array["descr_popup_" + getPopupNum( x_coord)];
    } else {
    	hideElementInCursor();
    }
	if ( x_coord >= windowWidth * 0.6) {
		if ( move != 0) {
			clearTimeout( timeOutVar);
			move = 0;
		}
		delta =  Math.round( ((x_coord - windowWidth * 0.6) / windowWidth * 0.4) * 100);
 		moveDiv( "left");
	} else if ( x_coord <= windowWidth * 0.4) {
		if ( move != 0) {
			clearTimeout( timeOutVar);
			move = 0;
		}
		delta = Math.round( (Math.abs(x_coord - windowWidth * 0.4) / windowWidth * 0.4) * 100);
 		moveDiv( "right");
	} else {
		clearTimeout( timeOutVar);
		move = 0;
	}
}

function getPopupNum( current_x ) {
    current_num = Math.floor(( ( Math.abs( parseInt( $( "#big_top").style.left)) + current_x ) / $( "#big_top").offsetWidth) * 4);
    current_num = current_num > 7 ? 7 : current_num;
     return current_num;
}

function setHref( event) {
	if ( !event) {
		event = window.event;
	}
	windowWidth = (window.innerWidth) ? window.innerWidth : ((document.all)? document.body.offsetWidth : null);
	x_coord = (event.clientX) ?  event.clientX : ((event.pageX) ? event.pageX : event.screenX);
    y_coord = (event.clientY) ?  event.clientY : ((event.pageY) ? event.pageY : event.screenY);

    location.href = g_href_array["descr_popup_" + getPopupNum( x_coord)];

}

function stop() {
	clearTimeout( timeOutVar);
	move = 0;
	hideElementInCursor();
}
