function SetNavigationDefaults(element, image) {
	if(element.attr('org-left') == undefined) 
		element.attr('org-left', element.css("left"));
	if(element.attr('org-top') == undefined) 
		element.attr('org-top', element.css("top"));
	if(image.attr('org-size') == undefined) 
		image.attr('org-size', image.width());
	if(image.attr('org-src') == undefined) 
		image.attr('org-src', image.attr('src'));
}

function getResStyle(width, height) {
    width = parseInt(width);
    height = parseInt(height);
    if (height > 900) {
    	return "/css/res1280.css";
    } else {
    	return "/css/res1024.css";
    }
}

function getResScrollHeight(width, height) {
    width = parseInt(width);
    height = parseInt(height);
    if (height > 900) {
    	return 410;
    } else {
    	return 350;
    }
}

$(document).ready(function(){
	$('#content').tinyscrollbar({'sizethumb': '20', 'size': 'auto'});
	$('#topLayer').hide();
    $('#preloader').fadeOut('fast', function() { $(this).remove(); });
	

    $('#openTopLayer').click(function() {
    	$('#topLayer').fadeIn(1000);
    });
    $('#closeTopLayer').click(function() {
    	$('#topLayer').fadeOut(1000);
    });
    
	$('.content_anchor').click(function(){
		var ref = $('#'+ $(this).stop().attr('goto'));
		$('#content').tinyscrollbar_update(ref.position().top);
		return false;
	});
	$('.content_totop').click(function(){
		$('#content').tinyscrollbar_update(0);
	});
	
	
	$('#navigation li').mouseover(function() {
		listel = $(this).stop();
		image = listel.find('img');
		SetNavigationDefaults(listel, image);
		
		image.attr('src', image.attr('data-hover'));
		image.css({
			width: image.attr('org-size'),
			height: image.attr('org-size')});
		listel.css({
			top: listel.attr('org-top'),
			left: listel.attr('org-left')});
		
		var wdiff = (image.attr('org-size')-image.attr('hover-size'))/2;
		var hdiff = (image.attr('org-size')-image.attr('hover-size'))/2;
		var top = image.css('top');
		var left = image.css('left');
		$(function () {
		    image.animate({
				width: image.attr('hover-size'),
				height: image.attr('hover-size'),
		    }, { duration: 150, queue: false });
		    listel.animate({
				left: '+='+wdiff,
				top: '+='+hdiff
		    }, { duration: 150, queue: false });
		});
	}).mouseout( function() {
		listel = $(this).stop();
		image = listel.find('img');
		$(function () {
		    image.animate({
				width: image.attr('org-size'),
				height: image.attr('org-size'),
		    }, { duration: 150, queue: false });
		    listel.animate({
				left: listel.attr('org-left'),
				top: listel.attr('org-top')
		    }, { duration: 150, queue: false });
		});
		image.attr('src', image.attr('org-src'));

	});
});

