$(function()
{
	$("#body").hide();	
	$("#info").hide();
	$("#reel").hide();
});

window.onload = function()
{
	$("#body").show();	
	$("#info").show();
	$("#reel").show();
	parseIMG();
	$('#works a').addClass('grid');
};

function parseIMG ()
{
	var max_width=0, width=eget("works").clientWidth, i_max=eget("ntn").value;
	for (i=0; i<i_max; i++ )
	{
		eget("tn"+i).width=x[i];
		eget("tnd"+i).className="dn";
		max_width=max_width+x[i];
		if (max_width>width)
		{
			max_width=max_width-width;
			eget("tn"+i).width=x[i]-max_width;
//			eget("tni"+i).height=100;
			eget("tni"+i).width=max_width;
			eget("tnd"+i).className="tn";
			eget("tnda"+i).className="grid";
		}
	}
}

function getWindowHeight()
{ 
	var windowHeight = 0; 
	if (typeof(window.innerHeight) == 'number')
	{ 
		windowHeight = window.innerHeight; 
	}
	else
	{ 
		if (document.documentElement && document.documentElement.clientHeight) 
		{ 
			windowHeight = document.documentElement.clientHeight; 
		} 
		else
		{ 
			if (document.body && document.body.clientHeight)
			{ 
				 windowHeight = document.body.clientHeight; 
			} 
		} 
	} 
	return windowHeight; 
} 

function setHeight()
{
	var windowHeight = getWindowHeight();
	document.getElementById('info').style.height = windowHeight+'px';
	document.getElementById('reel').style.height = windowHeight+'px';
}

$(function() {setHeight();});
window.onresize = function() {setHeight();parseIMG ();}

$(document).ready(function(){
  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target 
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 500);
       return false;
      }
    }
  });
});

function tns()
{
for (i=84; i>=1; i--)
	document.write ("<div class=\'tn\' style=\'background-image: url(img/"+i+"_tn.jpg);\'><a href=\'img/"+i+".jpg\'><img src=\'img/"+i+"_tn.jpg\' alt=\'\' /></a></div>");
};

$(function()
{
	$("#menu").draggable({ revert: true, revertDuration: 2500 });
	$("#contacts").draggable({ revert: true, revertDuration: 2500 });
});

$(function() {$('#works a').lightBox();});

$(function()
{
	$("#menu_works").click(function()
	{
		$('#menu_works').addClass('active');
		$('#menu_info').removeClass('active');
		$('#menu_reel').removeClass('active');
	});
});	

$(function()
{
	$("#menu_info").click(function()
	{
		$('#menu_works').removeClass('active');
		$('#menu_info').addClass('active');
		$('#menu_reel').removeClass('active');
	});
});

$(function()
{
	$("#menu_reel").click(function()
	{
		$('#menu_works').removeClass('active');
		$('#menu_info').removeClass('active');
		$('#menu_reel').addClass('active');
	});
});

function eget(id)
{
	if (document.all)
	{
		var el = document.getElementById(id) ? document.getElementById(id) : document.all[id];
	}
	else
	{
		var el = document.getElementById(id);
	}

	if (el)
	{
		return el;
	}
	else
	{
		return null;
	}
}


function hova(i) {
	eget('tna' + i).className='tnhover';
}

function hovd(i) {
	eget('tnda' + i).className='tnhover';
}

function uhova(i) {
	eget('tna' + i).className='grid';
}

function uhovd(i) {
	eget('tnda' + i).className='grid';
}
