function pageLoaded() {
	
	$('ul.fixlast').each(function(){
		$(this).find('> li:last').addClass('last');
	});
	$('ul.fixfirst').each(function(){
		$(this).find('> li:first').addClass('first');
	});
	
	$('#slider').jcarousel({
		'auto' : 0,
		'wrap' : 'both'
	});
	
	$('#slider2 .slider-holder').jcarousel({
		auto: 5,
		scroll: 1,
		wrap: 'both',
		initCallback: _init_slider2
	});
	
	$('#navigation li').each(function(){
		var sub = $(this).find('.dd:eq(0)');
		if( sub.length > 0 ) {
			$(this).find('a:eq(0)').addClass('has-dd');
		}
	});
	
	// Fancy Box
	$(".gallery a:not('.back'), .post-detailed .images a, a.fancy").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'overlayColor'	: '#000'
	});
	
	$('#under-construction').center();
}

$(function() {
	
	$('input[type=text], textarea').focus(function(){
		if( $(this).attr('value') == $(this).attr('title') ) {
			$(this).attr({ 'value': '' });
		}
	}).blur(function(){
		if( $(this).attr('value') == '' ) {
			$(this).attr({ 'value': $(this).attr('title') })
		}
	});
	
	$('#slider .item').hover(function() {
		$(this).find('.info').not(':animated').slideDown();
	}, function() {
		$(this).find('.info').slideUp();
	});
	
	$('#navigation li').hover(
		function(){
			var sub = $(this).find('.dd:eq(0)');
			if(sub.length == 0 ) return;
			sub.fadeIn('fast');
			$(this).addClass('hover');
		
		},
		function(){
			var	sub = $(this).find('.dd:eq(0)');
			if(sub.length == 0 ) return;
			
			sub.hide();
			$(this).removeClass('hover');
		}
	);
	
	// Login Popup
	$('#screen').live('click', function(){
		$('.login').fadeOut(function(){ $('#screen').hide(); });
	});
	
	$('.login-link').live('click', function(){
		
		var h = $( '#wrapper' ).height() > $( window ).height() ? $( '#wrapper' ).height() : $( window ).height();
		$('#screen').css({ 'height': h });
		
		$('#screen').show();
		$('.login').center();
		$('.login').fadeIn();
		return false;
	});

	
	// Contact Form
	$('.validate-form').submit(function(){
		var form = $(this);
		form.find('.required').parents('.row:eq(0)').removeClass('field-error');
		
		var field, v, id, msg, t, field_holder;
		var alert_msg = $('.msg-alert');
		var error = false;
		form.find('.required').each(function(){
			field = $(this);
			field_holder = field.parents('.row:eq(0)');
			v = $(this).val();
			t = $(this).attr('title');
			id = $(this).attr('id');
			
			if( $(this).hasClass('valid-email') ){
				if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(v) == false ) {
					error = true;
				}
			}else {
				if( v == '' || v == t ){
					error = true;
				}
			}
			
			if( error ) {
				field.addClass('field-error');
				alert_msg.fadeIn();
				//error_fields.push( field );
			}
		});
		
		if( !error ) {
		
			form.find('.required').removeClass('field-error');
			var data = {}
			
			form.find('.text-field').each(function(){
				data[ $(this).attr('name') ] = $(this).val();
			});
			
			form.find('.text-field').each(function(){
				$(this).val( $(this).attr('title') );
			});
			
			$('#message-field').val( 'Loading...' );
			
			$.post('send.php', data, function(){
				alert_msg.fadeOut();
				form.find('.msg-thanks').fadeIn(function(){
					
					$('#message-field').val( $('#message-field').attr('title') );
					
					window.setTimeout(function(){
						form.find('.msg-thanks').fadeOut();
					}, 5000);
					
				});
			});
		}
		
		return false;
	}); 
});

jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
    body_height = parseInt($(window).height());
    block_width = parseInt(obj.width());
    block_height = parseInt(obj.height());
    
    left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
    if (body_width<block_width) { left_position = 0 + $(window).scrollLeft(); };
    
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
    
    if(!loaded) {
        
        obj.css({'position': 'absolute'});
        obj.css({ 'top': top_position });
        $(window).bind('resize', function() { 
            obj.center(!loaded);
        });
        $(window).bind('scroll', function() { 
            obj.center(!loaded);
        });
        
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({ 'top': top_position }, 200, 'linear');
    }
}

function _init_slider2( carousel ){
	$('#slider2 .slider-nav ul a').bind('click', function() {
		var index = $(this).parent().parent().find('a').index(this) + 1;
		carousel.scroll( index );
		return false;
	});
}
