var $j = jQuery.noConflict();

$j(document).ready(function() {

/* ===[ Scrolls ]=== */
$j('header#header nav ul li a').click(function() {
	$j('body').scrollTo($j(this).attr('href'),1000);
	return false;
});

/* ===[ Contact ]=== */
function runContact() {
$j('#contact form').after('<a href="#" id="next" class="contactNav">Dalej</a>');
$j('#contact form').before('<a href="#" id="prev" style="display:none" class="contactNav">Wstecz</a>');
$j('a#next').click(function() {
	$j('a#prev').fadeIn();
});

$j('a.contactNav').css('opacity','0.3');
$j('a.contactNav').hover(function() {
	$j(this).stop().animate({ opacity: 1 }, 250);
}, function() {
	$j(this).stop().animate({ opacity: 0.3 }, 250);
});

$j('#wpcf7-f337-t1-o1 form ul.slide').cycle({
	timeout: 0,
	speed: 250,
	fx: 'scrollHorz',
	sync: false,
	next: '#next',
	prev: '#prev'
});
};

$j('.wpcf7-response-output').css({ 'opacity':'0.7', 'border-radius':'10px' });
$j('.wpcf7-not-valid-tip').css({ 'opacity':'0.7', 'border-radius':'10px' });

/* ===[ Works ]=== */
function border() {
var count = $j('.works article').size();
if(count % 2 === 0) {
	$j('.works article:last').prev().andSelf().children('footer').css({ 'border-bottom' : '0' });
} else {
	$j('.works article:last').children('footer').css({ 'border-bottom' : '0' });
}
};

function works () {
$j('.works article:odd').css('margin-left','10px');
$j('.works article').hover(function() {
	$j(this).children('.seeMore').fadeIn().stop().animate({ opacity: 0.9 }, 200);
}, function() {
	$j(this).children('.seeMore').fadeOut().stop().animate({ opacity: 0 }, 200);
});
}
if($j('.works').length) {
	works();
	border();
}

/* ===[ Work display ]=== */
function loadImages() {
	$j('img').load(function() {
		var imgheight = $j(this).height();
		$j(this).hide();
		$j(this).fadeIn('slow');
	});
};
loadImages();

$j('div.worksNav a').css('opacity','0.5');
$j('div.worksNav a').hover(function() {
	$j(this).stop().animate({ opacity: 1 }, 200);
}, function() {
	$j(this).stop().animate({ opacity: 0.5 }, 200);
});


/* ===[ Texts ]=== */
$j('section div p:last-child, section li:last-child, section dl:last-child').css('padding','0');

$j('section header p a').each(function() { 
$j(this).click(function() {
	var name = $j(this).parent().parent().parent().attr('id');
	var link = $j(this).attr('href');
	var sc = $j(this).parent().parent().next('div.section-content')
	
	sc.css('height',sc.height()).html('<span class="pageLoader"></span>').fadeIn();
	
	sc.load(link + ' div.main > *', function() {
		$j(this).wrapInner('<div class="wrapper wrapper-'+name+'"/>');
		if ( !($j.browser.msie && $j.browser.version == 7.0) ){
			var newH = $j('div.wrapper-'+name).height();
		} else { 
			var newH1 = $j('div.wrapper-'+name).height();
			var newH = newH1+295;
		}
		$j(this).animate({ height: newH },500, works(), border());
	});
	
	$j(this).parent().delay(1000).slideUp();
	$j('body').scrollTo($j('#'+name),500);
	
	//function refresh() { sc[0].innerHTML += ''; };
	
	return false;
});
});

$j('section#latest p a').click(function() {$j(this).parent().prev('h3').html('Prace');});
$j('section#about p a').click(function() {$j(this).parent().prev('h3').html('Tomek!');});

$j('a[href=#contact]').click(function() {
	$j('div#contact').slideDown('slow');
	$j('body').scrollTo($j('#contact'),500);
	runContact();
	return false;
});

$j('a[href=#latest]').click(function() {
	$j('body').scrollTo($j('#latest'),500);
	return false;
});

$j('a[href=#faq').click(function() {
	$j('body').scrollTo($j('#faq'),500);
	return false;
});

/* ===[ Lists ]=== */
if ($j('header ul').length){
$j('header ul.list li, header dd').css('opacity','0.7');
$j('header ul.list li a').hover(function() {
	$j(this).parent('li').stop().animate({
		'margin-left': '10px',
		'opacity': 1
	}, 250);
}, function() {
	$j(this).parent('li').stop().animate({
		'margin-left': '0px',
		'opacity': 0.7
	}, 250);
});

$j('header dd').hover(function() {
	$j(this).stop().animate({
		'margin-left': '10px',
		'opacity': 1
	}, 250);
}, function() {
	$j(this).stop().animate({
		'margin-left': '0px',
		'opacity': 0.7
	}, 250);
});
}
$j('#cv strong').append(' • ');

});
