function resizeFooterPosition() {
	if (typeof document.body.style.maxHeight == "undefined") {
		winH = $('#ie7').height();
		$('#extraFooter').css('position', 'absolute').css('top', winH +'px');
		//alert(winH);
	}
}

function refreshlinkclasses(url) {
	$('div.navigation p.pagination a').removeClass('active');
	$('div.navigation p.pagination a[href=' +url +']').addClass('active');

	var prevUrl = $('div.navigation a.active').prev('a').attr('href');
	
    if (prevUrl == undefined) {
        prevUrl = url;
    }
    
	var nextUrl = $('div.navigation a.active').next('a').attr('href');
	
	if (nextUrl == undefined) {
	   nextUrl = url;
	}
	
	$('div.images li.prev a').attr("href", prevUrl);
	$('div.images li.last a').attr("href", nextUrl);
}

$(document).ready(function() {
	$('.picture').innerfade({ 
		speed: 'fast', 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '175px' 
	}); 
    $.i18n.setDictionary(i18nDictionary);

	$('#bas-container').tabs({
		onShow: function() {
			sidebar();
    	}
	}).triggerTab($.i18n._('tab basic information')).ready(
			function() {
				sidebar();
			}
	);	
	if ( $.browser.msie ) {
		$('a#trigger-interior').bind('click', function() {
			var interiorId = $.i18n._('tab interior');
			$("ul.menu li a[@href=" +interiorId +"]").trigger("click");
		});
		$('body#request-building-view a#trigger-images').bind('click', function() {
			$('#bas-container').triggerTab(3);
		});
		$('body#request-apartment-view a#trigger-images').bind('click', function() {
			$('#bas-container').triggerTab(2);
		});
	}
	$('div.gallery').hide();
	
	$('div.figures a').bind('click', function() {
		$('div.gallery').show();
		$('#bas-images').hide();
		$('div.figures').addClass('gallery');
		var url = $(this).attr('href');
		$('#bas-picture').load(this.href, function() {
			refreshlinkclasses(url);
			resizeFooterPosition();
		});
		$(this).addClass('active');
		return false;
	}).removeClass('active');
	
	
	$('div.gallery a').click(function() {
		$('#bas-picture').load(this.href);
		var url = $(this).attr('href');
		if ((url.search('/null') <= -1)) {
			refreshlinkclasses(url);
		}
	});	


	
	$('div.sidebar div.pictures a').click(function() {
		$('div.gallery').hide();
		$('#bas-images, div.figures.gallery').show();
	});
	$('li.displayall a').unbind("click");
	$('li.displayall a').click(function() {
		$('div.gallery').hide();
		$('#bas-images, div.figures.gallery').show();
		$('#bas-picture > p.picture').html('');
	});
	
});

function sidebar(tab) {
	if (tab == undefined) {
		var section = $('ul.tabs-nav li.active a').attr('href');
	} else {
		var section = $(tab).attr('href');		
	}
	if (section == $.i18n._('tab contact information') || section == $.i18n._('tab interior')) {
		$('div.sidebar:visible').hide();
	} else {
		$('div.sidebar:hidden').show();			
	}
	if (section == $.i18n._('tab pictures')) {
		$('div.sidebar div.pictures:visible').hide();
	} else {
		$('div.sidebar div.pictures:hidden').show();			
	}
	if (section == $.i18n._('tab map')) {
		//alert('map');
		load()
	}
	resizeFooterPosition();
}

