/******************************************************************************************************************/
// GENERAL FX
/******************************************************************************************************************/

function handleFX(){	
	$('#sostienici').hover(function(){
		$(this).stop().animate({ marginLeft: '735px' }, 300);
	}, function(){
		$(this).stop().animate({ marginLeft: '730px' }, 300);
	});
	
	$('#menu .left a').hover(function(){
		$(this).stop().animate({ paddingRight: '5px' }, 200);
	}, function(){
		$(this).stop().animate({ paddingRight: '0px' }, 200);
	});
	
	$('#menu .right a').hover(function(){
		$(this).stop().animate({ paddingLeft: '5px' }, 200);
	}, function(){
		$(this).stop().animate({ paddingLeft: '0px' }, 200);
	});
}

/******************************************************************************************************************/
// TABS HANDLE
/******************************************************************************************************************/

function handleTabs(){
	$('.tabs .tab').hide();
	
	$('.tabs .sel').each(function(){
		initid = $(this).find('a').attr('href');
		mm = initid.match(/#.*/);
		$(mm[0]).show();
	});
	
	$('.tabs .labels a').click(function(){
		$(this).parents('.labels').find('li').removeClass('sel');
		$(this).parent().addClass('sel');
		
		myid = $(this).attr('href');
		mm = myid.match(/#.*/);
		
		$(this).parents('.tabs').find('.tab').hide();
		$(mm[0]).show();
		
		return false;
	});
}

/******************************************************************************************************************/
// MODAL BOXES
/******************************************************************************************************************/

function adjustModal(){
	fh = $('#modal-frame').height();
	wh = $(window).height();
	dh = $(document).height();
		
	if (wh > dh) mt = (wh - fh) / 2;
	else {
		mt = 50;
		$('#modal-box').height(dh);
	}
		
	$('#modal-frame').css({ marginTop: mt });
}

function handleModal(){
	$('.modal').click(function(){
		$('body').append('<div id="modal-box"><div id="modal-frame"><div id="modal-close">X</div><div id="modal-content"></div></div></div>');
		
		adjustModal();
			
		$('#modal-box').fadeIn(500);
		
		$('#modal-close').click(function(){
			$('#modal-box').fadeOut(300, function(){ $(this).remove(); });
		});
		
		// ajax loading
		mylink = $(this).attr('href');
		
		jQuery.ajax({
			url: mylink,
			success: function(html){
				mycont = $(html).find('.frame').html();
				
				$('#modal-content').html(mycont);
				
				// tabs
				handleTabs();
				
				//fancybox
				$('.fancybox').fancybox({
					'overlayShow': true,
					'frameWidth': 450,
					'frameHeight': 400
				});
			}
		});
		
		return false;
	});
}

/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	// general fx
	handleFX();
	
	// modal boxes
	handleModal();
});
