/**
 * @author Vlad Yakovlev (scorpix@design.ru)
 * @copyright Art.Lebedev Studio (http://www.artlebedev.ru)
 * @version 0.1 (19.11.2008)
 * @requires jQuery 1.2
 */
$(function() {
	var rootBlock = $('#lighter');

	var scroller = $('#scroller');

	var minWinSize = {
		height: 650,
		width: 970
	};

	if($.browser.opera){
		start();
	}
	else{
		$(window).load(start);
	}

	function start() {
        rootBlock.removeClass('jhidden');

		onResize();
		hideLighter();

		$(window).mousemove(setLighterPos).mouseover(setLighterPos).resize(onResize);
		// Для IE
		rootBlock.mousemove(setLighterPos).mouseover(setLighterPos);
		scroller.focus();
	}

	function onResize() {
		var scrollerSize = {
			height: scroller.height(),
			width: scroller.width()
		};

		var params = {
			left: minWinSize.width > scrollerSize.width ? -4 * minWinSize.width : '',
			top: minWinSize.height > scrollerSize.height ? -minWinSize.height : ''
		};

		if ($.browser.msie && 6 >= parseInt($.browser.version)) {
			params.height = minWinSize.height > scrollerSize.height ? 2 * minWinSize.height : '';
			params.width = minWinSize.width > scrollerSize.width ? 2 * minWinSize.width : '';
		}

		rootBlock.css(params);
	}

	function setLighterPos(event) {
		var coords = {
			x: event.pageX,
			y: event.pageY
		};

		rootBlock.css({
			marginTop: coords.y,
			marginLeft: coords.x
		});
	}

	function hideLighter() {
		rootBlock.css('margin-top', -300);
	}
});