$(document).ready(function() {
	
	$("#accordion").accordion({ header: '.tab', autoHeight:false});


	 
	$('.tab').click(function(){
		if($(this).attr('rel')=='index' && $('#index-block-div').is(':visible'))
			self.document.location.href = '/';

		 if($(this).attr('rel')!='index') {
			$('#index-block-div').hide();

			self.document.location.href = $(this).attr('href');
		 } else
			self.document.location.href = '#';

	});
  	

	$('#accordion').bind('accordionchange', function(event, ui) {
		if(ui.newHeader.attr('rel')) {
			if(ui.newHeader.attr('rel')=='index') {
				$('#index-block-div').fadeIn(1000);
			} 		
		} else
			$('#index-block-div').hide();

		ui.newHeader.parent().addClass('on');
		ui.oldHeader.parent().removeClass('on');	
	});
	
	$('.bubbles').fadeIn(1000);


	var current_page = self.document.location.hash;

	if(current_page)
		$('a[href$='+current_page.replace(/#/, '')+']').queue(function() {$(this).trigger('click') });

	$('.print-link').click(function() {
		window.print();
		return false;
	});


	$('.image-link').lightBox();


	$('#bank-details-link').click(function(){
		if($('#bank-details').is(':visible')) {
			$('#bank-details').slideUp();
		} else {
			$('#bank-details').css({opacity: 0.9});
			$('#bank-details').slideDown();
		}
		return false;
	});


	$('#example-arrow-prev').click(function(){
		if(!$(this).hasClass('off')) {
			$('#example-block').css({opacity: 0.1});
			var order = $('#example-block').attr('rel');
			$.get('/ajax/example/', {ord: order, dir: 'prev'}, $.update_example, 'json');
		}
		return false;
	});

	$('#example-arrow-next').click(function(){
		if(!$(this).hasClass('off')) {
			$('#example-block').css({opacity: 0.1});
			var order = $('#example-block').attr('rel');
			$.get('/ajax/example/', {ord: order, dir: 'next'}, $.update_example, 'json');
		}
		return false;
	});

	$.update_example = function(data) {
		if(data.result) {					
			$('#example-content').find('h2:first').html(data.content.name);
			$('#example-content').find('div:last').html(data.content.txt);							
			$('#example-block').attr('rel', data.content.rel);			
			$('#example-block').css({'background-image': 'url(' + (data.content.img ? data.content.img : '/files/images/empty.gif') + ')'});			

			if(data.next) {
				$('#example-arrow-next').removeClass('off');
				$('#example-arrow-next').find('img:first').attr('src', '/files/images/arrow_next.gif');
			} else {
				$('#example-arrow-next').addClass('off');
				$('#example-arrow-next').find('img:first').attr('src', '/files/images/arrow_next_off.gif');
			}		

			if(data.prev) {
				$('#example-arrow-prev').removeClass('off');
				$('#example-arrow-prev').find('img:first').attr('src', '/files/images/arrow_prev.gif');
			} else {
				$('#example-arrow-prev').addClass('off');
				$('#example-arrow-prev').find('img:first').attr('src', '/files/images/arrow_prev_off.gif');
			}					
		}
		$('#example-block').animate({opacity: 1});
	}
	
});

