var width = 800;
var height = 600;
var img_width = 470;
var img_height = 535;
var resizeTimer = null;
var ajax_content = null;

function getWidth() {
    width = $('#logo').width();
    height = $('#logo').height();
};

function moveLogo(where, url){
	var prop;
	def_where = where;
	wh = getWhere(where);
	prop = {"backgroundPosition": '('+wh[0]+'px '+wh[1]+'px)'};
	if(url==null){
		$('#logo').animate(prop,500);//,'',move1);
	} else {
		getContent(url);
		$('#logo').animate(prop,500,'',showContent);
	}
}

function resizing(){
	getWidth();
	moveLogo(def_where);
	if($('#move').is('*')){
		if(width>1200){
			$('#move').removeClass('move');
		} else {
			$('#move').addClass('move');
		}
	}
}

function getWhere(where){
	switch(where){
		case 'left':
			x = 0 - img_width/2;
			y = height/2 - img_height/2;
			break;
		case 'right':
			x = width - img_width/2;
			y = height/2 - img_height/2;
			break;
		case 'top':
			x = width/2 - img_width/2;
			y = 0 - img_height/2;
			break;
		case 'top_up':
			x = width/2 - img_width/2;
			y = 0 - img_height/2 - img_height;
			break;
		case 'bottom':
			x = width/2 - img_width/2;
			y = height - img_height/2;
			break;
		default:
			x = width/2 - img_width/2;
			y = height/2 - img_height/2;
			break;
	}
	return [Math.ceil(x),Math.ceil(y)];
}

$(document).ready(function(){
	$(window).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(resizing, 100);
	}); 
	getWidth();
	wh = getWhere(def_where);
	$('#logo').css({backgroundPosition: ''+wh[0]+'px '+wh[1]+'px'});
	moveLogo(def_where, null);
	
	$('#menu_about').click(function(){
		moveLogo('right', $(this).attr('href'));
		return false;
	});	
	$('#menu_archive').click(function(){
		moveLogo('left', $(this).attr('href'));
		return false;
	});	
	$('#menu_partners').click(function(){
		moveLogo('top', $(this).attr('href'));
		return false;
	});	
	$('#menu_contacts').click(function(){
		moveLogo('bottom', $(this).attr('href'));
		return false;
	});
	$('#menu_photographers').click(function(){
		moveLogo('top_up', $(this).attr('href'));
		return false;
	});
});


function getContent(url){
	$('#loading').show();
	$('#center').slideUp('fast',function(){
									   
		$('#center').html('');
		//$('#center').load(url, '', function(){
		//$.post('http://photoroom.qwe.lv'+url+"?random=" + Math.random()*99999, {rnd: Math.random()*99999 }, refreshContent);
		$.ajax({
			url: url,
			cache: false,
			success: refreshContent
		});

		//refreshContent('test');
									   
	});

}
function refreshContent(data){
			//alert(data);
			$('#center').html(data);
			$('#loading').hide();
			$('#center').slideDown();
			if($('#move').is('*')){
				if(width>1200){
					$('#move').removeClass('move');
				}
			}
		}
function showContent(){
	//alert(ajax_content);
}
