$(document).ready(function(){
	
//	$('a.back').click(function(){
//		history.back(); return false;
//	});
	
	/**
	 * added by Marek.b content animation
	 */
	$('div.content').animate({
    left: '+=50',
    height: 'toggle'
	}, 2000, function(){
	});
	
	/**
	 * added by gWd
	 */
	$('#search input[type=text]').focus(function(){
		if ($(this).attr('value')=='szukaj') $(this).attr('value','');
		else $(this).select();
	});
	$('#search input[type=text]').blur(function(){
		if ($(this).attr('value')=='') $(this).attr('value','szukaj');
	});
	
	// Portfolio hover
	$('a.project').hover( 
		function () {$(this).addClass('hover');
		}, 
		function () {$(this).removeClass('hover');
		}
	);
	//$('.large .img-wrap a').append('<span class="zoom"></span>');
	// Sidemenu
	$('.sidemenu li ul').hide();
	$('.sidemenu li.active ul').show();
	$('.sidemenu li a').click(function() {
		if ($(this).parents().hasClass('active')) {
			return true;
		} else {
			$('.sidemenu li ul').slideUp('slow');
			$('.sidemenu li').removeClass('active');
			$(this).next('ul').slideDown('slow');
			$(this).parent().addClass('active');
			return false;
		}
	});
	// Reset Font Size
	var originalFontSize = $('.font-size').css('font-size');
		$(".resetFont").click(function(){
		$('.font-size').css('font-size', originalFontSize);
		posCounters();
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('.font-size').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.1;
		if (newFontSize<10) { newFontSize = 10;}
		if (newFontSize>20) { return false;}
		$('.font-size').css('font-size', newFontSize);
		posCounters();
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('.font-size').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.9;
		if (newFontSize<8) { return false;}
		$('.font-size').css('font-size', newFontSize);
		posCounters();
		return false;
	});
	//Counter
	$('.user-text ol').css('list-style', 'none');
	user_siblings = $('.user-text ol li');
	for (i=0;i<user_siblings.size();i=i+1){
		$(user_siblings[i]).append('<span class="counter">'+(i+1)+'</span>');
		$('.user-text ol li span.counter').css('font-size', 12);
	}
	
	posCounters = function() {
		$('.user-text ol li').each(function() {
			if ($(this).height() >= 16 ) {
				$(this).children('span.counter').css('top', ($(this).height()-16)/2);
			} 
		});
	};
	posCounters();
	//Photos
//	$('.photos span.counter').html(1+'/'+$('.photos .img-wrap img').size());
//	$('.photos .img-wrap').cycle({ 
//		fx:     'blindX', 
//		speed:  'slow', 
//		timeout: 0, 
//		next:   '.photos .next', 
//		prev:   '.photos .prev',
//		after:  function(currSlideElement, nextSlideElement, options, forwardFlag) {
//			$('.photos span.counter').html((options.currSlide+1)+'/'+options.elements.length);
//		}
//	});
	/**
	 * added by Marek.b photos switcher
	 */
	$('.photos').ready(function (){
		var jqThis = $('.photos');
		var prev = $('a.prev', jqThis);
		var next = $('a.next', jqThis);
		var img = $('img', '.img-wrap');
		var time = 100;
		img.filter(':first').addClass('current first');
		img.filter(':last').addClass('last');

		var curr = $('.current');
		if (curr.hasClass('first')) {
			prev.hide();
		}
		if (curr.hasClass('last')) {
			next.hide();
		}

		var counter = 1;
		if (!(counter == img.size())) {
			$('span.counter', jqThis).html(counter+' / '+img.size());
		}
		
		prev.click(function(){
			curr = curr.prev()
			counter = counter-1;
			nextprev(time);
			$('span.counter', jqThis).html(counter+' / '+img.size());
		});
		next.click(function(){
			curr = curr.next();
			counter = counter+1;
			nextprev(time);
			$('span.counter', jqThis).html(counter+' / '+img.size());
		});
		
		function nextprev(time){
			img.fadeOut(time).removeClass('current');
			curr.fadeIn(time).addClass('current');
			if (curr.hasClass('first')) {
				prev.hide();
			}else{
				prev.show();
			}
			if (curr.hasClass('last')) {
				next.hide();
			}else{
				next.show();
			}
		}
	});
	
	//$('.large .img-wrap a').lightBox();
	//Shorts
	$('.shorts .short').css('display', 'block');
	$('.shorts').cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 0, 
		next:   '#realiz .next', 
		prev:   '#realiz .prev'
	});
	//Accordion
	$('.ui-accordion .ui-accordion-content').css('height', 94);
	$("#accordion").accordion({ 
		event: 'mouseover', 
		speed: 'fast',
		fillSpace: true
	});
	$("#accordion h3:first-child").addClass('ui-state-active');
	
});
