/**
 * @author wes
 */
$(document).ready(function(){
		
		$('body').css("min-height",$(window).height()-35);
		//it is possible that there is no activeNav set
		if($('#nav .activeNav a img').length > 0) {
			var naSrc = $("#nav .activeNav a img").attr("src").replace("default.gif","active.gif");
			$("#nav .activeNav a img").attr("src",naSrc);
		}
		//Navigation control
		$('#nav ul').hover(function(event) {
			$("ul:visible","#subNav").clearQueue();
		},readyToHide);
			
		//Main Nav mouse interaction
		$('#nav a').bind("mouseover", function() { 
			
			$("ul:visible","#subNav").clearQueue();	
			var href = this.href;
			var id = href.substr(href.indexOf('?')+1);
			
			$("ul:not(#"+id+")","#subNav").hide();
			$("#"+id+":hidden").show();
		});

		$("img#slideShowBtn").hover( function(){
			$(this).attr( "src", $(this).attr("src").split('default').join('over') )}, 
			function(){
				$(this).attr( "src", $(this).attr("src").split('over').join('default') )
		 });
		 
		 //if russian, make text larger
		if($('.backgroundNav').text() == "История Дома Мельникова") {
			$('body p').css('font-size','115%');
			$('#caption').css('font-size','90%');
		}
		
		//image rollver on main nav
		$("#nav li:not(.activeNav) a img").hover(function(){
				if($(this).attr("src").indexOf("over") == -1) {
					var newSrc = $(this).attr("src").replace("default.gif","over.gif");
					$(this).attr("src",newSrc);
				}
			},
			function(){
				if($(this).attr("src").indexOf("over.gif") != -1) {
					var oldSrc = $(this).attr("src").replace("over.gif","default.gif");
					$(this).attr("src",oldSrc);
				}
			}
		);
		
		
		
		//work toggle
		$('div.yearItem .yr').bind("click", function() { 
			//alert($(this).parent('frm'));
			$(this).parent().children('.frm').slideToggle("fast");
		});
		
		
		
		prepGallery();
});


//
//Controls when navigation will hide
//
function readyToHide(e) {
	$("ul:visible","#subNav").pause(600).hide(30,function() {
		$("#subNav .active").show();
	});
}

function newImage(siteRoot) {
	var i = Math.round(10000*Math.random());
	$('#editImageGallery').append('<div class="uploadImage hidden" id="newImage'+i+'"><hr />' +
			'<div class="col1">' +
			'<input type="hidden" name="ids[]" value="new" />' +
			'Thumb: <input type="file" name="galleryThumb[]" /><br />'+
			'Medium: <input type="file" name="galleryMed[]" /><br />'+
			'Large: <input type="file" name="galleryLarge[]" /><br />'+
			'<a href="#" onclick="deleteGalleryImage('+i+'); return false;">Delete?</a>' +
			'</div>' +
			'<div class="col2">'+
			'En Description: '+
			'<textarea rows="5" cols="30" name="enDescr[]"></textarea>'+
			'<br />'+
			'Ru Description:'+
			'<textarea rows="5" cols="30" name="ruDescr[]"></textarea>'+
			'</div>'+
			'<br clear="all" /></div>');
		$('#editImageGallery > .hidden').fadeIn();
	
}

//for ajax call from flash movie
function loadHouseDetail(lang,id) {
	highLightThumb(id);
	
	$('#newsRightContent span').css('background','#ffffff');
	
	$('#newsLeftContent').css("min-height",$('#newsLeftContent').height());
	//$('#newsLeftContent span').animate({opacity:'hide'},"fast",function() {
		$.get('functions/gethousegallery.php', {'lang':lang,'id':id}, function(data){
			$('#newsLeftContent span').html(data).animate({opacity: 'show'},"fast",function(){
				prepGallery();
				
				$('#newsLeftContent').css("min-height",$('#newsLeftContent').height());
			});
		});
	//});
	
	$('#newsRightContent span').css("min-height",$('#newsRightContent span').height());
	    $.get('functions/gethousedetail.php', {'lang':lang,'id':id}, function(data){
			$('#newsRightContent span').html(data).animate({opacity: 'show'},"fast",function(){
				//$('#newsRightContent').css("min-height",$('#bodyWrapper').height());
			});
		});
}

//loads melnikov work info
function loadWorkYear(id,lang){
	
	
	
	$('#newsRightContent span').css('background','#ffffff');

	$('#newsLeftContent').css("min-height",$('#newsLeftContent').height());
	//$('#newsLeftContent span').animate({opacity:'hide'},"fast",function() {
		
		$.get('functions/getyeargallery.php', {'lang':lang,'id':id}, function(data){
			$('#newsLeftContent span').html(data).fadeIn(400,function() {
				prepGallery();
			});
		});
	//});
	
	$('#newsRightContent span').css("min-height",$('#newsRightContent span').height());
		$.get('functions/getworkdetail.php', {'lang':lang,'id':id}, function(data){
			$('#newsRightContent span').html(data).animate({opacity: 'show'},"fast",function(){
				//$('#newsRightContent').css("min-height",$('#bodyWrapper').height());
			});
		});
		
	highLightDecade(id);
}

//loads publication info
function loadPubYear(id,lang){
	
	$('#newsRightContent span').css('background','#ffffff');
	
	$('#newsLeftContent').css("min-height",$('#newsLeftContent').height());	
		
		$.get('functions/getpubyeargallery.php', {'lang':lang,'id':id}, function(data){
			$('#newsLeftContent span').html(data).fadeIn(400,function() {
				prepGallery();
			});
				
		});
	
	$('#newsRightContent span').css("min-height",$('#newsRightContent span').height());
		$.get('functions/getpubdetail.php', {'lang':lang,'id':id}, function(data){
			$('#newsRightContent span').html(data).animate({opacity: 'show'},"fast",function(){
					
			});
		});
		
	highLightDecade(id);
}
