$(document).ready(function() {

	/* menu */
	if ($('body').hasClass('portfolio')) {
		var menu = $('.mod_navigation ul');
		var articles = $('.mod_article');
		
		$('li', menu).not(':first').remove();
		
		var ids = new Array();
		var titles = new Array();
		
		articles.each(function () {
			ids.push($(this).attr('id'));
			titles.push($(this).attr('title'));
		});
		
		var menuAdd = '';
		for (var i=0; i < ids.length; i++) {
			menuAdd += '<li class="sibling"><a class="slide" href="#' + ids[i] + '" title="' + titles[i] + '">' + titles[i] + '</a></li>';
		}
		menu.append(menuAdd);

		$('a', menu).eq(1).addClass('first');
		$('a', menu).eq($('a', menu).length - 1).addClass('last');
		menu = $('.mod_navigation');
		
		articles.not(':first').each(function(i) {
			var newMenu = menu.clone();
			$('a.slide', newMenu).eq(i+1).parent().addClass('active').removeClass('sibling');
			$(this).before(newMenu);
		})
		
		$('li', menu).eq(1).addClass('active').removeClass('sibling');		

		$('.mod_navigation ul li a.slide').click(function() {
			if ($(this).hasClass('first')) {
				$.scrollTo(0, 800);
			}
			/*
			else if ($(this).hasClass('last')) {
				$.scrollTo('100%', 800);
			}
			*/
			else {
				var res = $(this).attr('href').split('#');
				$.scrollTo('#' + res[1], 800, {offset: {top:-40}});
			}
			
			return false;			
		});
	}
	
	/* cycler */
	$('#promo-cycle').cycle({fx: 'fade', timeout: 5000});
	
	/* quotes */
	var q = $('#storitve .subcr');
	var quotes = $('div.quote', q);
	var current = Math.floor(Math.random() * quotes.size())
	quotes.eq(current).show();
	
	$('a.button', q).click(function() {
		var next;
		
		if (current == quotes.length - 1) {
			next = 0;
		}
		else {
			next = current + 1;
		}
		
		quotes.eq(current).hide();
		quotes.eq(next).show();
		current = next;
		
		return false;
	});

	
	/* portfolio */	
	$('.portfolio .mod_newslist').each(function () {
		var pitems = $('.portfolio_item', this);
		
		pitems.each(function (i) {
			if ((i+1) % 3 == 0) {
				if (i != pitems.length - 1) {
					$(this).after('<div class="portfolio_spacer"></div>');
				}
				
				$(this).addClass('pi_i2');
			}
		})
	});
	
	/* form */
	$('form input[type="submit"]').each(function () {
		$(this).hide().after('<a href="#" class="customSubmit button"><span>' + $(this).val() + '</span></a>');
	});
	
	$('form a.customSubmit').click(function () {
		$(this).parents('form').submit();
		return false;
	});
	
	/* footer links */
	$('#connect ul li:last').addClass('last');
	
});


	
