jQuery(document).ready(function($) {
	
	/* Slogans
	----------------------------------------------
	$('#slogans ul').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 5000,
		type: 'random'
	});
	*/
	
	/* Misc
	---------------------------------------------- */
	$('.type1 ul li:last').addClass('last');
	$('#blog table tr:nth-child(even)').addClass('odd');
	$('#blog table th').wrapInner("<div></div>")
	
	/* Submenu
	---------------------------------------------- */
	$('#menu li').each(function() {
		$(this).find('ul').wrap('<div class="submenu" style="display:none"></div>');
	});
	$('#menu li').hover(
		function() {
			$(this).addClass('hover');
			$(this).find('.submenu').show();
		},
		function() {
			$(this).removeClass('hover');
			$(this).find('.submenu').hide('fast');
		}
	);
	
	/* Project
	---------------------------------------------- */
	$('.project').each(function(e) {
		
		var banners = $(this).find('ul').find('li').size();
		var pages = '';
		
		// Setup
		$(this).parent().attr('id', 'project'+e);
		
		// Pagination
		for (i=1; i<(banners+1); i++) {
			if (i == 1)
				pages = pages + '<dd><a href="#" class="project'+i+' active">'+i+'</a></dd>';
			else
				pages = pages + '<dd><a href="#" class="project'+i+'">'+i+'</a></dd>';
		}			
		$(this).find('.project-paginator').append(pages);
		$(this).find('.project-paginator').find('a').click(function () {
			$(this).parent().parent().find('a').removeClass('active');
			$(this).addClass('active');
		});
		if (banners < 2)
			$(this).find('.project-paginator').hide();
		
		// Carousel
		var buttons = new Array();
		for (i=1; i<(banners+1); i++) {
			buttons[(i-1)] = '#project'+e+' .project .project-paginator .project'+i;
		}
		
		$(this).find('.wrapper').jCarouselLite({
			visible: 1,
			btnGo: buttons
		});	
		
	});
	
	/* Magento
	---------------------------------------------- */
	var autoTime = 3000;
	var stop = false;
	
	$(".project-screens .project-list").jCarouselLite({
		btnNext: ".project-changer .next a",
		btnPrev: ".project-changer .prev a",
		speed: 1000,
		scroll: 1
	});
	//simulate autoscroll by simulating "click" on next link
	$('.project-changer .prev a').click(function() {
		stop = true;
		clearInterval(x);
	});
	
	var x = setInterval("$('.project-changer .next a').trigger('click');", autoTime);
	//if stopAuto is clicked the autoscroll is suspended for autoTime
	//no matter how far along the timer already was
	
	if(stop == false) {
		$(".project-screens .project-list, .project-changer .next a").hover(
			function() {
				clearInterval(x);
			},
			function() {
				x = setInterval("$('.project-changer .next a').trigger('click');", autoTime);
			}
		);	
	}
	
	/*	
	var banners = $('.project ul li').size();
	var pages = '';
	
	// Pagination
	for (i=1; i<(banners+1); i++) {
		if (i == 1)
			pages = pages + '<dd><a href="#" class="project'+i+' active">'+i+'</a></dd>';
		else
			pages = pages + '<dd><a href="#" class="project'+i+'">'+i+'</a></dd>';
	}			
	$('.project .project-paginator').append(pages);
	$('.project .project-paginator a').click(function () {
		$('.project .project-paginator a').removeClass('active');
		$(this).addClass('active');
	});
	if (banners < 2)
		$('.project .project-paginator').hide();
		
	// Carousel
	var buttons = new Array();
	for (i=1; i<(banners+1); i++) {
		buttons[(i-1)] = '.project .project-paginator .project'+i;
	}
	
	$('.project .wrapper').jCarouselLite({
		visible: 1,
		btnGo: buttons
	});
	*/

	/* Our layouts
	---------------------------------------------- */
	var pages = $('#our-layouts .our-layouts ul li').length,
		buttons = new Array();

	for (i=0; i<pages; i++) {
		buttons.push('.page' + (i+1))

		if (i == 0)
			$('#our-layouts .pagination').append('<li><a href="#" class="active page'+ (i+1) +'">'+ (i+1) +'</a></li>');
		else
			$('#our-layouts .pagination').append('<li><a href="#" class="page'+ (i+1) +'">'+ (i+1) +'</a></li>');
	}

	$('#our-layouts .our-layouts').jCarouselLite({
		visible: 1,
		btnGo: buttons
	});

	$('#our-layouts .pagination a').click(function() {
		$('#our-layouts .pagination a').removeClass('active');
		$(this).addClass('active');
	});

	if (pages < 2)
		$('#our-layouts .pagination').hide();
	
	
	/* Table
	---------------------------------------------- */
	$('.table .first a').click(function() {
		return false;
	});
	$('.table .first a').hover(
		function() {
			$(this).parent().find('.tooltip').show();
			$(this).css('z-index', '50');
		},
		function() {
			$(this).parent().find('.tooltip').hide();
			$(this).css('z-index', '10');
		}
	);
	
	/* Home slider
	---------------------------------------------- */
	$("#home-partners ul").simplyScroll({
		autoMode: 'loop',
		pauseOnHover: false,
		frameRate: 30,
		speed: 1
	});
	
})
