$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

$(document).ready(function() {
	$(['/images/despre_noi_h.png','/images/referinte_h.png','/images/servicii_h.png','/images/echipamente_h.png']).preload();
	
	
	$('.dynamic_link').each(function(i,e) { 
		$(this).unbind('click').bind('click', function() {
			var link = '';
			var container = '#lower_holder';
			
			if ($(this).is("a"))
				link = $(this).attr('href');
			else 
				link = $(this).attr('rel');
			
			link = 'ajax/' + link;
			
			//alert(link);
			
			$(container).slideUp('fast',function() {
				$(container).load(link,function() {
					$(container).slideDown('fast',function(){
					$(container + ' .dynamic_link').each(function(i,e) { 
							$(this).unbind('click').bind('click', function() {
								var link = '';
								var container = '#lower_holder';
								
								if ($(this).is("a"))
									link = $(this).attr('href');
								else 
									link = $(this).attr('rel');
								
								link = 'ajax/' + link;
								
								//alert(link);
								
								$(container).slideUp('fast',function() {
									$(container).load(link,function() {
										$(container).slideDown('fast',function(){
											var h = 900 + $(container).height() + $('#telephone').height()+100;
											
											$('#full_back').height(h);
											$('#page').height(h);
											$('#white_bottom_bar').css({'top':h + 'px'});
											$('#telephone').css({'top':(h-$('#telephone').height()-50) + 'px'});
											
										});
									});
								});
								
								return false;
							});
						});
						var h = 900 + $(container).height() + $('#telephone').height()+100;
						
						$('#full_back').height(h);
						$('#page').height(h);
						$('#white_bottom_bar').css({'top':h + 'px'});
						$('#telephone').css({'top':(h-$('#telephone').height()-50) + 'px'});
						
					});
				});
			});
			
			return false;
		});
	});
	
	$(".movie").mb_YTPlayer();
	//$('.mbYTP_raster').after('<div>test</div>');
	
	$('a.first').click();
});
